mirror of https://github.com/OpenVidu/openvidu.git
User's metadata in response to 'joinRoom' and 'onParticipantJoined'
parent
1ee067adc2
commit
7a55aa7baf
|
@ -1,29 +1,18 @@
|
|||
package org.openvidu.client;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
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.TrustSelfSignedStrategy;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
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 {
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -7,12 +7,14 @@ type ObjMap<T> = { [s: string]: T; }
|
|||
|
||||
export interface ParticipantOptions {
|
||||
id: string;
|
||||
metadata: string;
|
||||
streams?: StreamOptions[];
|
||||
}
|
||||
|
||||
export class ParticipantInternal {
|
||||
|
||||
private id: string;
|
||||
private metadata: string;
|
||||
private streams: ObjMap<Stream> = {};
|
||||
private streamsOpts: StreamOptions[] = [];
|
||||
|
||||
|
@ -21,6 +23,7 @@ export class ParticipantInternal {
|
|||
if ( options ) {
|
||||
|
||||
this.id = options.id;
|
||||
this.metadata = options.metadata;
|
||||
|
||||
if ( options.streams ) {
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import EventEmitter = require('wolfy87-eventemitter');
|
|||
export interface SessionOptions {
|
||||
sessionId: string;
|
||||
participantId: string;
|
||||
metadata: string;
|
||||
subscribeToStreams?: boolean;
|
||||
updateSpeakerInterval?: number;
|
||||
thresholdSpeaker?: number;
|
||||
|
@ -39,16 +40,11 @@ export class SessionInternal {
|
|||
callback('ERROR CONNECTING TO OPENVIDU');
|
||||
}
|
||||
else {
|
||||
this.configure({
|
||||
sessionId: this.sessionId,
|
||||
participantId: token,
|
||||
subscribeToStreams: this.subscribeToStreams
|
||||
});
|
||||
|
||||
let joinParams = {
|
||||
token: token,
|
||||
session: this.sessionId,
|
||||
metadata: '',
|
||||
metadata: this.options.metadata,
|
||||
dataChannels: false
|
||||
}
|
||||
|
||||
|
@ -93,6 +89,10 @@ export class SessionInternal {
|
|||
}
|
||||
}
|
||||
|
||||
for (let part of roomEvent.participants) {
|
||||
this.ee.emitEvent('connectionCreated', [{ connection: part }]);
|
||||
}
|
||||
|
||||
//if (this.subscribeToStreams) {
|
||||
for (let stream of roomEvent.streams) {
|
||||
this.ee.emitEvent('stream-added', [{ stream }]);
|
||||
|
@ -235,6 +235,11 @@ export class SessionInternal {
|
|||
this.ee.emitEvent('participant-joined', [{
|
||||
participant: participant
|
||||
}]);
|
||||
|
||||
this.ee.emitEvent('connectionCreated', [{
|
||||
connection: participant
|
||||
}]);
|
||||
|
||||
}
|
||||
|
||||
onParticipantLeft(msg) {
|
||||
|
|
|
@ -135,7 +135,7 @@ public class SessionController {
|
|||
// IMPORTANT STUFF
|
||||
TokenOptions tokenOpts = new TokenOptions.Builder()
|
||||
.role(role)
|
||||
.data("mydata=mydata")
|
||||
.data("SERVER=" + this.user.getLoggedUser().getName())
|
||||
.build();
|
||||
String token = (String) this.lessonIdSession.get(id_lesson).generateToken(tokenOpts);
|
||||
// END IMPORTANT STUFF
|
||||
|
|
|
@ -55,17 +55,25 @@ export class VideoSessionComponent implements OnInit {
|
|||
});
|
||||
});
|
||||
|
||||
this.session.on('connectionCreated', (event) => {
|
||||
console.warn(event);
|
||||
});
|
||||
|
||||
// 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 (!error) {
|
||||
|
||||
// 4) Get your own camera stream with the desired resolution and publish it, only if the user is supposed to do so
|
||||
this.publisher = this.OV.initPublisher('publisher', this.cameraOptions);
|
||||
if (this.authenticationService.isTeacher()){
|
||||
|
||||
// 5) Publish your stream
|
||||
this.session.publish(this.publisher);
|
||||
// 4) Get your own camera stream with the desired resolution and publish it, only if the user is supposed to do so
|
||||
this.publisher = this.OV.initPublisher('publisher', this.cameraOptions);
|
||||
|
||||
// 5) Publish your stream
|
||||
this.session.publish(this.publisher);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('There was an error connecting to the session:', error.code, error.message);
|
||||
|
|
|
@ -25,14 +25,13 @@ import org.kurento.client.MediaPipeline;
|
|||
import org.kurento.client.MediaType;
|
||||
import org.openvidu.client.OpenViduException;
|
||||
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.MutedMediaType;
|
||||
import org.openvidu.server.core.api.NotificationRoomHandler;
|
||||
import org.openvidu.server.core.api.pojo.ParticipantRequest;
|
||||
import org.openvidu.server.core.api.pojo.UserParticipant;
|
||||
import org.openvidu.server.core.internal.DefaultKurentoClientSessionInfo;
|
||||
import org.openvidu.server.core.internal.DefaultNotificationRoomHandler;
|
||||
import org.openvidu.server.security.ParticipantRole;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -76,22 +75,27 @@ public class NotificationRoomManager {
|
|||
* when responding back to the client)
|
||||
* @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) {
|
||||
Set<UserParticipant> existingParticipants = null;
|
||||
UserParticipant newParticipant = null;
|
||||
try {
|
||||
KurentoClientSessionInfo kcSessionInfo =
|
||||
new DefaultKurentoClientSessionInfo(request.getParticipantId(), session);
|
||||
existingParticipants = internalManager
|
||||
.joinRoom(user, session, dataChannels, webParticipant, kcSessionInfo,
|
||||
new DefaultKurentoClientSessionInfo(request.getParticipantId(), roomId);
|
||||
|
||||
JoinRoomReturnValue returnValue = internalManager
|
||||
.joinRoom(token, roomId, dataChannels, webParticipant, kcSessionInfo,
|
||||
request.getParticipantId());
|
||||
existingParticipants = returnValue.existingParticipants;
|
||||
newParticipant = returnValue.newParticipant;
|
||||
|
||||
} catch (OpenViduException e) {
|
||||
log.warn("PARTICIPANT {}: Error joining/creating room {}", user, session, e);
|
||||
notificationRoomHandler.onParticipantJoined(request, session, user, null, e);
|
||||
log.warn("PARTICIPANT {}: Error joining/creating room {}", token, roomId, e);
|
||||
notificationRoomHandler.onParticipantJoined(request, roomId, null, null, e);
|
||||
}
|
||||
if (existingParticipants != null) {
|
||||
notificationRoomHandler
|
||||
.onParticipantJoined(request, session, user, existingParticipants, null);
|
||||
.onParticipantJoined(request, roomId, newParticipant, existingParticipants, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,17 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
* @author <a href="mailto:rvlad@naevatec.com">Radu Tom Vlad</a>
|
||||
*/
|
||||
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);
|
||||
|
||||
@Autowired
|
||||
|
@ -108,31 +119,31 @@ public class RoomManager {
|
|||
* @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)
|
||||
*/
|
||||
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)
|
||||
throws OpenViduException {
|
||||
log.debug("Request [JOIN_ROOM] user={}, room={}, web={} " + "kcSessionInfo.room={} ({})",
|
||||
user, session, webParticipant,
|
||||
token, roomId, webParticipant,
|
||||
kcSessionInfo != null ? kcSessionInfo.getRoomName() : null, participantId);
|
||||
Room room = rooms.get(session);
|
||||
Room room = rooms.get(roomId);
|
||||
if (room == null && kcSessionInfo != null) {
|
||||
createRoom(kcSessionInfo);
|
||||
}
|
||||
room = rooms.get(session);
|
||||
room = rooms.get(roomId);
|
||||
if (room == null) {
|
||||
log.warn("Room '{}' not found");
|
||||
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");
|
||||
}
|
||||
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,
|
||||
"'" + 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);
|
||||
room.join(participantId, user, dataChannels, webParticipant);
|
||||
return existingParticipants;
|
||||
Set<UserParticipant> existingParticipants = getParticipants(roomId);
|
||||
UserParticipant newParticipant = room.join(participantId, token, getTokenClientMetadata(token, roomId), getTokenServerMetadata(token, roomId), dataChannels, webParticipant);
|
||||
return new JoinRoomReturnValue(newParticipant, existingParticipants);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -646,7 +657,7 @@ public class RoomManager {
|
|||
Set<UserParticipant> userParts = new HashSet<UserParticipant>();
|
||||
for (Participant p : participants) {
|
||||
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;
|
||||
|
@ -941,23 +952,30 @@ public class RoomManager {
|
|||
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 (this.sessionIdToken.get(session) != null) {
|
||||
return this.sessionIdToken.get(session).containsKey(token);
|
||||
if (this.sessionIdToken.get(roomId) != null) {
|
||||
return this.sessionIdToken.get(roomId).containsKey(token);
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
} 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 (this.sessionIdToken.get(session) != null){
|
||||
if (this.sessionIdToken.get(session).get(token) != null){
|
||||
return (this.sessionIdToken.get(session).get(token).getRole().equals(ParticipantRole.PUBLISHER));
|
||||
if (this.sessionIdToken.get(roomId) != null){
|
||||
if (this.sessionIdToken.get(roomId).get(token) != null){
|
||||
return (this.sessionIdToken.get(roomId).get(token).getRole().equals(ParticipantRole.PUBLISHER));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -969,11 +987,39 @@ public class RoomManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void setTokenClientMetadata(String token, String session, String metadata){
|
||||
if (this.sessionIdToken.get(session) != null){
|
||||
if (this.sessionIdToken.get(session).get(token) != null){
|
||||
this.sessionIdToken.get(session).get(token).setClientMetadata(metadata);
|
||||
public String getTokenClientMetadata(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).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;
|
||||
}
|
||||
|
||||
public String newToken(String session, ParticipantRole role, String metadata){
|
||||
if (this.sessionIdToken.get(session) != null) {
|
||||
public String newToken(String roomId, ParticipantRole role, String metadata){
|
||||
if (this.sessionIdToken.get(roomId) != null) {
|
||||
if(metadataFormatCorrect(metadata)){
|
||||
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();
|
||||
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");
|
||||
}
|
||||
} 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,
|
||||
"[" + session +"] is not a valid sessionId");
|
||||
"[" + roomId +"] is not a valid sessionId");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public interface NotificationRoomHandler extends RoomHandler {
|
|||
* 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.
|
||||
*/
|
||||
void onParticipantJoined(ParticipantRequest request, String roomName, String newUserName,
|
||||
void onParticipantJoined(ParticipantRequest request, String roomName, UserParticipant newParticipant,
|
||||
Set<UserParticipant> existingParticipants, OpenViduException error);
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,8 @@ package org.openvidu.server.core.api.pojo;
|
|||
public class UserParticipant {
|
||||
private String participantId;
|
||||
private String userName;
|
||||
private String clientMetadata;
|
||||
private String serverMetadata;
|
||||
private boolean streaming = false;
|
||||
|
||||
public UserParticipant(String participantId, String userName, boolean streaming) {
|
||||
|
@ -34,6 +36,15 @@ public class UserParticipant {
|
|||
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) {
|
||||
super();
|
||||
this.participantId = participantId;
|
||||
|
@ -56,6 +67,22 @@ public class UserParticipant {
|
|||
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() {
|
||||
return streaming;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onParticipantJoined(ParticipantRequest request, String roomName, String newUserName,
|
||||
public void onParticipantJoined(ParticipantRequest request, String roomName, UserParticipant newParticipant,
|
||||
Set<UserParticipant> existingParticipants, OpenViduException error) {
|
||||
if (error != null) {
|
||||
notifService.sendErrorResponse(request, null, error);
|
||||
|
@ -67,6 +67,11 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
|
|||
JsonObject participantJson = new JsonObject();
|
||||
participantJson
|
||||
.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()) {
|
||||
JsonObject stream = new JsonObject();
|
||||
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM, "webcam");
|
||||
|
@ -77,10 +82,10 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
|
|||
result.add(participantJson);
|
||||
|
||||
JsonObject notifParams = new JsonObject();
|
||||
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, newUserName);
|
||||
|
||||
// TO-DO: Return metadata associated to each participant
|
||||
//notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, participant.getUserName());
|
||||
// Metadata associated to new participant
|
||||
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, newParticipant.getUserName());
|
||||
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, newParticipant.getClientMetadata() + "--" + newParticipant.getServerMetadata());
|
||||
|
||||
notifService.sendNotification(participant.getParticipantId(),
|
||||
ProtocolElements.PARTICIPANTJOINED_METHOD, notifParams);
|
||||
|
|
|
@ -53,6 +53,8 @@ public class Participant {
|
|||
|
||||
private String id;
|
||||
private String name;
|
||||
private String clientMetadata;
|
||||
private String serverMetadata;
|
||||
private boolean web = false;
|
||||
private boolean dataChannels = false;
|
||||
|
||||
|
@ -71,10 +73,12 @@ public class Participant {
|
|||
private volatile boolean streaming = false;
|
||||
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) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.clientMetadata = clientMetadata;
|
||||
this.serverMetadata = serverMetadata;
|
||||
this.web = web;
|
||||
this.dataChannels = dataChannels;
|
||||
this.pipeline = pipeline;
|
||||
|
@ -104,6 +108,14 @@ public class Participant {
|
|||
return name;
|
||||
}
|
||||
|
||||
public String getClientMetadata() {
|
||||
return clientMetadata;
|
||||
}
|
||||
|
||||
public String getServerMetadata() {
|
||||
return serverMetadata;
|
||||
}
|
||||
|
||||
public void shapePublisherMedia(MediaElement element, MediaType type) {
|
||||
if (type == null) {
|
||||
this.publisher.apply(element);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.kurento.client.MediaPipeline;
|
|||
import org.openvidu.client.OpenViduException;
|
||||
import org.openvidu.client.OpenViduException.Code;
|
||||
import org.openvidu.server.core.api.RoomHandler;
|
||||
import org.openvidu.server.core.api.pojo.UserParticipant;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -91,7 +92,7 @@ public class Room {
|
|||
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 {
|
||||
|
||||
checkClosed();
|
||||
|
@ -108,16 +109,18 @@ public class Room {
|
|||
|
||||
createPipeline();
|
||||
|
||||
Participant participant =
|
||||
new Participant(participantId, user, this, getPipeline(), dataChannels, webParticipant);
|
||||
participants.put(participantId, participant);
|
||||
Participant p =
|
||||
new Participant(participantId, user, clientMetadata, serverMetadata, this, getPipeline(), dataChannels, webParticipant);
|
||||
participants.put(participantId, p);
|
||||
|
||||
filterStates.forEach((filterId, state) -> {
|
||||
log.info("Adding filter {}", filterId);
|
||||
roomHandler.updateFilter(name, participant, filterId, state);
|
||||
roomHandler.updateFilter(name, p, filterId, state);
|
||||
});
|
||||
|
||||
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) {
|
||||
|
|
|
@ -69,7 +69,7 @@ public class RoomController {
|
|||
}
|
||||
|
||||
@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 = "";
|
||||
try {
|
||||
ParticipantRole role = ParticipantRole.valueOf((String) sessionIdRoleMetadata.get("1"));
|
||||
|
|
|
@ -50,17 +50,17 @@ public class JsonRpcUserControl {
|
|||
|
||||
public void joinRoom(Transaction transaction, Request<JsonObject> request,
|
||||
ParticipantRequest participantRequest) throws IOException, InterruptedException,
|
||||
ExecutionException {
|
||||
ExecutionException, OpenViduException {
|
||||
|
||||
String session = getStringParam(request, ProtocolElements.JOINROOM_ROOM_PARAM);
|
||||
String user = getStringParam(request, ProtocolElements.JOINROOM_USER_PARAM);
|
||||
String userData = getStringParam(request, ProtocolElements.JOINROOM_METADATA_PARAM);
|
||||
String roomId = getStringParam(request, ProtocolElements.JOINROOM_ROOM_PARAM);
|
||||
String token = getStringParam(request, ProtocolElements.JOINROOM_USER_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;
|
||||
if (request.getParams().has(ProtocolElements.JOINROOM_DATACHANNELS_PARAM)) {
|
||||
|
@ -69,11 +69,11 @@ public class JsonRpcUserControl {
|
|||
}
|
||||
|
||||
ParticipantSession participantSession = getParticipantSession(transaction);
|
||||
participantSession.setParticipantName(user);
|
||||
participantSession.setRoomName(session);
|
||||
participantSession.setParticipantName(token);
|
||||
participantSession.setRoomName(roomId);
|
||||
participantSession.setDataChannels(dataChannels);
|
||||
|
||||
roomManager.joinRoom(user, session, dataChannels, true, participantRequest);
|
||||
roomManager.joinRoom(token, roomId, dataChannels, true, participantRequest);
|
||||
} else {
|
||||
System.out.println("Error: metadata format is incorrect");
|
||||
throw new OpenViduException(Code.USER_METADATA_FORMAT_INVALID_ERROR_CODE,
|
||||
|
|
|
@ -7,12 +7,32 @@ public class Token {
|
|||
String serverMetadata;
|
||||
String clientMetadata ;
|
||||
|
||||
public Token(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public Token(String token, ParticipantRole role, String metadata) {
|
||||
this.token = token;
|
||||
this.role = role;
|
||||
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() {
|
||||
return token;
|
||||
}
|
||||
|
@ -21,13 +41,12 @@ public class Token {
|
|||
return role;
|
||||
}
|
||||
|
||||
public void setClientMetadata(String metadata){
|
||||
this.clientMetadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.role.name();
|
||||
if (this.role != null)
|
||||
return this.role.name();
|
||||
else
|
||||
return this.token;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ public class RoomProtocolTest {
|
|||
|
||||
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")) {
|
||||
existingParticipants.add(new UserParticipant(preq.getParticipantId(), "user0", true));
|
||||
|
|
|
@ -517,7 +517,7 @@ public class RoomManagerTest {
|
|||
public String getRoomName() {
|
||||
return room;
|
||||
}
|
||||
}, usersParticipantIds.get(user));
|
||||
}, usersParticipantIds.get(user)).existingParticipants;
|
||||
if (peers.isEmpty()) {
|
||||
assertEquals("Expected one peer in room " + room + ": " + user, 1,
|
||||
manager.getParticipants(room).size());
|
||||
|
@ -1357,7 +1357,7 @@ public class RoomManagerTest {
|
|||
}
|
||||
|
||||
Set<UserParticipant> existingPeers = manager.joinRoom(user, room, false, webParticipant, kcsi,
|
||||
pid);
|
||||
pid).existingParticipants;
|
||||
|
||||
// verifies create media pipeline was called once
|
||||
verify(kurentoClient, times(1)).createMediaPipeline(kurentoClientCaptor.capture());
|
||||
|
|
Loading…
Reference in New Issue