Simple-peer: Data channel crashing on sending Uint8Array

Created on 16 Oct 2019  路  3Comments  路  Source: feross/simple-peer

Hi,
The library works very well for sharing voice/video over rtc connection.
I have a problem sharing Uint8Array when i do conn.send(data) the conn.on('close') get triggered automatically

what i tried is
let c = document.getElementById("mySketcher");
let ctx = c.getContext("2d");
let imgData = ctx.getImageData(0, 0, c.width, c.height);
data = Buffer.from(imgData.data);
conn.send(data);
---- connection breaks here-------
Screenshot 2019-10-16 at 6 49 25 PM
The above shows what data i am trying to send.
i am using chrome Version 77.0.3865.120 (Official Build) (64-bit)
Does the browser allow this big buffer size to transfer? this is something around 1549412 bytes as per me.

question

All 3 comments

Chunk your data. That message is too large to send in a single frame.

Module to chunk streams: https://www.npmjs.com/package/chunk-stream

Blog about maximum chunk size for RTCDataChannels (recommends 16kb chunks): http://viblast.com/blog/2015/2/5/webrtc-data-channel-message-size/

var chunks = require('chunk-stream')
inputStream.pipe(chunks(16000)).pipe(peer)

or, with write:

var chunks = require('chunk-stream')
var chunkStream = chunks(16000)
chunkStream.pipe(peer)

chunkStream.write(myData)

Thanks alot i will check this out. Looks like this is some webrtc guideline to follow. Closing this, not going to increase issue count of this awesome plugin.

Also someone else trying to send over canvas, found a better way to send it as dataurl instead which is far light though this might also require chunking at some moment.

For sender :=
let c = document.getElementById("mySketcher");
let ctx = c.getContext("2d");
let data = c.toDataURL();
data = Buffer.from(data);
conn.send(data);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saagarbethi picture saagarbethi  路  4Comments

feross picture feross  路  4Comments

contra picture contra  路  6Comments

dnish picture dnish  路  5Comments

olgeorge picture olgeorge  路  5Comments