From bf576c540bd3740167c9490c195a6c32770e05a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Wed, 15 Nov 2023 23:42:21 +0100 Subject: [PATCH] Keep track of senders to allow unmutung with Safari MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- src/utils/webrtc/simplewebrtc/peer.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/webrtc/simplewebrtc/peer.js b/src/utils/webrtc/simplewebrtc/peer.js index 7c2f50a2f81..d7001d400a5 100644 --- a/src/utils/webrtc/simplewebrtc/peer.js +++ b/src/utils/webrtc/simplewebrtc/peer.js @@ -41,6 +41,7 @@ function Peer(options) { this._pendingReplaceTracksQueue = [] this._processPendingReplaceTracksPromise = null this._initialStreamSetup = false + this._localSenders = [] this.sid = options.sid || Date.now().toString() this.pc = new RTCPeerConnection(this.parent.config.peerConnectionConfig) this.pc.addEventListener('icecandidate', this.onIceCandidate.bind(this)) @@ -674,6 +675,7 @@ Peer.prototype.end = function() { } this.pc.close() this.handleStreamRemoved() + this._localSenders = [] this.parent.off('sentTrackReplaced', this.handleSentTrackReplacedBound) this.parent.off('sentTrackEnabledChanged', this.handleSentTrackEnabledChangedBound) @@ -770,7 +772,10 @@ Peer.prototype._replaceTrack = async function(newTrack, oldTrack, stream) { // is used to be on the safe side. const replaceTrackPromises = [] - this.pc.getSenders().forEach(sender => { + for (const sender of this.pc.getSenders()) { + // Keep reference, so that safari does not remove the tracks + this._localSenders.push(sender) + if (sender.track !== oldTrack && sender.trackDisabled !== oldTrack) { return } @@ -849,7 +854,7 @@ Peer.prototype._replaceTrack = async function(newTrack, oldTrack, stream) { }) replaceTrackPromises.push(replaceTrackPromise) - }) + } // If the call started when the audio or video device was not active there // will be no sender for that type. In that case the track needs to be added