From 65d1017aed656ccf5da8c00ec653b0dda2cc5046 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 13 Apr 2020 14:22:20 +0200 Subject: [PATCH] Release ressources whenever it is possible --- assets/js/components/calls/window.js | 41 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/assets/js/components/calls/window.js b/assets/js/components/calls/window.js index 9725375f..c87efe33 100644 --- a/assets/js/components/calls/window.js +++ b/assets/js/components/calls/window.js @@ -364,15 +364,9 @@ class CallWindow extends CustomEvents { if(this.mainPeer) { - this.mainPeer.destroy(); - delete this.mainPeer; + this.closeMainPeer() } - // Release user media - if(this.mainStream) { - this.mainStream.getTracks().forEach(e => e.stop()) - } - // Destroy peer connections for(const el of this.peersEls) el[1].destroy() @@ -486,12 +480,18 @@ class CallWindow extends CustomEvents { const hasVideo = (this.mainPeer && !this.mainPeer.destroyed && this.mainStream && this.mainStream.getVideoTracks().length > 0) === true; // Check if current stream is not enough - if(hasAudio && isVideo && !hasVideo) - this.mainPeer.destroy() + if(hasAudio && isVideo && !hasVideo) { + this.closeMainPeer() + } // Check if we have to start stream or just to mute them if(!hasAudio || (isVideo && !hasVideo)) { - await this.startStreaming(isVideo) + try { + await this.startStreaming(isVideo) + } catch(e) { + notify("Could not start streaming ! (did you block access to your camera / microphone ?)", "danger") + console.error(e) + } } // Toggle mute @@ -674,6 +674,25 @@ class CallWindow extends CustomEvents { });*/ } + /** + * Close main peer connection + */ + async closeMainPeer() { + + + // Close peer connection + if(this.mainPeer) { + this.mainPeer.destroy(); + delete this.mainPeer; + } + + // Release user media + if(this.mainStream) { + this.mainStream.getTracks().forEach(e => e.stop()) + delete this.mainStream + } + } + /** * Start to receive video from remote peer * @@ -729,8 +748,6 @@ class CallWindow extends CustomEvents { callID: this.callID, peerID: peerID, }) - - console.log(peer) } /**