From 4aa1813383b5ae14e358e091ad5572d5c83ac893 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Mon, 14 Nov 2022 12:56:37 +0100 Subject: [PATCH] openvidu-browser: dispose remote Connection on connectionDestroyed event --- openvidu-browser/src/OpenVidu/Connection.ts | 57 +++++++++++---------- openvidu-browser/src/OpenVidu/Session.ts | 3 +- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/Connection.ts b/openvidu-browser/src/OpenVidu/Connection.ts index c3424572..e4372634 100644 --- a/openvidu-browser/src/OpenVidu/Connection.ts +++ b/openvidu-browser/src/OpenVidu/Connection.ts @@ -129,31 +129,36 @@ export class Connection { * @hidden */ sendIceCandidate(candidate: RTCIceCandidate): void { - logger.debug((!!this.stream!.outboundStreamOpts ? 'Local' : 'Remote') + 'candidate for' + this.connectionId, candidate); - this.session.openvidu.sendRequest( - 'onIceCandidate', - { - endpointName: this.connectionId, - candidate: candidate.candidate, - sdpMid: candidate.sdpMid, - sdpMLineIndex: candidate.sdpMLineIndex - }, - (error, response) => { - if (error) { - logger.error('Error sending ICE candidate: ' + JSON.stringify(error)); - this.session.emitEvent('exception', [ - new ExceptionEvent( - this.session, - ExceptionEventName.ICE_CANDIDATE_ERROR, - this.session, - 'There was an unexpected error on the server-side processing an ICE candidate generated and sent by the client-side', - error - ) - ]); + if (!this.disposed) { + logger.debug((!!this.stream!.outboundStreamOpts ? 'Local' : 'Remote') + 'candidate for' + this.connectionId, candidate); + + this.session.openvidu.sendRequest( + 'onIceCandidate', + { + endpointName: this.connectionId, + candidate: candidate.candidate, + sdpMid: candidate.sdpMid, + sdpMLineIndex: candidate.sdpMLineIndex + }, + (error, response) => { + if (error) { + logger.error('Error sending ICE candidate: ' + JSON.stringify(error)); + this.session.emitEvent('exception', [ + new ExceptionEvent( + this.session, + ExceptionEventName.ICE_CANDIDATE_ERROR, + this.session, + 'There was an unexpected error on the server-side processing an ICE candidate generated and sent by the client-side', + error + ) + ]); + } } - } - ); + ); + } else { + logger.warn(`Connection ${this.connectionId} disposed when trying to send an ICE candidate. ICE candidate not sent`); + } } /** @@ -198,7 +203,7 @@ export class Connection { /** * @hidden */ - removeStream(streamId: string): void { + removeStream(): void { delete this.stream; } @@ -206,9 +211,7 @@ export class Connection { * @hidden */ dispose(): void { - if (!!this.stream) { - delete this.stream; - } this.disposed = true; + this.removeStream(); } } diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 1d922d27..58397650 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -845,6 +845,7 @@ export class Session extends EventDispatcher { this.remoteStreamsCreated.delete(stream.streamId); } + connection.dispose(); this.remoteConnections.delete(connection.connectionId); this.ee.emitEvent('connectionDestroyed', [ new ConnectionEvent(false, this, 'connectionDestroyed', connection, event.reason) @@ -912,7 +913,7 @@ export class Session extends EventDispatcher { if (connection.stream != null) { const streamId: string = connection.stream!.streamId; this.remoteStreamsCreated.delete(streamId); - connection.removeStream(streamId); + connection.removeStream(); } }) .catch((openViduError) => {