RTCPeerConnection example

242 views
Skip to first unread message

Ray C

unread,
Jul 2, 2014, 4:01:55 AM7/2/14
to eas...@googlegroups.com
I'm new to easyrtc.  I've installed the server and successfully connected from my phone to my pc while my phone's wifi was disabled.  I'd like to set up a low latency data connection between two clients.  Is using RTCPeerConnection the best way to do this?  Is there easyrtc sample code that show how to do this?

Ray C

unread,
Jul 2, 2014, 5:19:39 AM7/2/14
to eas...@googlegroups.com
function my_init()
{
    easyrtc.setRoomOccupantListener(roomListener);//populate buttons with ids of room visitors
    easyrtc.setPeerListener(addToConversation);
    easyrtc.enableDataChannels(true);
    console.log("supportsDataChannels() ="+easyrtc.supportsDataChannels() ) ;
    easyrtc.setDataChannelOpenListener( function(easyrtcid)
    {
        console.log("Sending data!!!!!!!");
        easyrtc.sendDataP2P(easyrtcid, "greeting", "hello p2p");
    });
    easyrtc.setDataChannelCloseListener( function(easyrtcid){
        console.log("Closing data channel");
        ("No longer connected to " + easyrtc.idToName(easyrtcid));
    });
    easyrtc.connect("Company_Chat_Line", connectSuccess, connectFailure);
}

The round trip latency measured a few times is about 200ms (from lan to mobile and back) so I'm guessing the one way latency is in the order of 100 ms.
Is there a better way to achieve low latency data transfer ?  Reliable data transfer is not critical.

Eric Davies

unread,
Jul 2, 2014, 11:47:35 AM7/2/14
to eas...@googlegroups.com
Hi Ray,

Two thoughts: 
  1) If you aren't using audio and video, disable them. Webrtc limits the datachannel bandwidth so as not to interfere with audio/video, so disabling such may result in an improvement. If it does/doesn't, please let us know.
  2) Check to see if you are going through a turn server.
  3) Try the following before you establish a call. According to the webrtc docs, it should give you UDP semantics
easyrtc.getDatachannelConstraints = function() {
return {
 ordered: false, // do not guarantee order 
 maxRetransmits: 0 // in milliseconds
};
}
  4) Worst case scenario, you could try the websocket for communication instead of datachannel, ie, use easyrtc.sendPeerMessage.
Message has been deleted

Ray C

unread,
Jul 2, 2014, 1:22:37 PM7/2/14
to eas...@googlegroups.com
Thanks Eric,
Regarding 2: how do I check if the data is passing thru a turn server?  I am using the same configuration as the tutorial, I haven't changed any stun or turn server settings.

EDIT: Regarding _4_: Before I started this thread I was using easyrtc.sendDataWS (as was done in the chat tutorial), the latency seemed a little worse, about 150-200 ms.  According to the easyrtc docs:

sendDataWS(destination, msgType, msgData, ackhandler)

Sends data to another user using websockets. The easyrtc.sendServerMessage or easyrtc.sendPeerMessage methods are wrappers for this method; application code should use them instead.

So sendDataWS and sendPeerMessage should have the same performance, correct?

Eric Davies

unread,
Jul 2, 2014, 3:08:02 PM7/2/14
to eas...@googlegroups.com
Yes, sendDataWS and sendPeerMessage are equivalent, one is essentially a wrapper for the other.

Assuming you are using Chrome:
  • The easiest way to check if you are using a turn server is using our tawk.com application on both sides. There is a little signal level icon on the bottom of the other guy's video, if you hover over it, it will tell you if a turn server is needed between two points.
  • You can also check the chrome://webrtc-internals to see the ip address of the active connection.
  • You could also remove any turn server entry from your ice configuration and see if it still formed a connection. If it doesn't, you were using a turn server before.
  • Lastly, there is a statistics function you can use inside your client, but for a one shot test, it would be over-kill. 

Reply all
Reply to author
Forward
0 new messages