Reputation: 1315
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.
Upvotes: 4
Views: 3090
Reputation: 1315
I modified my code, now everything worked amazing:
RtpDataChannels
option when creating RTCPeerConnection
.(YES, remove RtpDataChannels
option if you want data channel, what a magic world!)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);
};
};
Upvotes: 5