Skip to content

Commit

Permalink
transceiver: use receiver ID to match transceiver in ontrack
Browse files Browse the repository at this point in the history
Also remove the non-standard RTCRtpTransceiver.id property.
  • Loading branch information
saghul committed Nov 22, 2022
1 parent 0247841 commit 107e195
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/RTCPeerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,16 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
let track;
let transceiver;

// Make sure transceivers are stored in timestamp order. Also, we have to make
// sure we do not add a transceiver if it exists.
const [ { transceiver: oldTransceiver } = { transceiver: null } ]
= this._transceivers.filter(({ transceiver }) => transceiver.id === ev.transceiver.id);
= this._transceivers.filter(({ transceiver }) => transceiver.receiver.id === ev.receiver.id);

// We need to fire this event for an existing track sometimes, like
// when the transceiver direction (on the sending side) switches from
// sendrecv to recvonly and then back.

if (oldTransceiver) {
transceiver = oldTransceiver;
track = transceiver._receiver._track;
track = transceiver.receiver.track;
transceiver._mid = ev.transceiver.mid;
transceiver._currentDirection = ev.transceiver.currentDirection;
transceiver._direction = ev.transceiver.direction;
Expand Down Expand Up @@ -702,7 +700,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
for (const update of transceiverUpdates) {
const [ transceiver ] = this
.getTransceivers()
.filter(t => t.id === update.transceiverId);
.filter(t => t.sender.id === update.transceiverId);

if (!transceiver) {
continue;
Expand Down
11 changes: 2 additions & 9 deletions src/RTCRtpTransceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ export default class RTCRtpTransceiver {
_sender: RTCRtpSender;
_receiver: RTCRtpReceiver;

_id: string;
_mid: string | null = null;
_direction: string;
_currentDirection: string;
_stopped: boolean;

constructor(args: {
peerConnectionId: number,
id: string,
isStopped: boolean,
direction: string,
currentDirection: string,
Expand All @@ -28,7 +26,6 @@ export default class RTCRtpTransceiver {
receiver: RTCRtpReceiver,
}) {
this._peerConnectionId = args.peerConnectionId;
this._id = args.id;
this._mid = args.mid ? args.mid : null;
this._direction = args.direction;
this._currentDirection = args.currentDirection;
Expand All @@ -37,10 +34,6 @@ export default class RTCRtpTransceiver {
this._receiver = args.receiver;
}

get id() {
return this._id;
}

get mid() {
return this._mid;
}
Expand Down Expand Up @@ -68,7 +61,7 @@ export default class RTCRtpTransceiver {

const oldDirection = this._direction;

WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.id, val)
WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.sender.id, val)
.catch(() => {
this._direction = oldDirection;
});
Expand All @@ -93,7 +86,7 @@ export default class RTCRtpTransceiver {
return;
}

WebRTCModule.transceiverStop(this._peerConnectionId, this.id)
WebRTCModule.transceiverStop(this._peerConnectionId, this.sender.id)
.then(() => this._setStopped());
}

Expand Down

0 comments on commit 107e195

Please sign in to comment.