Add transceiver.mid to onTrack() event payload
- Dominant language
- JavaScript
- Stars
- 7.8k
- Forks
- 983
- PR merge metrics
- No merged PRs in 30d
Description
I'd like to propose adding a third parameter, `event.transceiver.mid`, to the [`track`][track] event:
```diff
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][up] 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!
[track]: https://github.com/feross/simple-peer/blob/dd9e6d390ab38a3dff8912f30e020f2cd22c54d1/index.js#L961
[up]: https://docs.google.com/document/d/1-ZfikoUtoJa9k-GZG1daN0BU3IjIanQ_JSscHxQesvU/
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.