Search code examples
androidwebrtcrtcdatachannel

Using PeerConnection.createDataChannel() in Android


I have built webrtc for android and have included the jar file in my project. I want to attach data channel to my PeerConnection object. On web, we do following in javascript :

sendChannel = pc.createDataChannel("sendDataChannel", {reliable: true});

or

sendChannel = pc.createDataChannel("sendDataChannel", {reliable: false});

where pc is the PeerConnection.

I want to do same in Java on Android using native webrtc code. I have little confusion. By looking at Jar file on eclipse, I could see that createDataChannel method of PeerConnection takes two arguments of type String and Init.

PeerConnection.createDataChannel(String, Init)

I could not understand what should I put in the second argument. WebRTC documentation, I found, is for web applications. I have seen the following WebRTC draft document but could not understand clearly.

http://www.w3.org/TR/webrtc/#methods-2

It would be helpful if someone can provide a small example of how it should be used.

Currently, I am trying to do this:

DataChannel dc = this.pc.createDataChannel("sendDataChannel", new DataChannel.Init());

Solution

  • You'd create the Init instance and manipulate the public properties before passing it to createDataChannel: https://code.google.com/p/webrtc/source/browse/trunk/talk/app/webrtc/java/src/org/webrtc/DataChannel.java#35

    If you did not find "reliable" there, that is because this does not work anymore. See maxRetransmits and maxRetransmitTimeMs.