Skip to content

Commit

Permalink
Fix lost audio track on safari
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
  • Loading branch information
SystemKeeper committed Nov 27, 2023
1 parent 7d47b43 commit 09360a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/webrtc/simplewebrtc/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import util from 'util'
import adapter from 'webrtc-adapter'
import webrtcSupport from 'webrtcsupport'
import WildEmitter from 'wildemitter'
import { isSafari } from '../../../utils/browserCheck.js'

/**
* @param {object} stream the stream object.
Expand Down Expand Up @@ -831,7 +832,10 @@ Peer.prototype._replaceTrack = async function(newTrack, oldTrack, stream) {
return
}

if (sender.track && newTrack && !newTrack.enabled) {
// When replacing with a null track on Safari the reference to the track is
// lost (setting trackDisabled is not enough). Therefore we keep the track
// intact and don't replace it with a null track.
if (sender.track && newTrack && !newTrack.enabled && !isSafari) {
// Replace with a null track to stop the sender.
newTrack = null
}
Expand Down Expand Up @@ -871,6 +875,8 @@ Peer.prototype.handleSentTrackEnabledChanged = function(track, stream) {
this.handleSentTrackReplacedBound(track, track, stream)
} else if (!track.enabled && sender) {
this.handleSentTrackReplacedBound(track, track, stream)
} else if (!sender && !stoppedSender) {
console.error('No sender found to handle localTrackEnabledChanged', track, stream)
}
}

Expand Down

0 comments on commit 09360a8

Please sign in to comment.