Skip to content

Commit

Permalink
Tokens are now completely private
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Jun 2, 2017
1 parent 5ac854c commit 1a5dbab
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 96 deletions.
33 changes: 14 additions & 19 deletions openvidu-browser/src/main/resources/static/js/OpenVidu.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export class Connection {
+ ", streams opts: ", this.streamsOpts );
}

setId( newId ) {
this.connectionId = newId;
}

addStream( stream: Stream ) {
this.streams[stream.getIdInParticipant()] = stream;
this.room.getStreams()[stream.getIdInParticipant()] = stream;
Expand All @@ -70,17 +66,13 @@ export class Connection {
}
}

getId() {
return this.connectionId;
}

sendIceCandidate( candidate ) {

console.debug(( this.local ? "Local" : "Remote" ), "candidate for",
this.getId(), JSON.stringify( candidate ) );
this.connectionId, JSON.stringify( candidate ) );

this.openVidu.sendRequest( "onIceCandidate", {
endpointName: this.getId(),
endpointName: this.connectionId,
candidate: candidate.candidate,
sdpMid: candidate.sdpMid,
sdpMLineIndex: candidate.sdpMLineIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class SessionInternal {

let exParticipants = response.value;

// IMPORTANT: Update connectionId with value send by server
this.localParticipant.connectionId = response.id;
this.participants[response.id] = this.localParticipant;

let roomEvent = {
participants: new Array<Connection>(),
streams: new Array<Stream>()
Expand All @@ -77,7 +81,7 @@ export class SessionInternal {
exParticipants[i]);
connection.creationTime = new Date().getTime();

this.participants[connection.getId()] = connection;
this.participants[connection.connectionId] = connection;

roomEvent.participants.push(connection);

Expand Down Expand Up @@ -130,16 +134,12 @@ export class SessionInternal {


configure(options: SessionOptions) {

this.options = options;
this.id = options.sessionId;
this.subscribeToStreams = options.subscribeToStreams == null ? true : options.subscribeToStreams;
this.updateSpeakerInterval = options.updateSpeakerInterval || 1500;
this.thresholdSpeaker = options.thresholdSpeaker || -50;
this.localParticipant.setId(options.participantId);
this.activateUpdateMainSpeaker();

this.participants[options.participantId] = this.localParticipant;
}

getId() {
Expand Down Expand Up @@ -210,7 +210,7 @@ export class SessionInternal {

let connection = new Connection(this.openVidu, false, this, options);

let pid = connection.getId();
let pid = connection.connectionId;
if (!(pid in this.participants)) {
console.info("Publisher not found in participants list by its id", pid);
} else {
Expand Down Expand Up @@ -240,7 +240,7 @@ export class SessionInternal {
let connection = new Connection(this.openVidu, false, this, msg);
connection.creationTime = new Date().getTime();

let pid = connection.getId();
let pid = connection.connectionId;
if (!(pid in this.participants)) {
console.log("New participant to participants list with id", pid);
this.participants[pid] = connection;
Expand Down Expand Up @@ -434,12 +434,12 @@ export class SessionInternal {
return;
}

delete this.participants[connection.getId()];
delete this.participants[connection.connectionId];
connection.dispose();

if (connection === this.localParticipant) {

console.log("Unpublishing my media (I'm " + connection.getId() + ")");
console.log("Unpublishing my media (I'm " + connection.connectionId + ")");
delete this.localParticipant;
this.openVidu.sendRequest('unpublishVideo', function (error, response) {
if (error) {
Expand All @@ -464,10 +464,10 @@ export class SessionInternal {

if (connection === this.localParticipant) {

delete this.participants[connection.getId()];
delete this.participants[connection.connectionId];
connection.dispose();

console.log("Unpublishing my media (I'm " + connection.getId() + ")");
console.log("Unpublishing my media (I'm " + connection.connectionId + ")");
delete this.localParticipant;
this.openVidu.sendRequest('unpublishVideo', function (error, response) {
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class Stream {

getId() {
if (this.connection) {
return this.connection.getId() + "_" + this.id;
return this.connection.connectionId + "_" + this.id;
} else {
return this.id + "_webcam";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class ProtocolElements {
public static final String LEAVEROOM_METHOD = "leaveRoom";

public static final String JOINROOM_METHOD = "joinRoom";
public static final String JOINROOM_USER_PARAM = "token";
public static final String JOINROOM_USER_PARAM = "user";
public static final String JOINROOM_TOKEN_PARAM = "token";
public static final String JOINROOM_ROOM_PARAM = "session";
public static final String JOINROOM_METADATA_PARAM = "metadata";
public static final String JOINROOM_DATACHANNELS_PARAM = "dataChannels";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public NotificationRoomManager() {
* when responding back to the client)
* @see RoomManager#joinRoom(String, String, boolean, boolean, KurentoClientSessionInfo, String)
*/
public void joinRoom(String token, String roomId, boolean dataChannels,
public void joinRoom(String userName, String roomId, boolean dataChannels,
boolean webParticipant, ParticipantRequest request) {
Set<UserParticipant> existingParticipants = null;
UserParticipant newParticipant = null;
Expand All @@ -84,13 +84,13 @@ public void joinRoom(String token, String roomId, boolean dataChannels,
new DefaultKurentoClientSessionInfo(request.getParticipantId(), roomId);

JoinRoomReturnValue returnValue = internalManager
.joinRoom(token, roomId, dataChannels, webParticipant, kcSessionInfo,
.joinRoom(userName, roomId, dataChannels, webParticipant, kcSessionInfo,
request.getParticipantId());
existingParticipants = returnValue.existingParticipants;
newParticipant = returnValue.newParticipant;

} catch (OpenViduException e) {
log.warn("PARTICIPANT {}: Error joining/creating room {}", token, roomId, e);
log.warn("PARTICIPANT {}: Error joining/creating room {}", userName, roomId, e);
notificationRoomHandler.onParticipantJoined(request, roomId, null, null, e);
}
if (existingParticipants != null) {
Expand Down Expand Up @@ -438,4 +438,8 @@ public String newSessionId(){
public String newToken(String sessionId, ParticipantRole role, String metaData){
return this.internalManager.newToken(sessionId, role, metaData);
}

public String newRandomUserName(String token, String roomId){
return this.internalManager.newRandomUserName(token, roomId);
}
}
Loading

0 comments on commit 1a5dbab

Please sign in to comment.