Bug fix: race condition of "streamCreated" event (triggered by "joinRoom" callback and "onParticipantPublished)

pull/30/merge
pabloFuente 2018-03-13 15:44:52 +01:00
parent 88d017dc18
commit df074b5d15
1 changed files with 22 additions and 18 deletions

View File

@ -305,15 +305,17 @@ export class SessionInternal {
console.debug("Remote Connection found in connections list by its id [" + pid + "]");
}
this.participants[pid] = connection;
this.ee.emitEvent('participant-published', [{ connection }]);
let streams = connection.getStreams();
for (let key in streams) {
let stream = streams[key];
if (!this.streams[stream.streamId]) {
// Avoid race condition between stream.subscribe() in "onParticipantPublished" and in "joinRoom" rpc callback
// This condition is false if openvidu-server sends "participantPublished" event to a subscriber participant that has
// already subscribed to certain stream in the callback of "joinRoom" method
if (this.subscribeToStreams) {
stream.subscribe();
}
@ -321,6 +323,8 @@ export class SessionInternal {
// Adding the remote stream to the OpenVidu object
this.openVidu.getRemoteStreams().push(stream);
}
}
}