Merge pull request #1288 from thecodingmachine/fixVideoBox

FIX: VideoPeer destroy could be called twice
This commit is contained in:
Kharhamel 2021-07-15 16:46:21 +02:00 committed by GitHub
commit f2ca7b2b16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,7 @@ export class VideoPeer extends Peer {
public readonly statusStore: Readable<PeerStatus>; public readonly statusStore: Readable<PeerStatus>;
public readonly constraintsStore: Readable<MediaStreamConstraints | null>; public readonly constraintsStore: Readable<MediaStreamConstraints | null>;
private newMessageunsubscriber: Unsubscriber | null = null; private newMessageunsubscriber: Unsubscriber | null = null;
private closing: Boolean = false; //this is used to prevent destroy() from being called twice
constructor( constructor(
public user: UserSimplePeerInterface, 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 * This is triggered twice. Once by the server, and once by a remote client disconnecting
*/ */
public destroy(error?: Error): void { public destroy(): void {
try { try {
this._connected = false; this._connected = false;
if (!this.toClose) { if (!this.toClose || this.closing) {
return; return;
} }
this.closing = true;
this.onBlockSubscribe.unsubscribe(); this.onBlockSubscribe.unsubscribe();
this.onUnBlockSubscribe.unsubscribe(); this.onUnBlockSubscribe.unsubscribe();
if (this.newMessageunsubscriber) this.newMessageunsubscriber(); if (this.newMessageunsubscriber) this.newMessageunsubscriber();
chatMessagesStore.addOutcomingUser(this.userId); chatMessagesStore.addOutcomingUser(this.userId);
// FIXME: I don't understand why "Closing connection with" message is displayed TWICE before "Nb users in peerConnectionArray" super.destroy();
// I do understand the method closeConnection is called twice, but I don't understand how they manage to run in parallel.
super.destroy(error);
} catch (err) { } catch (err) {
console.error("VideoPeer::destroy", err); console.error("VideoPeer::destroy", err);
} }