Reputation: 4946
Is the ID of a RTCDataChannels global or specific to a RTCPeerConnection?
Eg, if I have a p1 and p2, two peer connections, can I create a data channel on each that has id 7, or will they collide?
I have tried this on Chrome with the webrtc shim, an it appears that ids are specific to a RTCPeerConnection. I can't, however, find where in the spec this is specified...
Does anyone know?
Upvotes: 1
Views: 370
Reputation: 42450
The id comes from the transport layer of the connection. It's a number between 0 and 65534, and is unique only to that connection (the pair of RTCPeerConnections communicating).
See "Stream Identifier" in section 3 of https://www.ietf.org/id/draft-ietf-rtcweb-data-protocol-09.txt
There's a workaround however. You're allowed to specify your own id with createDataChannel
:
let channel = createDataChannel("foo", { id: 3 });
So you could use localStorage to keep them unique for your app (up to a point of course) if that's what you want.
In other words, you don't have to worry about collisions between RTCPeerConnections, unless they're the two ends of the same connection.
Upvotes: 1