From 285079cae276ca8144ae066d475b6e08f55eace0 Mon Sep 17 00:00:00 2001 From: kharhamel Date: Thu, 15 Jul 2021 16:31:43 +0200 Subject: [PATCH] FIX: VideoPeer destroy could be called twice --- front/src/WebRtc/VideoPeer.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/front/src/WebRtc/VideoPeer.ts b/front/src/WebRtc/VideoPeer.ts index 10bd54c7..9fadef8c 100644 --- a/front/src/WebRtc/VideoPeer.ts +++ b/front/src/WebRtc/VideoPeer.ts @@ -35,6 +35,7 @@ export class VideoPeer extends Peer { public readonly statusStore: Readable; public readonly constraintsStore: Readable; private newMessageunsubscriber: Unsubscriber | null = null; + private closing: Boolean = false; //this is used to prevent destroy() from being called twice constructor( public user: UserSimplePeerInterface, @@ -249,19 +250,18 @@ export class VideoPeer extends Peer { /** * This is triggered twice. Once by the server, and once by a remote client disconnecting */ - public destroy(error?: Error): void { + public destroy(): void { try { this._connected = false; - if (!this.toClose) { + if (!this.toClose || this.closing) { return; } + this.closing = true; this.onBlockSubscribe.unsubscribe(); this.onUnBlockSubscribe.unsubscribe(); if (this.newMessageunsubscriber) this.newMessageunsubscriber(); chatMessagesStore.addOutcomingUser(this.userId); - // FIXME: I don't understand why "Closing connection with" message is displayed TWICE before "Nb users in peerConnectionArray" - // I do understand the method closeConnection is called twice, but I don't understand how they manage to run in parallel. - super.destroy(error); + super.destroy(); } catch (err) { console.error("VideoPeer::destroy", err); }