Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
Implements switching streams on firefox by using RTPSender.replaceTrack(). Fixes bugs with switching between camera and screen sharing.
Boris Grozeva5e15025f8b9
diff --git a/modules/xmpp/JingleSessionPC.js b/modules/xmpp/JingleSessionPC.jsindex 6253096d8a..a76448120d 100644--- a/modules/xmpp/JingleSessionPC.js+++ b/modules/xmpp/JingleSessionPC.js@@ -1120,20 +1120,56 @@ JingleSessionPC.prototype._modifySources = function (successCallback, queueCallb* @param newStream new stream that will be used as video of this session.* @param oldStream old video stream of this session.* @param successCallback callback executed after successful stream switch.+ * @param isAudio whether the streams are audio (if true) or video (if false).*/-JingleSessionPC.prototype.switchStreams = function (newStream, oldStream, successCallback) {-+JingleSessionPC.prototype.switchStreams =+ function (newStream, oldStream, successCallback, isAudio) {var self = this;-+ var sender, newTrack;+ var senderKind = isAudio ? 'audio' : 'video';// Remember SDP to figure out added/removed SSRCsvar oldSdp = null;+if (self.peerconnection) {if (self.peerconnection.localDescription) {oldSdp = new SDP(self.peerconnection.localDescription.sdp);}- self.peerconnection.removeStream(oldStream, true);- if (newStream)- self.peerconnection.addStream(newStream);+ if (RTCBrowserType.getBrowserType() ===+ RTCBrowserType.RTC_BROWSER_FIREFOX) {+ // On Firefox we don't replace MediaStreams as this messes up the+ // m-lines (which can't be removed in Plan Unified) and brings a lot+ // of complications. Instead, we use the RTPSender and replace just+ // the track.++ // Find the right sender (for audio or video)+ self.peerconnection.peerconnection.getSenders().some(function (s) {+ if (s.track && s.track.kind === senderKind) {+ sender = s;+ return true;+ }+ });++ if (sender) {+ // We assume that our streams have a single track, either audio+ // or video.+ newTrack = isAudio ? newStream.getAudioTracks()[0] :+ newStream.getVideoTracks()[0];+ sender.replaceTrack(newTrack)+ .then(function() {+ console.log("Replaced a track, isAudio=" + isAudio);+ })+ .catch(function(err) {+ console.log("Failed to replace a track: " + err);+ });+ } else {+ console.log("Cannot switch tracks: no RTPSender.");+ }+ } else {+ self.peerconnection.removeStream(oldStream, true);+ if (newStream) {+ self.peerconnection.addStream(newStream);+ }+ }}// Conference is not active