4

I want to send streaming data (as sequences of ArrayBuffer) from a Chrome extension to a Chrome App, since Chrome message API (includes chrome.runtime.sendMessage, postMessage...) does not support ArrayBuffer and JS arrays have poor performance, I have to try other methods. Eventually, I found WebRTC over RTCDataChannel might a good solution in my case.

I have succeeded to send string over a RTCDataChannel, but when I tried to send ArrayBuffer I got:

code: 19
message: "Failed to execute 'send' on 'RTCDataChannel': Could not send data"
name: "NetworkError"

It seems that it's not a bandwidths limits problem since it failed even though I sent one byte of data. Here is my code:

pc = new RTCPeerConnection(configuration, { optional: [ { RtpDataChannels: true } ]});
//...
var dataChannel = m.pc.createDataChannel("mydata", {reliable: true});
//...
var ab = new ArrayBuffer(8);
dataChannel.send(ab);

Tested on OSX 10.10.1, Chrome M40 (Stnble), M42(Canary); and on Chromebook M40.

I have filed a bug for WebRTC here.

Community
  • 1
  • 1
Imskull
  • 1,316
  • 14
  • 16

1 Answers1

5

I modified my code, now everything worked amazing:

  1. removed RtpDataChannels option when creating RTCPeerConnection.(YES, remove RtpDataChannels option if you want data channel, what a magic world!)
  2. on receiver side: no need createDataChannel, instead, handle onmessage, onxxx by using event.channle from pc.ondatachannel callback:

    pc.ondatachannel function(event)
        var receiveChannel = event.channel;
        receiveChannel.onmessage = function(event){
            console.log("Got Data Channel Message:", event.data);
        }; 
    };
    
Imskull
  • 1,316
  • 14
  • 16
  • Thanks @lmskull for answering your question, you solved my problem as well. For anyone that has the same problem: you should not create the same channels on the sender and receiver side, but just use ondatachannel to get the channels created on the other side (works with multiple channels, too). An example here: https://github.com/webrtc/samples/blob/master/src/content/datachannel/basic/js/main.js – janesconference Apr 12 '15 at 17:32