Skip to content

Commit

Permalink
openvidu-browser: fix Map refactoring bugs (for..in not working on Map)
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Feb 18, 2021
1 parent d91721c commit f672090
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 44 deletions.
72 changes: 33 additions & 39 deletions openvidu-browser/src/OpenVidu/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,22 +616,20 @@ export class Session extends EventDispatcher {
if (type === 'publisherStartSpeaking') {
this.startSpeakingEventsEnabled = true;
// If there are already available remote streams, enable hark 'speaking' event in all of them
for (const connectionId in this.remoteConnections) {
const str = this.remoteConnections.get(connectionId)?.stream;
if (!!str && str.hasAudio) {
str.enableStartSpeakingEvent();
this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
remoteConnection.stream.enableStartSpeakingEvent();
}
}
});
}
if (type === 'publisherStopSpeaking') {
this.stopSpeakingEventsEnabled = true;
// If there are already available remote streams, enable hark 'stopped_speaking' event in all of them
for (const connectionId in this.remoteConnections) {
const str = this.remoteConnections.get(connectionId)?.stream;
if (!!str && str.hasAudio) {
str.enableStopSpeakingEvent();
this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
remoteConnection.stream.enableStopSpeakingEvent();
}
}
});
}

return this;
Expand All @@ -648,22 +646,20 @@ export class Session extends EventDispatcher {
if (type === 'publisherStartSpeaking') {
this.startSpeakingEventsEnabledOnce = true;
// If there are already available remote streams, enable hark 'speaking' event in all of them once
for (const connectionId in this.remoteConnections) {
const str = this.remoteConnections.get(connectionId)?.stream;
if (!!str && str.hasAudio) {
str.enableOnceStartSpeakingEvent();
this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
remoteConnection.stream.enableOnceStartSpeakingEvent();
}
}
});
}
if (type === 'publisherStopSpeaking') {
this.stopSpeakingEventsEnabledOnce = true;
// If there are already available remote streams, enable hark 'stopped_speaking' event in all of them once
for (const connectionId in this.remoteConnections) {
const str = this.remoteConnections.get(connectionId)?.stream;
if (!!str && str.hasAudio) {
str.enableOnceStopSpeakingEvent();
this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
remoteConnection.stream.enableOnceStopSpeakingEvent();
}
}
});
}

return this;
Expand All @@ -682,25 +678,23 @@ export class Session extends EventDispatcher {
if (remainingStartSpeakingListeners === 0) {
this.startSpeakingEventsEnabled = false;
// If there are already available remote streams, disable hark in all of them
for (const connectionId in this.remoteConnections) {
const str = this.remoteConnections.get(connectionId)?.stream;
if (!!str) {
str.disableStartSpeakingEvent(false);
this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream) {
remoteConnection.stream.disableStartSpeakingEvent(false);
}
}
});
}
}
if (type === 'publisherStopSpeaking') {
let remainingStopSpeakingListeners = this.ee.getListeners(type).length;
if (remainingStopSpeakingListeners === 0) {
this.stopSpeakingEventsEnabled = false;
// If there are already available remote streams, disable hark in all of them
for (const connectionId in this.remoteConnections) {
const str = this.remoteConnections.get(connectionId)?.stream;
if (!!str) {
str.disableStopSpeakingEvent(false);
this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream) {
remoteConnection.stream.disableStopSpeakingEvent(false);
}
}
});
}
}
return this;
Expand Down Expand Up @@ -731,7 +725,7 @@ export class Session extends EventDispatcher {
*/
onParticipantLeft(msg): void {

if(this.remoteConnections.size > 0) {
if (this.remoteConnections.size > 0) {
this.getRemoteConnection(msg.connectionId).then(connection => {
if (!!connection.stream) {
const stream = connection.stream;
Expand All @@ -750,9 +744,9 @@ export class Session extends EventDispatcher {
this.remoteConnections.delete(connection.connectionId);
this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]);
})
.catch(openViduError => {
logger.error(openViduError);
});
.catch(openViduError => {
logger.error(openViduError);
});
}
}

Expand Down Expand Up @@ -852,7 +846,7 @@ export class Session extends EventDispatcher {

if (!!msg.from) {
// Signal sent by other client
this.getConnection(msg.from, "Connection '" + msg.from + "' unknow when 'onNewMessage'. Existing remote connections: "
this.getConnection(msg.from, "Connection '" + msg.from + "' unknown when 'onNewMessage'. Existing remote connections: "
+ JSON.stringify(this.remoteConnections.keys()) + '. Existing local connection: ' + this.connection.connectionId)

.then(connection => {
Expand Down Expand Up @@ -1100,13 +1094,13 @@ export class Session extends EventDispatcher {
someReconnection = true;
}
// Re-establish Subscriber streams
for (let remoteConnection of Object.values(this.remoteConnections)) {
this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream && remoteConnection.stream.streamIceConnectionStateBroken()) {
logger.warn('Re-establishing Subscriber ' + remoteConnection.stream.streamId);
remoteConnection.stream.initWebRtcPeerReceive(true);
someReconnection = true;
}
}
});
if (!someReconnection) {
logger.info('There were no media streams in need of a reconnection');
}
Expand Down Expand Up @@ -1202,7 +1196,7 @@ export class Session extends EventDispatcher {
if (loops < maxLoops) {
loops++;
obtainAndSendVideo();
}else {
} else {
clearInterval(this.videoDataInterval);
}
}, intervalSeconds * 1000);
Expand Down Expand Up @@ -1334,7 +1328,7 @@ export class Session extends EventDispatcher {
resolve(connection);
} else {
// Remote connection not found. Reject with OpenViduError
const errorMessage = 'Remote connection ' + connectionId + " unknown when 'onParticipantLeft'. " +
const errorMessage = 'Remote connection ' + connectionId + " unknown when 'onParticipantLeft'. " +
'Existing remote connections: ' + JSON.stringify(this.remoteConnections.keys());

reject(new OpenViduError(OpenViduErrorName.GENERIC_ERROR, errorMessage));
Expand Down
2 changes: 1 addition & 1 deletion openvidu-browser/src/OpenVidu/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ export class Stream extends EventDispatcher {
return false;
}
if (this.isLocal() && !!this.session.openvidu.advancedConfiguration.forceMediaReconnectionAfterNetworkDrop) {
logger.warn('OpenVidu Browser advanced configuration option "forceMediaReconnectionAfterNetworkDrop" is enabled. Publisher stream ' + this.streamId + 'will force a reconnection');
logger.warn('OpenVidu Browser advanced configuration option "forceMediaReconnectionAfterNetworkDrop" is enabled. Stream ' + this.streamId + ' will force a reconnection');
return true;
}
const iceConnectionState: RTCIceConnectionState = this.getRTCPeerConnection().iceConnectionState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ export class SessionDisconnectedEvent extends Event {
const session = <Session>this.target;

// Dispose and delete all remote Connections
for (const connectionId in session.remoteConnections) {
session.remoteConnections.forEach(remoteConnection => {
const connectionId = remoteConnection.connectionId;
if (!!session.remoteConnections.get(connectionId)?.stream) {
session.remoteConnections.get(connectionId)?.stream!.disposeWebRtcPeer();
session.remoteConnections.get(connectionId)?.stream!.disposeMediaStream();
if (session.remoteConnections.get(connectionId)?.stream!.streamManager) {
session.remoteConnections.get(connectionId)?.stream!.streamManager.removeAllVideos();
}
const streamId = session.remoteConnections.get(connectionId)?.stream?.streamId;
if(!!streamId){
if (!!streamId) {
session.remoteStreamsCreated.delete(streamId);
}
session.remoteConnections.get(connectionId)?.dispose();
}
session.remoteConnections.delete(connectionId);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class StreamEvent extends Event {
if (this.stream.streamManager) this.stream.streamManager.removeAllVideos();

// Delete stream from Session.remoteStreamsCreated map
delete this.stream.session.remoteStreamsCreated[this.stream.streamId];
this.stream.session.remoteStreamsCreated.delete(this.stream.streamId);

// Delete StreamOptionsServer from remote Connection
const remoteConnection = this.stream.session.remoteConnections.get(this.stream.connection.connectionId);
Expand Down

0 comments on commit f672090

Please sign in to comment.