Closed pimterry closed 2 years ago
Found a further strange edge case here in fact.
This first example below, which uses a non-conflicting 1234 mid, does correctly create SDP with both video & application media, which is good:
NDC = require('node-datachannel');
p = new NDC.PeerConnection('test', { iceServers: [] });
p.addTrack(new NDC.Video("1234", "SencRecv"));
p.createDataChannel('test');
console.log(p.localDescription().sdp); // Includes m=application and m=video
If you swap the track/channel setup lines though so that the channel is created first, as below, then it doesn't include the video at all:
NDC = require('node-datachannel');
p = new NDC.PeerConnection('test', { iceServers: [] });
p.createDataChannel('test');
p.addTrack(new NDC.Video("1234", "SencRecv"));
console.log(p.localDescription().sdp); // Only includes m=application
Is there a good reason for that? Seems very odd to me.
When present, it seems like the application stream always uses mid '0', even if that mid is already in use. If there's a conflict, the other stream is not included in the offer SDP.
Indeed, the library prevents conflicts with existing remote tracks, but not local ones, which is an oversight. It should be fixed by https://github.com/paullouisageneau/libdatachannel/pull/586
(Sorry I'm filing so many issues! NodeDataChannel/libdatachannel is working really well for me and I'm just getting into the meat of it at the moment, I'll having so many complicated issues soon smile. I hope this one is actually a real bug!)
On the contrary, it is great that you test corner cases like this one and take the time to write such detailed bug reports, thank you!
If you swap the track/channel setup lines though so that the channel is created first, as below, then it doesn't include the video at all:
NDC = require('node-datachannel'); p = new NDC.PeerConnection('test', { iceServers: [] }); p.createDataChannel('test'); p.addTrack(new NDC.Video("1234", "SencRecv")); console.log(p.localDescription().sdp); // Only includes m=application
Is there a good reason for that? Seems very odd to me.
This is actually an expected behavior. By default, createDataChannel()
calls setLocalDescription()
internally while addTrack()
does not, as it would prevent adding multiple tracks. Therefore, you need to call createDataChannel()
(possibly multiple times) after addTrack()
(possibly multiple time).
To disable this behavior, there is a flag called disableAutoNegotiation
in the PeerConnection
configuration. When it is enabled, the user is responsible for calling setLocalDescription()
after createDataChannel()
, addTrack()
, and setRemoteDescription()
. However, I'm seeing now that this flag appears to be missing in the node-datachannel wrapper.
It should be fixed by https://github.com/paullouisageneau/libdatachannel/pull/586
Perfect, thanks!
To disable this behavior, there is a flag called disableAutoNegotiation in the PeerConnection configuration. When it is enabled, the user is responsible for calling setLocalDescription() after createDataChannel(), addTrack(), and setRemoteDescription(). However, I'm seeing now that this flag appears to be missing in the node-datachannel wrapper.
That all makes sense, and I see you've already opened https://github.com/murat-dogan/node-datachannel/pull/96 to fix it, thank you! Manually managing negotiation is definitely going to work better for my use case, that's great.
You're welcome, I'm closing this as it looks solved.
When present, it seems like the application stream always uses mid '0', even if that mid is already in use. If there's a conflict, the other stream is not included in the offer SDP.
I'm reproducing this with node-datachannel v0.2.4, but I'm fairly sure it's coming from here internally. Repro:
This prints the following SDP:
Running it again, but using
p.addTrack(new NDC.Video("1234", "SencRecv"))
instead (i.e. using "1234" as the mid for the video stream instead of "0") returns the below:Note the 5 extra lines at the end for the video stream that are lost in the previous example.
This affects my use case because I'm proxying WebRTC streams between other clients, I'd like to preserve the mids selected by those clients, and Chrome at least happily uses mid 0 for its video streams. Seems like this would affect anybody who explicitly uses "0" as their media mid in an offer though.
It would be good if the application stream used an unused mid, instead of always using 0. More generaly, it'd would be nice to have a way to set an explicit mid for the application stream, both because that would provide a workaround for this and more generally.
(Sorry I'm filing so many issues! NodeDataChannel/libdatachannel is working really well for me and I'm just getting into the meat of it at the moment, I'll having so many complicated issues soon :smile:. I hope this one is actually a real bug!)