|
|
@@ -79,12 +79,19 @@ export class TPCUtils {
|
|
79
|
79
|
_findTransceiver(mediaType, localTrack = null) {
|
|
80
|
80
|
let transceiver = null;
|
|
81
|
81
|
|
|
82
|
|
- if (localTrack) {
|
|
83
|
|
- transceiver = this.pc.peerconnection.getTransceivers()
|
|
84
|
|
- .find(t => t.sender?.track?.id === localTrack.getTrackId());
|
|
85
|
|
- } else if (mediaType) {
|
|
|
82
|
+ // Check if the local track has been removed from the peerconnection already.
|
|
|
83
|
+ const trackRemoved = !localTrack
|
|
|
84
|
+ || (localTrack
|
|
|
85
|
+ && browser.doesVideoMuteByStreamRemove()
|
|
|
86
|
+ && localTrack.isVideoTrack()
|
|
|
87
|
+ && localTrack.isMuted());
|
|
|
88
|
+
|
|
|
89
|
+ if (trackRemoved) {
|
|
86
|
90
|
transceiver = this.pc.peerconnection.getTransceivers()
|
|
87
|
91
|
.find(t => t.receiver?.track?.kind === mediaType);
|
|
|
92
|
+ } else if (localTrack) {
|
|
|
93
|
+ transceiver = this.pc.peerconnection.getTransceivers()
|
|
|
94
|
+ .find(t => t.sender?.track?.id === localTrack.getTrackId());
|
|
88
|
95
|
}
|
|
89
|
96
|
|
|
90
|
97
|
return transceiver;
|
|
|
@@ -328,9 +335,7 @@ export class TPCUtils {
|
|
328
|
335
|
return Promise.resolve();
|
|
329
|
336
|
}
|
|
330
|
337
|
|
|
331
|
|
- const transceiver = oldTrack.isVideoTrack() && browser.doesVideoMuteByStreamRemove && oldTrack.isMuted()
|
|
332
|
|
- ? this._findTransceiver(mediaType)
|
|
333
|
|
- : this._findTransceiver(mediaType, oldTrack);
|
|
|
338
|
+ const transceiver = this._findTransceiver(mediaType, oldTrack);
|
|
334
|
339
|
const track = newTrack.getTrack();
|
|
335
|
340
|
|
|
336
|
341
|
if (!transceiver) {
|
|
|
@@ -368,7 +373,6 @@ export class TPCUtils {
|
|
368
|
373
|
});
|
|
369
|
374
|
} else if (newTrack && !oldTrack) {
|
|
370
|
375
|
return this.addTrackUnmute(newTrack)
|
|
371
|
|
- .then(() => this.setEncodings(newTrack))
|
|
372
|
376
|
.then(() => {
|
|
373
|
377
|
const mediaType = newTrack.getType();
|
|
374
|
378
|
const transceiver = this._findTransceiver(mediaType, newTrack);
|
|
|
@@ -379,8 +383,15 @@ export class TPCUtils {
|
|
379
|
383
|
transceiver.direction = TransceiverDirection.SENDRECV;
|
|
380
|
384
|
}
|
|
381
|
385
|
|
|
382
|
|
- // Add the new track to the list of local tracks.
|
|
383
|
|
- this.pc.localTracks.set(newTrack.rtcId, newTrack);
|
|
|
386
|
+ // Avoid configuring the encodings on chromium since the encoding params are read-only
|
|
|
387
|
+ // until the renegotation is done after the track is replaced on the sender.
|
|
|
388
|
+ const promise = browser.isChromiumBased() ? Promise.resolve() : this.setEncodings(newTrack);
|
|
|
389
|
+
|
|
|
390
|
+ return promise
|
|
|
391
|
+ .then(() => {
|
|
|
392
|
+ // Add the new track to the list of local tracks.
|
|
|
393
|
+ this.pc.localTracks.set(newTrack.rtcId, newTrack);
|
|
|
394
|
+ });
|
|
384
|
395
|
});
|
|
385
|
396
|
}
|
|
386
|
397
|
|