|
@@ -376,7 +376,10 @@ export class TPCUtils {
|
376
|
376
|
transceiver = this.pc.peerconnection.getTransceivers().find(
|
377
|
377
|
t => t.receiver.track.kind === mediaType
|
378
|
378
|
&& t.direction === MediaDirection.RECVONLY
|
379
|
|
- && t.currentDirection === MediaDirection.INACTIVE);
|
|
379
|
+
|
|
380
|
+ // Re-use any existing recvonly transceiver (if available) for p2p case.
|
|
381
|
+ && ((this.pc.isP2P && t.currentDirection === MediaDirection.RECVONLY)
|
|
382
|
+ || t.currentDirection === MediaDirection.INACTIVE));
|
380
|
383
|
|
381
|
384
|
// For mute/unmute operations, find the transceiver based on the track index in the source name if present,
|
382
|
385
|
// otherwise it is assumed to be the first local track that was added to the peerconnection.
|
|
@@ -387,17 +390,20 @@ export class TPCUtils {
|
387
|
390
|
if (sourceName) {
|
388
|
391
|
const trackIndex = Number(sourceName.split('-')[1].substring(1));
|
389
|
392
|
|
390
|
|
- if (trackIndex) {
|
391
|
|
- transceiver = this.pc.isP2P
|
392
|
|
- ? this.pc.peerconnection.getTransceivers()
|
393
|
|
- .filter(t => t.receiver.track.kind === mediaType)[trackIndex]
|
394
|
|
- : this.pc.peerconnection.getTransceivers()
|
|
393
|
+ if (this.pc.isP2P) {
|
|
394
|
+ transceiver = this.pc.peerconnection.getTransceivers()
|
|
395
|
+ .filter(t => t.receiver.track.kind === mediaType)[trackIndex];
|
|
396
|
+ } else if (oldTrack) {
|
|
397
|
+ const transceiverMid = this.pc._localTrackTransceiverMids.get(oldTrack.rtcId);
|
|
398
|
+
|
|
399
|
+ transceiver = this.pc.peerconnection.getTransceivers().find(t => t.mid === transceiverMid);
|
|
400
|
+ } else if (trackIndex) {
|
|
401
|
+ transceiver = this.pc.peerconnection.getTransceivers()
|
395
|
402
|
.filter(t => t.receiver.track.kind === mediaType
|
396
|
403
|
&& t.direction !== MediaDirection.RECVONLY)[trackIndex];
|
397
|
404
|
}
|
398
|
405
|
}
|
399
|
406
|
}
|
400
|
|
-
|
401
|
407
|
if (!transceiver) {
|
402
|
408
|
return Promise.reject(new Error('replace track failed'));
|
403
|
409
|
}
|