From: Chad Phillips Date: Fri, 31 May 2019 17:52:18 +0000 (-0700) Subject: Fix FS-11873: addStream() adds audio/video tracks in random order X-Git-Tag: v1.8.6~1^2~50^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1bc56d65b44f1d97e1e9c690175fa8757e42c29;p=thirdparty%2Ffreeswitch.git Fix FS-11873: addStream() adds audio/video tracks in random order addStream() is a deprecated WebRTC API method, and only works via shimming on some platforms. Internally, it is inconsistent in building an offer SDP in the order which FreeSWITCH expects it, which is audio m-lines first. This can result in intermittent m-line ordering errors on the client. Instead addTrack() can be used to force the media tracks to be added to the peer in the order FreeSWITCH expects. --- diff --git a/html5/verto/js/src/jquery.FSRTC.js b/html5/verto/js/src/jquery.FSRTC.js index 3b0ef04290..1046f7c9e2 100644 --- a/html5/verto/js/src/jquery.FSRTC.js +++ b/html5/verto/js/src/jquery.FSRTC.js @@ -767,7 +767,13 @@ }; // attachStream = MediaStream; - if (options.attachStream) peer.addStream(options.attachStream); + if (options.attachStream) { + // FreeSWITCH currently orders its answer SDP such that audio m-lines + // always come first, adding the tracks to the peer in that order + // prevents possible m-line ordering validation errors on the client. + options.attachStream.getAudioTracks().forEach(function(track) { peer.addTrack(track, options.attachStream) }); + options.attachStream.getVideoTracks().forEach(function(track) { peer.addTrack(track, options.attachStream) }); + } // attachStreams[0] = audio-stream; // attachStreams[1] = video-stream;