From f4568b9087067e3124468166d40ff9fdd7aa4043 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 8 Jul 2023 12:08:46 -0700 Subject: [PATCH] Properly release local media devices when user turns off their cam --- web/static/js/BareRTC.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/web/static/js/BareRTC.js b/web/static/js/BareRTC.js index 22478fa..ddc3ee6 100644 --- a/web/static/js/BareRTC.js +++ b/web/static/js/BareRTC.js @@ -1376,12 +1376,6 @@ const app = Vue.createApp({ // Stop broadcasting. stopVideo() { - this.webcam.elem.srcObject = null; - this.webcam.stream = null; - this.webcam.active = false; - this.webcam.muted = false; - this.whoTab = "online"; - // Close all WebRTC sessions. for (username of Object.keys(this.WebRTC.pc)) { this.closeVideo(username, "answerer"); @@ -1390,6 +1384,18 @@ const app = Vue.createApp({ // Hang up on mutual cameras. this.unMutualVideo(); + // Close the local camera devices completely. + this.webcam.stream.getTracks().forEach(track => { + track.stop(); + }); + + // Reset all front-end state. + this.webcam.elem.srcObject = null; + this.webcam.stream = null; + this.webcam.active = false; + this.webcam.muted = false; + this.whoTab = "online"; + // Tell backend our camera state. this.sendMe(); },