Release ressources whenever it is possible

This commit is contained in:
Pierre HUBERT 2020-04-13 14:22:20 +02:00
parent a4f5228037
commit 65d1017aed

View File

@ -364,13 +364,7 @@ class CallWindow extends CustomEvents {
if(this.mainPeer) { if(this.mainPeer) {
this.mainPeer.destroy(); this.closeMainPeer()
delete this.mainPeer;
}
// Release user media
if(this.mainStream) {
this.mainStream.getTracks().forEach(e => e.stop())
} }
// Destroy peer connections // Destroy peer connections
@ -486,12 +480,18 @@ class CallWindow extends CustomEvents {
const hasVideo = (this.mainPeer && !this.mainPeer.destroyed && this.mainStream && this.mainStream.getVideoTracks().length > 0) === true; const hasVideo = (this.mainPeer && !this.mainPeer.destroyed && this.mainStream && this.mainStream.getVideoTracks().length > 0) === true;
// Check if current stream is not enough // Check if current stream is not enough
if(hasAudio && isVideo && !hasVideo) if(hasAudio && isVideo && !hasVideo) {
this.mainPeer.destroy() this.closeMainPeer()
}
// Check if we have to start stream or just to mute them // Check if we have to start stream or just to mute them
if(!hasAudio || (isVideo && !hasVideo)) { if(!hasAudio || (isVideo && !hasVideo)) {
try {
await this.startStreaming(isVideo) 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 // 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 * Start to receive video from remote peer
* *
@ -729,8 +748,6 @@ class CallWindow extends CustomEvents {
callID: this.callID, callID: this.callID,
peerID: peerID, peerID: peerID,
}) })
console.log(peer)
} }
/** /**