Description
I'd like to propose adding a third parameter, event.transceiver.mid
, to the track
event:
diff --git a/index.js b/index.js
index 5d0d08b..c274499 100644
--- a/index.js
+++ b/index.js
@@ -958,7 +958,7 @@ class Peer extends stream.Duplex {
event.streams.forEach(eventStream => {
this._debug('on track')
- this.emit('track', event.track, eventStream)
+ this.emit('track', event.track, eventStream, event.transceiver.mid)
this._remoteTracks.push({
track: event.track,
Background
The Unified Plan Transition Guide says the following:
Local and Remote Track IDs Do Not Match
In Plan B, a sender is created for each local track that is added and a receiver is created for each remote track that is negotiated, the track IDs of local and remote endpoints match.
In Unified Plan, senders and receivers are created in pairs of transceivers, and a transceiver.receiver.track may have been created long before remote SDP offers a track. As such, the track that is fired in RTCPeerConnection.ontrack is no longer guaranteed to have an ID matching the sender-side version of the track. Furthermore, because of addTransceiver() and replaceTrack(), a track may be sent multiple times. Track IDs are misleading, and shouldn’t be assumed to match. Instead, transceiver.mid should be used to correlate local and remote tracks. You may have to “setLocalDescription(answer)” before the mid is known.
I'm building an SFU, and since a change of track.id
or MediaStream.id
might not be visible in the browser, I see no other option than to use the mid
and send the track information for a particular mid
through a different channel.
To be able to do that, I need to know which transceiver a track belongs to, and I was unable to find a public API from simple-peer
that would allow me to do that. Thanks!