awslabs / amazon-kinesis-video-streams-webrtc-sdk-js

JS SDK for interfacing with the Amazon Kinesis Video Streams Signaling Service.
https://awslabs.github.io/amazon-kinesis-video-streams-webrtc-sdk-js/examples/index.html
Apache License 2.0
286 stars 141 forks source link

Two datachannels #201

Closed srinivasbakki closed 1 year ago

srinivasbakki commented 1 year ago

I need to send two kinds of data and hence need two data channels. How can i create two channels. I did peerConnection.createDatachannel with two different names. However There's only peerConnection.ondatachannel event handler. How do i register events with two different data channels ?

niyatim23 commented 1 year ago

Hi @srinivasbakki, one way to do that would be to negotiate out-of-bands. You wouldn't have to use the ondatachannel event at all. You can just wait for the state to reach open. You'll have to use the negotiated parameter. This would require your viewer to know the channel names beforehand. For example:

dataChannelA = peerConnection.createDataChannel(“channelA”, {negotiated: true, id: 1};
dataChannelB = peerConnection.createDataChannel(“channelB”, {negotiated: true, id: 2};

Closing assuming answered. Feel free to reach out to us with further questions