User's metadata in response to 'joinRoom' and 'onParticipantJoined'

pull/20/head
pabloFuente 2017-05-16 16:57:36 +02:00
parent 1ee067adc2
commit 7a55aa7baf
18 changed files with 242 additions and 151 deletions

View File

@ -1,29 +1,18 @@
package org.openvidu.client; package org.openvidu.client;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider; import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContextBuilder;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.openvidu.client.OpenViduException.Code;
public class OpenVidu { public class OpenVidu {

File diff suppressed because one or more lines are too long

View File

@ -7,12 +7,14 @@ type ObjMap<T> = { [s: string]: T; }
export interface ParticipantOptions { export interface ParticipantOptions {
id: string; id: string;
metadata: string;
streams?: StreamOptions[]; streams?: StreamOptions[];
} }
export class ParticipantInternal { export class ParticipantInternal {
private id: string; private id: string;
private metadata: string;
private streams: ObjMap<Stream> = {}; private streams: ObjMap<Stream> = {};
private streamsOpts: StreamOptions[] = []; private streamsOpts: StreamOptions[] = [];
@ -21,6 +23,7 @@ export class ParticipantInternal {
if ( options ) { if ( options ) {
this.id = options.id; this.id = options.id;
this.metadata = options.metadata;
if ( options.streams ) { if ( options.streams ) {

View File

@ -6,6 +6,7 @@ import EventEmitter = require('wolfy87-eventemitter');
export interface SessionOptions { export interface SessionOptions {
sessionId: string; sessionId: string;
participantId: string; participantId: string;
metadata: string;
subscribeToStreams?: boolean; subscribeToStreams?: boolean;
updateSpeakerInterval?: number; updateSpeakerInterval?: number;
thresholdSpeaker?: number; thresholdSpeaker?: number;
@ -39,16 +40,11 @@ export class SessionInternal {
callback('ERROR CONNECTING TO OPENVIDU'); callback('ERROR CONNECTING TO OPENVIDU');
} }
else { else {
this.configure({
sessionId: this.sessionId,
participantId: token,
subscribeToStreams: this.subscribeToStreams
});
let joinParams = { let joinParams = {
token: token, token: token,
session: this.sessionId, session: this.sessionId,
metadata: '', metadata: this.options.metadata,
dataChannels: false dataChannels: false
} }
@ -93,6 +89,10 @@ export class SessionInternal {
} }
} }
for (let part of roomEvent.participants) {
this.ee.emitEvent('connectionCreated', [{ connection: part }]);
}
//if (this.subscribeToStreams) { //if (this.subscribeToStreams) {
for (let stream of roomEvent.streams) { for (let stream of roomEvent.streams) {
this.ee.emitEvent('stream-added', [{ stream }]); this.ee.emitEvent('stream-added', [{ stream }]);
@ -235,6 +235,11 @@ export class SessionInternal {
this.ee.emitEvent('participant-joined', [{ this.ee.emitEvent('participant-joined', [{
participant: participant participant: participant
}]); }]);
this.ee.emitEvent('connectionCreated', [{
connection: participant
}]);
} }
onParticipantLeft(msg) { onParticipantLeft(msg) {

View File

@ -135,7 +135,7 @@ public class SessionController {
// IMPORTANT STUFF // IMPORTANT STUFF
TokenOptions tokenOpts = new TokenOptions.Builder() TokenOptions tokenOpts = new TokenOptions.Builder()
.role(role) .role(role)
.data("mydata=mydata") .data("SERVER=" + this.user.getLoggedUser().getName())
.build(); .build();
String token = (String) this.lessonIdSession.get(id_lesson).generateToken(tokenOpts); String token = (String) this.lessonIdSession.get(id_lesson).generateToken(tokenOpts);
// END IMPORTANT STUFF // END IMPORTANT STUFF

View File

@ -55,17 +55,25 @@ export class VideoSessionComponent implements OnInit {
}); });
}); });
this.session.on('connectionCreated', (event) => {
console.warn(event);
});
// 3) Connect to the session // 3) Connect to the session
this.session.connect(this.token, (error) => { this.session.connect(this.token, "CLIENT:" + this.authenticationService.getCurrentUser().name ,(error) => {
// If the connection is successful, initialize a publisher and publish to the session // If the connection is successful, initialize a publisher and publish to the session
if (!error) { if (!error) {
// 4) Get your own camera stream with the desired resolution and publish it, only if the user is supposed to do so if (this.authenticationService.isTeacher()){
this.publisher = this.OV.initPublisher('publisher', this.cameraOptions);
// 5) Publish your stream // 4) Get your own camera stream with the desired resolution and publish it, only if the user is supposed to do so
this.session.publish(this.publisher); this.publisher = this.OV.initPublisher('publisher', this.cameraOptions);
// 5) Publish your stream
this.session.publish(this.publisher);
}
} else { } else {
console.log('There was an error connecting to the session:', error.code, error.message); console.log('There was an error connecting to the session:', error.code, error.message);

View File

@ -25,14 +25,13 @@ import org.kurento.client.MediaPipeline;
import org.kurento.client.MediaType; import org.kurento.client.MediaType;
import org.openvidu.client.OpenViduException; import org.openvidu.client.OpenViduException;
import org.openvidu.client.OpenViduException.Code; import org.openvidu.client.OpenViduException.Code;
import org.openvidu.server.core.api.KurentoClientProvider; import org.openvidu.server.core.RoomManager.JoinRoomReturnValue;
import org.openvidu.server.core.api.KurentoClientSessionInfo; import org.openvidu.server.core.api.KurentoClientSessionInfo;
import org.openvidu.server.core.api.MutedMediaType; import org.openvidu.server.core.api.MutedMediaType;
import org.openvidu.server.core.api.NotificationRoomHandler; import org.openvidu.server.core.api.NotificationRoomHandler;
import org.openvidu.server.core.api.pojo.ParticipantRequest; import org.openvidu.server.core.api.pojo.ParticipantRequest;
import org.openvidu.server.core.api.pojo.UserParticipant; import org.openvidu.server.core.api.pojo.UserParticipant;
import org.openvidu.server.core.internal.DefaultKurentoClientSessionInfo; import org.openvidu.server.core.internal.DefaultKurentoClientSessionInfo;
import org.openvidu.server.core.internal.DefaultNotificationRoomHandler;
import org.openvidu.server.security.ParticipantRole; import org.openvidu.server.security.ParticipantRole;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -76,22 +75,27 @@ public class NotificationRoomManager {
* when responding back to the client) * when responding back to the client)
* @see RoomManager#joinRoom(String, String, boolean, boolean, KurentoClientSessionInfo, String) * @see RoomManager#joinRoom(String, String, boolean, boolean, KurentoClientSessionInfo, String)
*/ */
public void joinRoom(String user, String session, boolean dataChannels, public void joinRoom(String token, String roomId, boolean dataChannels,
boolean webParticipant, ParticipantRequest request) { boolean webParticipant, ParticipantRequest request) {
Set<UserParticipant> existingParticipants = null; Set<UserParticipant> existingParticipants = null;
UserParticipant newParticipant = null;
try { try {
KurentoClientSessionInfo kcSessionInfo = KurentoClientSessionInfo kcSessionInfo =
new DefaultKurentoClientSessionInfo(request.getParticipantId(), session); new DefaultKurentoClientSessionInfo(request.getParticipantId(), roomId);
existingParticipants = internalManager
.joinRoom(user, session, dataChannels, webParticipant, kcSessionInfo, JoinRoomReturnValue returnValue = internalManager
.joinRoom(token, roomId, dataChannels, webParticipant, kcSessionInfo,
request.getParticipantId()); request.getParticipantId());
existingParticipants = returnValue.existingParticipants;
newParticipant = returnValue.newParticipant;
} catch (OpenViduException e) { } catch (OpenViduException e) {
log.warn("PARTICIPANT {}: Error joining/creating room {}", user, session, e); log.warn("PARTICIPANT {}: Error joining/creating room {}", token, roomId, e);
notificationRoomHandler.onParticipantJoined(request, session, user, null, e); notificationRoomHandler.onParticipantJoined(request, roomId, null, null, e);
} }
if (existingParticipants != null) { if (existingParticipants != null) {
notificationRoomHandler notificationRoomHandler
.onParticipantJoined(request, session, user, existingParticipants, null); .onParticipantJoined(request, roomId, newParticipant, existingParticipants, null);
} }
} }

View File

@ -62,6 +62,17 @@ import org.springframework.beans.factory.annotation.Value;
* @author <a href="mailto:rvlad@naevatec.com">Radu Tom Vlad</a> * @author <a href="mailto:rvlad@naevatec.com">Radu Tom Vlad</a>
*/ */
public class RoomManager { public class RoomManager {
public class JoinRoomReturnValue {
public UserParticipant newParticipant;
public Set<UserParticipant> existingParticipants;
public JoinRoomReturnValue(UserParticipant newParticipant, Set<UserParticipant> existingParticipants){
this.newParticipant = newParticipant;
this.existingParticipants = existingParticipants;
}
}
private final Logger log = LoggerFactory.getLogger(RoomManager.class); private final Logger log = LoggerFactory.getLogger(RoomManager.class);
@Autowired @Autowired
@ -108,31 +119,31 @@ public class RoomManager {
* @return set of existing peers of type {@link UserParticipant}, can be empty if first * @return set of existing peers of type {@link UserParticipant}, can be empty if first
* @throws OpenViduException on error while joining (like the room is not found or is closing) * @throws OpenViduException on error while joining (like the room is not found or is closing)
*/ */
public Set<UserParticipant> joinRoom(String user, String session, boolean dataChannels, public JoinRoomReturnValue joinRoom(String token, String roomId, boolean dataChannels,
boolean webParticipant, KurentoClientSessionInfo kcSessionInfo, String participantId) boolean webParticipant, KurentoClientSessionInfo kcSessionInfo, String participantId)
throws OpenViduException { throws OpenViduException {
log.debug("Request [JOIN_ROOM] user={}, room={}, web={} " + "kcSessionInfo.room={} ({})", log.debug("Request [JOIN_ROOM] user={}, room={}, web={} " + "kcSessionInfo.room={} ({})",
user, session, webParticipant, token, roomId, webParticipant,
kcSessionInfo != null ? kcSessionInfo.getRoomName() : null, participantId); kcSessionInfo != null ? kcSessionInfo.getRoomName() : null, participantId);
Room room = rooms.get(session); Room room = rooms.get(roomId);
if (room == null && kcSessionInfo != null) { if (room == null && kcSessionInfo != null) {
createRoom(kcSessionInfo); createRoom(kcSessionInfo);
} }
room = rooms.get(session); room = rooms.get(roomId);
if (room == null) { if (room == null) {
log.warn("Room '{}' not found"); log.warn("Room '{}' not found");
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE,
"Room '" + session + "' was not found, must be created before '" + session "Room '" + roomId + "' was not found, must be created before '" + roomId
+ "' can join"); + "' can join");
} }
if (room.isClosed()) { if (room.isClosed()) {
log.warn("'{}' is trying to join room '{}' but it is closing", user, session); log.warn("'{}' is trying to join room '{}' but it is closing", token, roomId);
throw new OpenViduException(Code.ROOM_CLOSED_ERROR_CODE, throw new OpenViduException(Code.ROOM_CLOSED_ERROR_CODE,
"'" + user + "' is trying to join room '" + session + "' but it is closing"); "'" + token + "' is trying to join room '" + roomId + "' but it is closing");
} }
Set<UserParticipant> existingParticipants = getParticipants(session); Set<UserParticipant> existingParticipants = getParticipants(roomId);
room.join(participantId, user, dataChannels, webParticipant); UserParticipant newParticipant = room.join(participantId, token, getTokenClientMetadata(token, roomId), getTokenServerMetadata(token, roomId), dataChannels, webParticipant);
return existingParticipants; return new JoinRoomReturnValue(newParticipant, existingParticipants);
} }
/** /**
@ -646,7 +657,7 @@ public class RoomManager {
Set<UserParticipant> userParts = new HashSet<UserParticipant>(); Set<UserParticipant> userParts = new HashSet<UserParticipant>();
for (Participant p : participants) { for (Participant p : participants) {
if (!p.isClosed()) { if (!p.isClosed()) {
userParts.add(new UserParticipant(p.getId(), p.getName(), p.isStreaming())); userParts.add(new UserParticipant(p.getId(), p.getName(), p.getClientMetadata(), p.getServerMetadata(), p.isStreaming()));
} }
} }
return userParts; return userParts;
@ -941,23 +952,30 @@ public class RoomManager {
return getParticipant(pid).getRoom().getName(); return getParticipant(pid).getRoom().getName();
} }
public boolean isParticipantInRoom(String token, String session) { public boolean isParticipantInRoom(String token, String roomId) throws OpenViduException {
if (SECURITY_ENABLED) { if (SECURITY_ENABLED) {
if (this.sessionIdToken.get(session) != null) { if (this.sessionIdToken.get(roomId) != null) {
return this.sessionIdToken.get(session).containsKey(token); return this.sessionIdToken.get(roomId).containsKey(token);
} else{ } else{
return false; return false;
} }
} else { } else {
return true; this.sessionIdToken.putIfAbsent(roomId, new ConcurrentHashMap<>());
if (this.sessionIdToken.get(roomId).containsKey(token)){
// If the user already exists
throw new OpenViduException(Code.EXISTING_USER_IN_ROOM_ERROR_CODE, "The user " + token + " already exists in room " + roomId);
} else {
this.sessionIdToken.get(roomId).put(token, new Token(token));
return true;
}
} }
} }
public boolean isPublisherInRoom(String token, String session) { public boolean isPublisherInRoom(String token, String roomId) {
if (SECURITY_ENABLED) { if (SECURITY_ENABLED) {
if (this.sessionIdToken.get(session) != null){ if (this.sessionIdToken.get(roomId) != null){
if (this.sessionIdToken.get(session).get(token) != null){ if (this.sessionIdToken.get(roomId).get(token) != null){
return (this.sessionIdToken.get(session).get(token).getRole().equals(ParticipantRole.PUBLISHER)); return (this.sessionIdToken.get(roomId).get(token).getRole().equals(ParticipantRole.PUBLISHER));
} else { } else {
return false; return false;
} }
@ -969,11 +987,39 @@ public class RoomManager {
} }
} }
public void setTokenClientMetadata(String token, String session, String metadata){ public String getTokenClientMetadata(String token, String roomId) throws OpenViduException {
if (this.sessionIdToken.get(session) != null){ if (this.sessionIdToken.get(roomId) != null){
if (this.sessionIdToken.get(session).get(token) != null){ if (this.sessionIdToken.get(roomId).get(token) != null){
this.sessionIdToken.get(session).get(token).setClientMetadata(metadata); return this.sessionIdToken.get(roomId).get(token).getClientMetadata();
} else {
throw new OpenViduException(Code.USER_NOT_FOUND_ERROR_CODE, roomId);
} }
} else {
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, token);
}
}
public String getTokenServerMetadata(String token, String roomId) throws OpenViduException {
if (this.sessionIdToken.get(roomId) != null){
if (this.sessionIdToken.get(roomId).get(token) != null){
return this.sessionIdToken.get(roomId).get(token).getServerMetadata();
} else {
throw new OpenViduException(Code.USER_NOT_FOUND_ERROR_CODE, roomId);
}
} else {
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, token);
}
}
public void setTokenClientMetadata(String token, String roomId, String metadata) throws OpenViduException {
if (this.sessionIdToken.get(roomId) != null){
if (this.sessionIdToken.get(roomId).get(token) != null){
this.sessionIdToken.get(roomId).get(token).setClientMetadata(metadata);
} else {
throw new OpenViduException(Code.USER_NOT_FOUND_ERROR_CODE, roomId);
}
} else {
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, token);
} }
} }
@ -984,11 +1030,11 @@ public class RoomManager {
return sessionId; return sessionId;
} }
public String newToken(String session, ParticipantRole role, String metadata){ public String newToken(String roomId, ParticipantRole role, String metadata){
if (this.sessionIdToken.get(session) != null) { if (this.sessionIdToken.get(roomId) != null) {
if(metadataFormatCorrect(metadata)){ if(metadataFormatCorrect(metadata)){
String token = new BigInteger(130, new SecureRandom()).toString(32); String token = new BigInteger(130, new SecureRandom()).toString(32);
this.sessionIdToken.get(session).put(token, new Token(token, role, metadata)); this.sessionIdToken.get(roomId).put(token, new Token(token, role, metadata));
showMap(); showMap();
return token; return token;
} }
@ -996,9 +1042,9 @@ public class RoomManager {
throw new OpenViduException(Code.GENERIC_ERROR_CODE, "Data invalid format. Max length allowed is 1000 chars"); throw new OpenViduException(Code.GENERIC_ERROR_CODE, "Data invalid format. Max length allowed is 1000 chars");
} }
} else { } else {
System.out.println("Error: the sessionId [" + session + "] is not valid"); System.out.println("Error: the sessionId [" + roomId + "] is not valid");
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE,
"[" + session +"] is not a valid sessionId"); "[" + roomId +"] is not a valid sessionId");
} }
} }

View File

@ -57,7 +57,7 @@ public interface NotificationRoomHandler extends RoomHandler {
* instance of {@link OpenViduException} POJO, includes a code and error message. If not * instance of {@link OpenViduException} POJO, includes a code and error message. If not
* null, then the join was unsuccessful and the user should be responded accordingly. * null, then the join was unsuccessful and the user should be responded accordingly.
*/ */
void onParticipantJoined(ParticipantRequest request, String roomName, String newUserName, void onParticipantJoined(ParticipantRequest request, String roomName, UserParticipant newParticipant,
Set<UserParticipant> existingParticipants, OpenViduException error); Set<UserParticipant> existingParticipants, OpenViduException error);
/** /**

View File

@ -25,6 +25,8 @@ package org.openvidu.server.core.api.pojo;
public class UserParticipant { public class UserParticipant {
private String participantId; private String participantId;
private String userName; private String userName;
private String clientMetadata;
private String serverMetadata;
private boolean streaming = false; private boolean streaming = false;
public UserParticipant(String participantId, String userName, boolean streaming) { public UserParticipant(String participantId, String userName, boolean streaming) {
@ -34,6 +36,15 @@ public class UserParticipant {
this.streaming = streaming; this.streaming = streaming;
} }
public UserParticipant(String participantId, String userName, String clientMetadata, String serverMetadata, boolean streaming) {
super();
this.participantId = participantId;
this.userName = userName;
this.clientMetadata = clientMetadata;
this.serverMetadata = serverMetadata;
this.streaming = streaming;
}
public UserParticipant(String participantId, String userName) { public UserParticipant(String participantId, String userName) {
super(); super();
this.participantId = participantId; this.participantId = participantId;
@ -56,6 +67,22 @@ public class UserParticipant {
this.userName = userName; this.userName = userName;
} }
public String getClientMetadata() {
return clientMetadata;
}
public void setClientMetadata(String clientMetadata) {
this.clientMetadata = clientMetadata;
}
public String getServerMetadata() {
return serverMetadata;
}
public void setServerMetadata(String serverMetadata) {
this.serverMetadata = serverMetadata;
}
public boolean isStreaming() { public boolean isStreaming() {
return streaming; return streaming;
} }

View File

@ -55,7 +55,7 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
} }
@Override @Override
public void onParticipantJoined(ParticipantRequest request, String roomName, String newUserName, public void onParticipantJoined(ParticipantRequest request, String roomName, UserParticipant newParticipant,
Set<UserParticipant> existingParticipants, OpenViduException error) { Set<UserParticipant> existingParticipants, OpenViduException error) {
if (error != null) { if (error != null) {
notifService.sendErrorResponse(request, null, error); notifService.sendErrorResponse(request, null, error);
@ -67,6 +67,11 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
JsonObject participantJson = new JsonObject(); JsonObject participantJson = new JsonObject();
participantJson participantJson
.addProperty(ProtocolElements.JOINROOM_PEERID_PARAM, participant.getUserName()); .addProperty(ProtocolElements.JOINROOM_PEERID_PARAM, participant.getUserName());
// Metadata associated to each existing participant
participantJson
.addProperty(ProtocolElements.JOINROOM_METADATA_PARAM, participant.getClientMetadata() + "--" + participant.getServerMetadata());
if (participant.isStreaming()) { if (participant.isStreaming()) {
JsonObject stream = new JsonObject(); JsonObject stream = new JsonObject();
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM, "webcam"); stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM, "webcam");
@ -77,10 +82,10 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
result.add(participantJson); result.add(participantJson);
JsonObject notifParams = new JsonObject(); JsonObject notifParams = new JsonObject();
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, newUserName);
// TO-DO: Return metadata associated to each participant // Metadata associated to new participant
//notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, participant.getUserName()); notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, newParticipant.getUserName());
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, newParticipant.getClientMetadata() + "--" + newParticipant.getServerMetadata());
notifService.sendNotification(participant.getParticipantId(), notifService.sendNotification(participant.getParticipantId(),
ProtocolElements.PARTICIPANTJOINED_METHOD, notifParams); ProtocolElements.PARTICIPANTJOINED_METHOD, notifParams);

View File

@ -53,6 +53,8 @@ public class Participant {
private String id; private String id;
private String name; private String name;
private String clientMetadata;
private String serverMetadata;
private boolean web = false; private boolean web = false;
private boolean dataChannels = false; private boolean dataChannels = false;
@ -71,10 +73,12 @@ public class Participant {
private volatile boolean streaming = false; private volatile boolean streaming = false;
private volatile boolean closed; private volatile boolean closed;
public Participant(String id, String name, Room room, MediaPipeline pipeline, public Participant(String id, String name, String clientMetadata, String serverMetadata, Room room, MediaPipeline pipeline,
boolean dataChannels, boolean web) { boolean dataChannels, boolean web) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.clientMetadata = clientMetadata;
this.serverMetadata = serverMetadata;
this.web = web; this.web = web;
this.dataChannels = dataChannels; this.dataChannels = dataChannels;
this.pipeline = pipeline; this.pipeline = pipeline;
@ -104,6 +108,14 @@ public class Participant {
return name; return name;
} }
public String getClientMetadata() {
return clientMetadata;
}
public String getServerMetadata() {
return serverMetadata;
}
public void shapePublisherMedia(MediaElement element, MediaType type) { public void shapePublisherMedia(MediaElement element, MediaType type) {
if (type == null) { if (type == null) {
this.publisher.apply(element); this.publisher.apply(element);

View File

@ -33,6 +33,7 @@ import org.kurento.client.MediaPipeline;
import org.openvidu.client.OpenViduException; import org.openvidu.client.OpenViduException;
import org.openvidu.client.OpenViduException.Code; import org.openvidu.client.OpenViduException.Code;
import org.openvidu.server.core.api.RoomHandler; import org.openvidu.server.core.api.RoomHandler;
import org.openvidu.server.core.api.pojo.UserParticipant;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -91,7 +92,7 @@ public class Room {
return this.pipeline; return this.pipeline;
} }
public synchronized void join(String participantId, String user, boolean dataChannels, public synchronized UserParticipant join(String participantId, String user, String clientMetadata, String serverMetadata, boolean dataChannels,
boolean webParticipant) throws OpenViduException { boolean webParticipant) throws OpenViduException {
checkClosed(); checkClosed();
@ -108,16 +109,18 @@ public class Room {
createPipeline(); createPipeline();
Participant participant = Participant p =
new Participant(participantId, user, this, getPipeline(), dataChannels, webParticipant); new Participant(participantId, user, clientMetadata, serverMetadata, this, getPipeline(), dataChannels, webParticipant);
participants.put(participantId, participant); participants.put(participantId, p);
filterStates.forEach((filterId, state) -> { filterStates.forEach((filterId, state) -> {
log.info("Adding filter {}", filterId); log.info("Adding filter {}", filterId);
roomHandler.updateFilter(name, participant, filterId, state); roomHandler.updateFilter(name, p, filterId, state);
}); });
log.info("ROOM {}: Added participant {}", name, user); log.info("ROOM {}: Added participant {}", name, user);
return new UserParticipant(p.getId(), p.getName(), p.getClientMetadata(), p.getServerMetadata(), p.isStreaming());
} }
public void newPublisher(Participant participant) { public void newPublisher(Participant participant) {

View File

@ -69,7 +69,7 @@ public class RoomController {
} }
@RequestMapping(value = "/newToken", method = RequestMethod.POST) @RequestMapping(value = "/newToken", method = RequestMethod.POST)
public ResponseEntity<JSONObject> getToken(@RequestBody Map sessionIdRoleMetadata) { // {0: sessionID, 1: role, 2: metadata} public ResponseEntity<JSONObject> newToken(@RequestBody Map sessionIdRoleMetadata) { // {0: sessionID, 1: role, 2: metadata}
String errorMessage = ""; String errorMessage = "";
try { try {
ParticipantRole role = ParticipantRole.valueOf((String) sessionIdRoleMetadata.get("1")); ParticipantRole role = ParticipantRole.valueOf((String) sessionIdRoleMetadata.get("1"));

View File

@ -50,17 +50,17 @@ public class JsonRpcUserControl {
public void joinRoom(Transaction transaction, Request<JsonObject> request, public void joinRoom(Transaction transaction, Request<JsonObject> request,
ParticipantRequest participantRequest) throws IOException, InterruptedException, ParticipantRequest participantRequest) throws IOException, InterruptedException,
ExecutionException { ExecutionException, OpenViduException {
String session = getStringParam(request, ProtocolElements.JOINROOM_ROOM_PARAM); String roomId = getStringParam(request, ProtocolElements.JOINROOM_ROOM_PARAM);
String user = getStringParam(request, ProtocolElements.JOINROOM_USER_PARAM); String token = getStringParam(request, ProtocolElements.JOINROOM_USER_PARAM);
String userData = getStringParam(request, ProtocolElements.JOINROOM_METADATA_PARAM); String clientMetadata = getStringParam(request, ProtocolElements.JOINROOM_METADATA_PARAM);
if(roomManager.getRoomManager().isParticipantInRoom(user, session)){ if(roomManager.getRoomManager().isParticipantInRoom(token, roomId)){
if(roomManager.getRoomManager().metadataFormatCorrect(userData)){ if(roomManager.getRoomManager().metadataFormatCorrect(clientMetadata)){
this.roomManager.getRoomManager().setTokenClientMetadata(user, session, userData); this.roomManager.getRoomManager().setTokenClientMetadata(token, roomId, clientMetadata);
boolean dataChannels = false; boolean dataChannels = false;
if (request.getParams().has(ProtocolElements.JOINROOM_DATACHANNELS_PARAM)) { if (request.getParams().has(ProtocolElements.JOINROOM_DATACHANNELS_PARAM)) {
@ -69,11 +69,11 @@ public class JsonRpcUserControl {
} }
ParticipantSession participantSession = getParticipantSession(transaction); ParticipantSession participantSession = getParticipantSession(transaction);
participantSession.setParticipantName(user); participantSession.setParticipantName(token);
participantSession.setRoomName(session); participantSession.setRoomName(roomId);
participantSession.setDataChannels(dataChannels); participantSession.setDataChannels(dataChannels);
roomManager.joinRoom(user, session, dataChannels, true, participantRequest); roomManager.joinRoom(token, roomId, dataChannels, true, participantRequest);
} else { } else {
System.out.println("Error: metadata format is incorrect"); System.out.println("Error: metadata format is incorrect");
throw new OpenViduException(Code.USER_METADATA_FORMAT_INVALID_ERROR_CODE, throw new OpenViduException(Code.USER_METADATA_FORMAT_INVALID_ERROR_CODE,

View File

@ -7,12 +7,32 @@ public class Token {
String serverMetadata; String serverMetadata;
String clientMetadata ; String clientMetadata ;
public Token(String token) {
this.token = token;
}
public Token(String token, ParticipantRole role, String metadata) { public Token(String token, ParticipantRole role, String metadata) {
this.token = token; this.token = token;
this.role = role; this.role = role;
this.serverMetadata = metadata; this.serverMetadata = metadata;
} }
public String getServerMetadata() {
return serverMetadata;
}
public void setServerMetadata(String serverMetadata) {
this.serverMetadata = serverMetadata;
}
public String getClientMetadata() {
return clientMetadata;
}
public void setClientMetadata(String metadata){
this.clientMetadata = metadata;
}
public String getToken() { public String getToken() {
return token; return token;
} }
@ -21,13 +41,12 @@ public class Token {
return role; return role;
} }
public void setClientMetadata(String metadata){
this.clientMetadata = metadata;
}
@Override @Override
public String toString(){ public String toString(){
return this.role.name(); if (this.role != null)
return this.role.name();
else
return this.token;
} }
} }

View File

@ -126,7 +126,7 @@ public class RoomProtocolTest {
log.debug("joinRoom -> {} to {}, preq: {}", userName, roomName, preq); log.debug("joinRoom -> {} to {}, preq: {}", userName, roomName, preq);
roomEventHandler.onParticipantJoined(preq, roomName, userName, existingParticipants, null); roomEventHandler.onParticipantJoined(preq, roomName, new UserParticipant(userName, userName), existingParticipants, null);
if (userName.equalsIgnoreCase("user0")) { if (userName.equalsIgnoreCase("user0")) {
existingParticipants.add(new UserParticipant(preq.getParticipantId(), "user0", true)); existingParticipants.add(new UserParticipant(preq.getParticipantId(), "user0", true));

View File

@ -517,7 +517,7 @@ public class RoomManagerTest {
public String getRoomName() { public String getRoomName() {
return room; return room;
} }
}, usersParticipantIds.get(user)); }, usersParticipantIds.get(user)).existingParticipants;
if (peers.isEmpty()) { if (peers.isEmpty()) {
assertEquals("Expected one peer in room " + room + ": " + user, 1, assertEquals("Expected one peer in room " + room + ": " + user, 1,
manager.getParticipants(room).size()); manager.getParticipants(room).size());
@ -1357,7 +1357,7 @@ public class RoomManagerTest {
} }
Set<UserParticipant> existingPeers = manager.joinRoom(user, room, false, webParticipant, kcsi, Set<UserParticipant> existingPeers = manager.joinRoom(user, room, false, webParticipant, kcsi,
pid); pid).existingParticipants;
// verifies create media pipeline was called once // verifies create media pipeline was called once
verify(kurentoClient, times(1)).createMediaPipeline(kurentoClientCaptor.capture()); verify(kurentoClient, times(1)).createMediaPipeline(kurentoClientCaptor.capture());