Properly release local media devices when user turns off their cam

This commit is contained in:
Noah 2023-07-08 12:08:46 -07:00
parent 3a334a8d68
commit f4568b9087

View File

@ -1376,12 +1376,6 @@ const app = Vue.createApp({
// Stop broadcasting. // Stop broadcasting.
stopVideo() { 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. // Close all WebRTC sessions.
for (username of Object.keys(this.WebRTC.pc)) { for (username of Object.keys(this.WebRTC.pc)) {
this.closeVideo(username, "answerer"); this.closeVideo(username, "answerer");
@ -1390,6 +1384,18 @@ const app = Vue.createApp({
// Hang up on mutual cameras. // Hang up on mutual cameras.
this.unMutualVideo(); 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. // Tell backend our camera state.
this.sendMe(); this.sendMe();
}, },