From d65f0e508455a915edf30712b2686b88ef6bd125 Mon Sep 17 00:00:00 2001 From: Brandon Lee Date: Tue, 13 Dec 2022 04:36:55 -0800 Subject: [PATCH] Resolves issue of _audioMuted and _videoMuted not being synced with local mediaStream tracks. --- lib/RTCSession.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/RTCSession.js b/lib/RTCSession.js index df9e50a56..2c1b4806e 100644 --- a/lib/RTCSession.js +++ b/lib/RTCSession.js @@ -657,6 +657,7 @@ module.exports = class RTCSession extends EventEmitter // A local MediaStream is given, use it. if (mediaStream) { + this._checkLocalMediaStream(mediaStream); return mediaStream; } @@ -2621,6 +2622,7 @@ module.exports = class RTCSession extends EventEmitter // A stream is given, let the app set events such as 'peerconnection' and 'connecting'. if (mediaStream) { + this._checkLocalMediaStream(mediaStream); return mediaStream; } // Request for user media access. @@ -3444,6 +3446,26 @@ module.exports = class RTCSession extends EventEmitter } } + /** + * Syncs muted status of audio to mediaStream option passed to answer and connect functions. + */ + _checkLocalMediaStream(mediaStream) { + + if (!mediaStream || typeof mediaStream.getTracks !== "function") + return; + + mediaStream.getTracks().forEach((track) => { + + if (track.kind === "audio") { + this._audioMuted = track.enabled ? false : true; + } + else { + this._videoMuted = track.enabled ? false : true; + } + + }); + } + _toggleMuteAudio(mute) { const senders = this._connection.getSenders().filter((sender) =>