|
@@ -1802,43 +1802,53 @@ export default class JingleSessionPC extends JingleSession {
|
1802
|
1802
|
* @returns {void}
|
1803
|
1803
|
*/
|
1804
|
1804
|
processSourceMap(message, mediaType) {
|
1805
|
|
- const newSources = [];
|
|
1805
|
+ const newSsrcs = [];
|
1806
|
1806
|
|
1807
|
1807
|
for (const src of message.mappedSources) {
|
1808
|
|
- if (this.peerconnection.addRemoteSsrc(src.ssrc)) {
|
1809
|
|
- newSources.push(src);
|
1810
|
|
- } else {
|
1811
|
|
- const { owner, source, ssrc, videoType } = src;
|
1812
|
|
- const track = this.peerconnection.getTrackBySSRC(ssrc);
|
|
1808
|
+ // eslint-disable-next-line prefer-const
|
|
1809
|
+ let { owner, source, ssrc, videoType } = src;
|
|
1810
|
+ const isNewSsrc = this.peerconnection.addRemoteSsrc(ssrc, source);
|
|
1811
|
+ let lookupSsrc = ssrc;
|
1813
|
1812
|
|
1814
|
|
- if (track) {
|
1815
|
|
- logger.debug(`Existing SSRC ${ssrc}: new owner=${owner}, source-name=${source}`);
|
|
1813
|
+ if (isNewSsrc) {
|
|
1814
|
+ newSsrcs.push(src);
|
1816
|
1815
|
|
1817
|
|
- // Update the SSRC owner.
|
1818
|
|
- this._signalingLayer.setSSRCOwner(ssrc, owner);
|
|
1816
|
+ // Check if there is an old mapping for the given source and clear the owner on the associated track.
|
|
1817
|
+ const oldSsrc = this.peerconnection.remoteSources.get(source);
|
1819
|
1818
|
|
1820
|
|
- // Update the track with all the relevant info.
|
1821
|
|
- track.setSourceName(source);
|
1822
|
|
- track.setOwner(owner);
|
1823
|
|
- if (mediaType === MediaType.VIDEO) {
|
1824
|
|
- const type = videoType === 'CAMERA' ? VideoType.CAMERA : VideoType.DESKTOP;
|
|
1819
|
+ if (oldSsrc) {
|
|
1820
|
+ lookupSsrc = oldSsrc;
|
|
1821
|
+ owner = undefined;
|
|
1822
|
+ source = undefined;
|
|
1823
|
+ }
|
|
1824
|
+ }
|
|
1825
|
+ const track = this.peerconnection.getTrackBySSRC(lookupSsrc);
|
1825
|
1826
|
|
1826
|
|
- track._setVideoType(type);
|
1827
|
|
- }
|
|
1827
|
+ if (track) {
|
|
1828
|
+ logger.debug(`Existing SSRC ${ssrc}: new owner=${owner}, source-name=${source}`);
|
1828
|
1829
|
|
1829
|
|
- // Update the muted state on the track since the presence for this track could have been received
|
1830
|
|
- // before the updated source map is received on the bridge channel.
|
1831
|
|
- const peerMediaInfo = this._signalingLayer.getPeerMediaInfo(owner, mediaType, source);
|
|
1830
|
+ // Update the SSRC owner.
|
|
1831
|
+ this._signalingLayer.setSSRCOwner(ssrc, owner);
|
1832
|
1832
|
|
1833
|
|
- peerMediaInfo && this.peerconnection._sourceMutedChanged(source, peerMediaInfo.muted);
|
1834
|
|
- } else {
|
1835
|
|
- logger.error(`Remote track attached to a remote SSRC=${ssrc} not found`);
|
|
1833
|
+ // Update the track with all the relevant info.
|
|
1834
|
+ track.setSourceName(source);
|
|
1835
|
+ track.setOwner(owner);
|
|
1836
|
+ if (mediaType === MediaType.VIDEO) {
|
|
1837
|
+ const type = videoType === 'CAMERA' ? VideoType.CAMERA : VideoType.DESKTOP;
|
|
1838
|
+
|
|
1839
|
+ track._setVideoType(type);
|
1836
|
1840
|
}
|
|
1841
|
+
|
|
1842
|
+ // Update the muted state on the track since the presence for this track could have been received
|
|
1843
|
+ // before the updated source map is received on the bridge channel.
|
|
1844
|
+ const peerMediaInfo = this._signalingLayer.getPeerMediaInfo(owner, mediaType, source);
|
|
1845
|
+
|
|
1846
|
+ peerMediaInfo && this.peerconnection._sourceMutedChanged(source, peerMediaInfo.muted);
|
1837
|
1847
|
}
|
1838
|
1848
|
}
|
1839
|
1849
|
|
1840
|
1850
|
// Add the new SSRCs to the remote description by generating a source message.
|
1841
|
|
- if (newSources.length) {
|
|
1851
|
+ if (newSsrcs.length) {
|
1842
|
1852
|
let node = $build('content', {
|
1843
|
1853
|
xmlns: 'urn:xmpp:jingle:1',
|
1844
|
1854
|
name: mediaType
|
|
@@ -1847,8 +1857,8 @@ export default class JingleSessionPC extends JingleSession {
|
1847
|
1857
|
media: mediaType
|
1848
|
1858
|
});
|
1849
|
1859
|
|
1850
|
|
- for (const src of newSources) {
|
1851
|
|
- const { rtx, ssrc } = src;
|
|
1860
|
+ for (const src of newSsrcs) {
|
|
1861
|
+ const { rtx, ssrc, source } = src;
|
1852
|
1862
|
let msid;
|
1853
|
1863
|
|
1854
|
1864
|
if (mediaType === MediaType.VIDEO) {
|
|
@@ -1880,6 +1890,7 @@ export default class JingleSessionPC extends JingleSession {
|
1880
|
1890
|
msid = `remote-audio-${idx} remote-audio-${idx}`;
|
1881
|
1891
|
}
|
1882
|
1892
|
_addSourceElement(node, src, ssrc, msid);
|
|
1893
|
+ this.peerconnection.remoteSources.set(source, ssrc);
|
1883
|
1894
|
}
|
1884
|
1895
|
node = node.up();
|
1885
|
1896
|
this._addOrRemoveRemoteStream(true /* add */, node.node);
|