openvidu-browser: dispose remote Connection on connectionDestroyed event

pull/761/head
pabloFuente 2022-11-14 12:56:37 +01:00
parent b2426149c6
commit 4aa1813383
2 changed files with 32 additions and 28 deletions

View File

@ -129,31 +129,36 @@ export class Connection {
* @hidden * @hidden
*/ */
sendIceCandidate(candidate: RTCIceCandidate): void { sendIceCandidate(candidate: RTCIceCandidate): void {
logger.debug((!!this.stream!.outboundStreamOpts ? 'Local' : 'Remote') + 'candidate for' + this.connectionId, candidate);
this.session.openvidu.sendRequest( if (!this.disposed) {
'onIceCandidate', logger.debug((!!this.stream!.outboundStreamOpts ? 'Local' : 'Remote') + 'candidate for' + this.connectionId, candidate);
{
endpointName: this.connectionId, this.session.openvidu.sendRequest(
candidate: candidate.candidate, 'onIceCandidate',
sdpMid: candidate.sdpMid, {
sdpMLineIndex: candidate.sdpMLineIndex endpointName: this.connectionId,
}, candidate: candidate.candidate,
(error, response) => { sdpMid: candidate.sdpMid,
if (error) { sdpMLineIndex: candidate.sdpMLineIndex
logger.error('Error sending ICE candidate: ' + JSON.stringify(error)); },
this.session.emitEvent('exception', [ (error, response) => {
new ExceptionEvent( if (error) {
this.session, logger.error('Error sending ICE candidate: ' + JSON.stringify(error));
ExceptionEventName.ICE_CANDIDATE_ERROR, this.session.emitEvent('exception', [
this.session, new ExceptionEvent(
'There was an unexpected error on the server-side processing an ICE candidate generated and sent by the client-side', this.session,
error 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 * @hidden
*/ */
removeStream(streamId: string): void { removeStream(): void {
delete this.stream; delete this.stream;
} }
@ -206,9 +211,7 @@ export class Connection {
* @hidden * @hidden
*/ */
dispose(): void { dispose(): void {
if (!!this.stream) {
delete this.stream;
}
this.disposed = true; this.disposed = true;
this.removeStream();
} }
} }

View File

@ -845,6 +845,7 @@ export class Session extends EventDispatcher {
this.remoteStreamsCreated.delete(stream.streamId); this.remoteStreamsCreated.delete(stream.streamId);
} }
connection.dispose();
this.remoteConnections.delete(connection.connectionId); this.remoteConnections.delete(connection.connectionId);
this.ee.emitEvent('connectionDestroyed', [ this.ee.emitEvent('connectionDestroyed', [
new ConnectionEvent(false, this, 'connectionDestroyed', connection, event.reason) new ConnectionEvent(false, this, 'connectionDestroyed', connection, event.reason)
@ -912,7 +913,7 @@ export class Session extends EventDispatcher {
if (connection.stream != null) { if (connection.stream != null) {
const streamId: string = connection.stream!.streamId; const streamId: string = connection.stream!.streamId;
this.remoteStreamsCreated.delete(streamId); this.remoteStreamsCreated.delete(streamId);
connection.removeStream(streamId); connection.removeStream();
} }
}) })
.catch((openViduError) => { .catch((openViduError) => {