====== Data channel ====== You can add a data channel to an established call (add an extra data channel to the call's voice and video channels). You can transmit any kind of data through the data channel to the recipient at the other end of the call. Usually you add data channel to an already established call (to be compatible to clients not supporting data channels). Once a data channel is added to the call it will stay open ready to transmit data multiple times until call is ended. ===== Limitations ===== All browsers do not support data channels. Therefore you need to make sure both browsers (yours and the one at the other end of the call) support data channels. You must check if both browsers support data channels using **call.is("dataChannelSupport")** - it only returns true if both ends of call supports data channels. As of now (2018) implementations of data channels differ so much between different browsers that you should avoid sending binary data. Convert any binary data to eg base64 before sending it. You should also avoid sending more than 16KB at a time. As of now (2018) Firefox does not support sending new SDP during ongoing call (renegotiating), thus data channel cannot be added to a call and can therefore not be used. ===== Functions ===== | [[ixnx:wrtc:js:api:call:is|call.is("dataChannelSupport")]] | returns true if both browsers (yours and the other end of the call) supports data channels | | [[ixnx:wrtc:js:api:call:is|call.is("dataChannelUp")]] | returns true if a data channel has been established | | [[ixnx:wrtc:js:api:call:is|call.is("localDataChannelSupport")]] | returns true if your browser supports data channels | | [[ixnx:wrtc:js:api:call:is|call.is("remoteDataChannelSupport")]] | returns true if browser at other end of the call supports data channels | | [[ixnx:wrtc:js:api:call:adv.adddatachannel|call.adv.addDataChannel(constraints)]] | add a data channel to a call | | [[ixnx:wrtc:js:api:call:adv.senddata|call.adv.sendData(data)]] | create a data channel if needed and send data through it | | [[ixnx:wrtc:js:api:wrtc:is|wrtc.is("localDataChannelSupport")]] | returns true if your browser supports data channels | | [[ixnx:wrtc:js:api:wrtc:ondatareceived|wrtc.onDataReceived(callobj, data)]] | data has been received on data channel | ===== Errors ===== [[ixnx:wrtc:js:api:wrtc:onerror|Error 311]] can occur if call.adv.addDataChannel() or call.adv.sendData() has been called but your or called partner's browser do not support data channels. ===== Usage ===== Most of the time only **[[ixnx:wrtc:js:api:call:is|call.is("dataChannelSupport")]]** and **[[ixnx:wrtc:js:api:call:adv.senddata|call.adv.sendData(data)]]** need to be used: if call.is("dataChannelSupport") call.adv.sendData("HELLO"); Always check if browsers support data channel before attempting to use it. First time **call.adv.sendData()** is called it will create the necessary data channel (by calling call.adv.addDataChannel()) and send the data through it. The data channel will then stay open, further calls to **call.adv.sendData()** will use the existing data channel. The data channel becomes closed when the call is ended. Any data received on the data channel will trigger the **[[ixnx:wrtc:js:api:wrtc:ondatareceived|wrtc.onDataReceived()]]** event function. The above example code will trigger onDataReceived() at the receiving end: wrtc.onDataReceived(callobj, msg); // msg will contain the string "HELLO" Any answer back can be sent using callobj.adv.sendData() ===== Starting a call with data channel ===== Usually you add data channel to an already established call (to be compatible to clients not supporting data channels). But if you want to create a call that already contains a data channel from the very beginning you can do so using the addDataChannel config parameter to [[ixnx:wrtc:js:api:wrtc:call|wrtc.call()]]. You are though advised not to do so, as before making a call you do not know if client at other end supports data channels or not. The call can then fail. ===== File transfer ===== You can make wrtc_kit file transfer use data channel by supplying the call object in the wrtc.sendFile() call. wrtc.sendFile() will also check if there are any available calls already open to the recipient it can use for data transfer, and if so it will open a data channel on that call and send the file through it. Read more at [[ixnx:wrtc:js:api:wrtc:sendfile|wrtc.sendFile()]]