Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Due to limitations in the plugin interface, we had to delegate part of the data sending implementation to javascript.
This documents explains how this was done, and what the repercussion of this solutions are.

Sending a string

If you use the plugin so send a string with this callActive/NPAPI interfaces, the plugin's DataChannel has limited support to different data types.

Sending a string

The plugin behaves exactly the same way as Chrome and Firefox when sending a string :

Code Block
languagejs
 var data = "My string data";
 mySendingChannel.send(data);

Then the plugin is directly sending the string "data" to the other side of the data channel.

Sending a non string data

...

Sending ArrayBufferViews

The following ArrayBuffer types can be sent using the plugin:

  • Int8Array

  • Uint8Array

  • Int16Array

  • Uint16Array

  • Int32Array

  • Uint32Array

Code Block
languagejs
 var data = new Int8Array(10);
 mySendingChannel.send(data);

then the plugin will call the following javascript function to parse the ArrayBuffer into a string that can be sent to through the plugin interface

...

languagejs

...

 

 

When the remote data channel receives the string, it will change it back into a UInt8Array using the following function:

Code Block
languagejs
_Tem_str2ab = function(str) { 
    var buf = new ArrayBuffer(str.length); 
    var bufView = new Uint8Array(buf); 
    for (var i=0, strLen=str.length; i<strLen; i++) { 
    bufView[i] = str[i]; 
}; 

When you receive the data on the other side of the data channel, you can then use:

Code Block
languagejs
function onReceiveMessageCallback(event) { // was set as the receiving datachannel onmessage callback
	var data = new Int8Array(event.data);
	...
}

 

Temasys considered it the best available solution and does not plan on releasing a different implementation in the close future.

Sending other types of data

Sending other types of data will lead to unexpected behaviour. You data might be sent successfully, some of it might be lost or corrupted, or the plugin could even crash.

Implications

  1. The implementation of string sending is that same as it was before.
  2. You should not override the functions _Tem_ab2str nor _Tem_str2ab.
  3. Overriding these functions might lead to unexpected behaviours

Sending ArrayBuffers

We suggest sending ArrayBuffers by transforming them in typed arrays first:

Code Block
languagejs
var AB   = new ArrayBuffer(8);
var data = new Int8Array(10);
mySendingChannel.send(data);

Sending Blobs

Temasys is actively considering options for blob sending. 
Follow our Google Group or our support portal to be update as soon as a solution is released.

Examples of how to use the data channel

We adapted the dataChannel sample provided by Google to work with the plugin, and implemented a second test for sending non-string elements. 

Please refer to these examples if you try to implement a data channel in your own solution.

DataChannel and strings: Temasys provides a few samples apps to help users integrate the plugin into their application.

https://githubplugin.com/Temasys/Google-WebRTC-Samples/tree/master/samples/web/content/datachannel
DataChannel and ArrayBuffers: https://github.com/Temasys/Google-WebRTC-Samples/tree/dev/samples/web/content/datachannel-arraybuffertemasys.com.sg/demo/