Search code examples
javascriptnode.jsstunkurentoturn

Kurento datachannel creation and management


I'm developing a WebRTC application based in node.js and Kurento and I want to implement a chat using datachannels.

I've seen the browser javascript version and I want to integrate it in the one to one node.js example.

What I have done

1.- I've created both WebRTCEndpoints with datachannel capabilities like this: pipeline.create('WebRtcEndpoint', {useDataChannels: true}, function(error, calleeWebRtcEndpoint) {...}
2.- Then I've created a <textarea> with a <button> to send messages, and a <div> to view them.

So my question is, what servers I have to put when I create the datachannel in the client? This snippet is from the browser javascript datachannel tutorial but at the start of the file we can clearly see ICE servers are ignoring in the connection creation. Also, I don’t know how you manage them in the node.js tutorials, so I'm a bit lost here.

peerConnection = new RTCPeerConnection(servers, configuration);

channel = peerConnection.createDataChannel(getChannelName(), dataConstraints);

channel.onopen = onSendChannelStateChange;
channel.onclose = onSendChannelStateChange;
channel.onmessage = onMessage;`

Thanks for the help.


Solution

  • I've discovered what was I doing wrong and now the I can send messages by datachannels.

    Basically what I've done is to add peerConnection option to the options object. Next that option object is passed to WebRtcPeerSendrecv connection method and it's done!

    var options = {
        peerConnection: peerConnection, //Must be passed as a field in options to make DataChannels work
        localVideo : videoInput,
        remoteVideo : videoOutput,
        onicecandidate : onIceCandidate
    }
    
    webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(){...});