From ce6beac85da281adad4b21613ec6ccfd755ffd30 Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Wed, 3 Feb 2021 17:41:25 +0100 Subject: [PATCH] openvidu-browser: Checked remoteConections size before find into it When two connections close at the same time, it shows the following error : OpenVidu Error Remote connection unknown when 'onParticipantLeft'. Existing remote connections: [] it has been avoided checking if remoteConnections is not empty --- openvidu-browser/src/OpenVidu/Session.ts | 37 ++++++++++++------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 199f134f..0f5bc0f6 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -731,28 +731,29 @@ export class Session extends EventDispatcher { */ onParticipantLeft(msg): void { - this.getRemoteConnection(msg.connectionId).then(connection => { - if (!!connection.stream) { - const stream = connection.stream; + if(this.remoteConnections.size > 0) { + this.getRemoteConnection(msg.connectionId).then(connection => { + if (!!connection.stream) { + const stream = connection.stream; - const streamEvent = new StreamEvent(true, this, 'streamDestroyed', stream, msg.reason); - this.ee.emitEvent('streamDestroyed', [streamEvent]); - streamEvent.callDefaultBehavior(); + const streamEvent = new StreamEvent(true, this, 'streamDestroyed', stream, msg.reason); + this.ee.emitEvent('streamDestroyed', [streamEvent]); + streamEvent.callDefaultBehavior(); - this.remoteStreamsCreated.delete(stream.streamId); + this.remoteStreamsCreated.delete(stream.streamId); - if (this.remoteStreamsCreated.size === 0) { - this.isFirstIonicIosSubscriber = true; - this.countDownForIonicIosSubscribersActive = true; + if (this.remoteStreamsCreated.size === 0) { + this.isFirstIonicIosSubscriber = true; + this.countDownForIonicIosSubscribersActive = true; + } } - } - this.remoteConnections.delete(connection.connectionId); - this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]); - }) - .catch(openViduError => { - logger.error(openViduError); - }); - + this.remoteConnections.delete(connection.connectionId); + this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]); + }) + .catch(openViduError => { + logger.error(openViduError); + }); + } } /**