I am creating multiple webrtc peer connections and creating a single mediastream using
if (mediaStream == undefined) {
navigator.mediaDevices.getUserMedia({
audio: true,
video: true
}).then(function (stream) {
mediaStream = stream;
mediaStream.getTracks().forEach(function (track) {
rtcPeerConns[userName].addTrack(track, mediaStream);
});
}).catch(function (err) {
console.log("get user media " + err.name + ": " + err.message);
});
} else {
console.log("using the existing local stream");
mediaStream.getTracks().forEach(function (track) {
rtcPeerConns[userName].addTrack(track, mediaStream);
});
}
Everything works perfectly until the last peer connection is closed and I want to close the mediastream.
if (mediaStream != undefined) {
if (mediaStream.active) {
mediaStream.getTracks().forEach(function (track) {
track.stop();
});
mediaStream = null;
}
}
If only 1 peer connection has been used then everything shuts down as planned. If more than 1 peer connection has used the MediaStream then the MediaStream becomes null , but the camera indicator on the browser and the camera light both stay on.
What am I missing?