openvidu-browser: fix Map refactoring bugs (for..in not working on Map)

pull/609/head
pabloFuente 2021-02-18 16:00:07 +01:00
parent d91721c11d
commit f672090757
4 changed files with 39 additions and 44 deletions

View File

@ -616,22 +616,20 @@ export class Session extends EventDispatcher {
if (type === 'publisherStartSpeaking') { if (type === 'publisherStartSpeaking') {
this.startSpeakingEventsEnabled = true; this.startSpeakingEventsEnabled = true;
// If there are already available remote streams, enable hark 'speaking' event in all of them // If there are already available remote streams, enable hark 'speaking' event in all of them
for (const connectionId in this.remoteConnections) { this.remoteConnections.forEach(remoteConnection => {
const str = this.remoteConnections.get(connectionId)?.stream; if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
if (!!str && str.hasAudio) { remoteConnection.stream.enableStartSpeakingEvent();
str.enableStartSpeakingEvent();
} }
} });
} }
if (type === 'publisherStopSpeaking') { if (type === 'publisherStopSpeaking') {
this.stopSpeakingEventsEnabled = true; this.stopSpeakingEventsEnabled = true;
// If there are already available remote streams, enable hark 'stopped_speaking' event in all of them // If there are already available remote streams, enable hark 'stopped_speaking' event in all of them
for (const connectionId in this.remoteConnections) { this.remoteConnections.forEach(remoteConnection => {
const str = this.remoteConnections.get(connectionId)?.stream; if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
if (!!str && str.hasAudio) { remoteConnection.stream.enableStopSpeakingEvent();
str.enableStopSpeakingEvent();
} }
} });
} }
return this; return this;
@ -648,22 +646,20 @@ export class Session extends EventDispatcher {
if (type === 'publisherStartSpeaking') { if (type === 'publisherStartSpeaking') {
this.startSpeakingEventsEnabledOnce = true; this.startSpeakingEventsEnabledOnce = true;
// If there are already available remote streams, enable hark 'speaking' event in all of them once // If there are already available remote streams, enable hark 'speaking' event in all of them once
for (const connectionId in this.remoteConnections) { this.remoteConnections.forEach(remoteConnection => {
const str = this.remoteConnections.get(connectionId)?.stream; if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
if (!!str && str.hasAudio) { remoteConnection.stream.enableOnceStartSpeakingEvent();
str.enableOnceStartSpeakingEvent();
} }
} });
} }
if (type === 'publisherStopSpeaking') { if (type === 'publisherStopSpeaking') {
this.stopSpeakingEventsEnabledOnce = true; this.stopSpeakingEventsEnabledOnce = true;
// If there are already available remote streams, enable hark 'stopped_speaking' event in all of them once // If there are already available remote streams, enable hark 'stopped_speaking' event in all of them once
for (const connectionId in this.remoteConnections) { this.remoteConnections.forEach(remoteConnection => {
const str = this.remoteConnections.get(connectionId)?.stream; if (!!remoteConnection.stream && remoteConnection.stream.hasAudio) {
if (!!str && str.hasAudio) { remoteConnection.stream.enableOnceStopSpeakingEvent();
str.enableOnceStopSpeakingEvent();
} }
} });
} }
return this; return this;
@ -682,12 +678,11 @@ export class Session extends EventDispatcher {
if (remainingStartSpeakingListeners === 0) { if (remainingStartSpeakingListeners === 0) {
this.startSpeakingEventsEnabled = false; this.startSpeakingEventsEnabled = false;
// If there are already available remote streams, disable hark in all of them // If there are already available remote streams, disable hark in all of them
for (const connectionId in this.remoteConnections) { this.remoteConnections.forEach(remoteConnection => {
const str = this.remoteConnections.get(connectionId)?.stream; if (!!remoteConnection.stream) {
if (!!str) { remoteConnection.stream.disableStartSpeakingEvent(false);
str.disableStartSpeakingEvent(false);
} }
} });
} }
} }
if (type === 'publisherStopSpeaking') { if (type === 'publisherStopSpeaking') {
@ -695,12 +690,11 @@ export class Session extends EventDispatcher {
if (remainingStopSpeakingListeners === 0) { if (remainingStopSpeakingListeners === 0) {
this.stopSpeakingEventsEnabled = false; this.stopSpeakingEventsEnabled = false;
// If there are already available remote streams, disable hark in all of them // If there are already available remote streams, disable hark in all of them
for (const connectionId in this.remoteConnections) { this.remoteConnections.forEach(remoteConnection => {
const str = this.remoteConnections.get(connectionId)?.stream; if (!!remoteConnection.stream) {
if (!!str) { remoteConnection.stream.disableStopSpeakingEvent(false);
str.disableStopSpeakingEvent(false);
} }
} });
} }
} }
return this; return this;
@ -731,7 +725,7 @@ export class Session extends EventDispatcher {
*/ */
onParticipantLeft(msg): void { onParticipantLeft(msg): void {
if(this.remoteConnections.size > 0) { if (this.remoteConnections.size > 0) {
this.getRemoteConnection(msg.connectionId).then(connection => { this.getRemoteConnection(msg.connectionId).then(connection => {
if (!!connection.stream) { if (!!connection.stream) {
const stream = connection.stream; const stream = connection.stream;
@ -750,9 +744,9 @@ export class Session extends EventDispatcher {
this.remoteConnections.delete(connection.connectionId); this.remoteConnections.delete(connection.connectionId);
this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]); this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]);
}) })
.catch(openViduError => { .catch(openViduError => {
logger.error(openViduError); logger.error(openViduError);
}); });
} }
} }
@ -852,7 +846,7 @@ export class Session extends EventDispatcher {
if (!!msg.from) { if (!!msg.from) {
// Signal sent by other client // 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) + JSON.stringify(this.remoteConnections.keys()) + '. Existing local connection: ' + this.connection.connectionId)
.then(connection => { .then(connection => {
@ -1100,13 +1094,13 @@ export class Session extends EventDispatcher {
someReconnection = true; someReconnection = true;
} }
// Re-establish Subscriber streams // Re-establish Subscriber streams
for (let remoteConnection of Object.values(this.remoteConnections)) { this.remoteConnections.forEach(remoteConnection => {
if (!!remoteConnection.stream && remoteConnection.stream.streamIceConnectionStateBroken()) { if (!!remoteConnection.stream && remoteConnection.stream.streamIceConnectionStateBroken()) {
logger.warn('Re-establishing Subscriber ' + remoteConnection.stream.streamId); logger.warn('Re-establishing Subscriber ' + remoteConnection.stream.streamId);
remoteConnection.stream.initWebRtcPeerReceive(true); remoteConnection.stream.initWebRtcPeerReceive(true);
someReconnection = true; someReconnection = true;
} }
} });
if (!someReconnection) { if (!someReconnection) {
logger.info('There were no media streams in need of a reconnection'); logger.info('There were no media streams in need of a reconnection');
} }
@ -1202,7 +1196,7 @@ export class Session extends EventDispatcher {
if (loops < maxLoops) { if (loops < maxLoops) {
loops++; loops++;
obtainAndSendVideo(); obtainAndSendVideo();
}else { } else {
clearInterval(this.videoDataInterval); clearInterval(this.videoDataInterval);
} }
}, intervalSeconds * 1000); }, intervalSeconds * 1000);
@ -1334,7 +1328,7 @@ export class Session extends EventDispatcher {
resolve(connection); resolve(connection);
} else { } else {
// Remote connection not found. Reject with OpenViduError // 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()); 'Existing remote connections: ' + JSON.stringify(this.remoteConnections.keys());
reject(new OpenViduError(OpenViduErrorName.GENERIC_ERROR, errorMessage)); reject(new OpenViduError(OpenViduErrorName.GENERIC_ERROR, errorMessage));

View File

@ -780,7 +780,7 @@ export class Stream extends EventDispatcher {
return false; return false;
} }
if (this.isLocal() && !!this.session.openvidu.advancedConfiguration.forceMediaReconnectionAfterNetworkDrop) { 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; return true;
} }
const iceConnectionState: RTCIceConnectionState = this.getRTCPeerConnection().iceConnectionState; const iceConnectionState: RTCIceConnectionState = this.getRTCPeerConnection().iceConnectionState;

View File

@ -60,7 +60,8 @@ export class SessionDisconnectedEvent extends Event {
const session = <Session>this.target; const session = <Session>this.target;
// Dispose and delete all remote Connections // 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) { if (!!session.remoteConnections.get(connectionId)?.stream) {
session.remoteConnections.get(connectionId)?.stream!.disposeWebRtcPeer(); session.remoteConnections.get(connectionId)?.stream!.disposeWebRtcPeer();
session.remoteConnections.get(connectionId)?.stream!.disposeMediaStream(); session.remoteConnections.get(connectionId)?.stream!.disposeMediaStream();
@ -68,13 +69,13 @@ export class SessionDisconnectedEvent extends Event {
session.remoteConnections.get(connectionId)?.stream!.streamManager.removeAllVideos(); session.remoteConnections.get(connectionId)?.stream!.streamManager.removeAllVideos();
} }
const streamId = session.remoteConnections.get(connectionId)?.stream?.streamId; const streamId = session.remoteConnections.get(connectionId)?.stream?.streamId;
if(!!streamId){ if (!!streamId) {
session.remoteStreamsCreated.delete(streamId); session.remoteStreamsCreated.delete(streamId);
} }
session.remoteConnections.get(connectionId)?.dispose(); session.remoteConnections.get(connectionId)?.dispose();
} }
session.remoteConnections.delete(connectionId); session.remoteConnections.delete(connectionId);
} });
} }
} }

View File

@ -97,7 +97,7 @@ export class StreamEvent extends Event {
if (this.stream.streamManager) this.stream.streamManager.removeAllVideos(); if (this.stream.streamManager) this.stream.streamManager.removeAllVideos();
// Delete stream from Session.remoteStreamsCreated map // 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 // Delete StreamOptionsServer from remote Connection
const remoteConnection = this.stream.session.remoteConnections.get(this.stream.connection.connectionId); const remoteConnection = this.stream.session.remoteConnections.get(this.stream.connection.connectionId);