From 107e19596b082805e61767ecce7bfc5a77fd03f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 21 Nov 2022 10:57:24 +0100 Subject: [PATCH] transceiver: use receiver ID to match transceiver in ontrack Also remove the non-standard RTCRtpTransceiver.id property. --- src/RTCPeerConnection.ts | 8 +++----- src/RTCRtpTransceiver.ts | 11 ++--------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/RTCPeerConnection.ts b/src/RTCPeerConnection.ts index b5eff2e1a..e1a4c6216 100644 --- a/src/RTCPeerConnection.ts +++ b/src/RTCPeerConnection.ts @@ -510,10 +510,8 @@ 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 @@ -521,7 +519,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C 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; @@ -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; diff --git a/src/RTCRtpTransceiver.ts b/src/RTCRtpTransceiver.ts index 1c4e75637..0617ef26f 100644 --- a/src/RTCRtpTransceiver.ts +++ b/src/RTCRtpTransceiver.ts @@ -11,7 +11,6 @@ export default class RTCRtpTransceiver { _sender: RTCRtpSender; _receiver: RTCRtpReceiver; - _id: string; _mid: string | null = null; _direction: string; _currentDirection: string; @@ -19,7 +18,6 @@ export default class RTCRtpTransceiver { constructor(args: { peerConnectionId: number, - id: string, isStopped: boolean, direction: string, currentDirection: string, @@ -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; @@ -37,10 +34,6 @@ export default class RTCRtpTransceiver { this._receiver = args.receiver; } - get id() { - return this._id; - } - get mid() { return this._mid; } @@ -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; }); @@ -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()); }