android - Sending JSON data over WebRTC -



android - Sending JSON data over WebRTC -

i new webrtc native framework.

i able webrtc source , run demo android application based on http://andrii.sergiienko.me/?go=all/building-webrtc-demo-for-android/enter link description here.

i able send/receive sound , video between 2 android devices on same local network.

is there way send little json payload in peer connection?

i tried looking in source , found back upwards send video , audio.

thank you.

your looking webrtc datachannels.

webrtc's rtcdatachannel api used transfer info straight 1 peer another. great sending info between 2 browsers(peers) activities communication, gaming, or file transfer , slew of other functionalities.

it alternative websockets:

this great alternative websockets because no central server involved , transmission faster , there no bottleneck. can of course of study mitigate failover of p2p transfer having hooks activates websockets based communication if p2p data-channel communication fails.

code reference:

the events defined called when wish send message of when message received (including error handling). code should running in both browsers. instead of sending "hello world" need send json string.

var peerconnection = new rtcpeerconnection(); // found peer connection using signaling channel here var datachannel = peerconnection.createdatachannel("mylabel", datachanneloptions); datachannel.onerror = function (error) { console.log("data channel error:", error); }; datachannel.onmessage = function (event) { console.log("got info channel message:", event.data); }; datachannel.onopen = function () { datachannel.send("hello world!"); }; datachannel.onclose = function () { console.log("the info channel closed"); };

the datachannel object created established peer connection. can created before or after signaling happens. pass in label distinguish channel others , set of optional configuration settings:

var datachanneloptions = { ordered: false, // not guarantee order maxretransmittime: 3000, // in milliseconds };

for more details check out links provided.

examples:

link official documentation: datachannels in webrtc

link file trasfer illustration using webrtc info channels. file transfer

link popular utilize cases webrtc info channels use cases

android jni webrtc

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -