Exception thrown when trying to peer.send() large amounts of data very quickly.
I think this is to do with the datachannel limiting. Unfortunately the channel closes right after, so we can't just retry later.
Should we buffer data when we can't send it? Or is there a better way to do this outside of simple-peer?
I saw you hit this issue on instant.io @feross. What was your solution?
Is there some kind of property on the datachannel that we can expose to know if it's ready to send?
Issue doesn't occur when piping.
peer.send() just calls the underlying datachannel.send() method. It is very low-level and doesn't check to see that sending will work.
If you use peer.write() or pipe to the stream instead, you shouldn't have any issues. Note that we get peer.write() because we inherit from the stream.Duplex class.
You can see how we handle backpressure here: https://github.com/feross/simple-peer/blob/00d6b40f3758ffe26551bfae6fa18a9b17edf01f/index.js#L361 but that property is not exposed.
FWIW, Firefox is about to ship an improvement that allows you to call peer.send() with data up to 1GB (!!) More info here: https://bugzilla.mozilla.org/show_bug.cgi?id=979417
Most helpful comment
peer.send()just calls the underlyingdatachannel.send()method. It is very low-level and doesn't check to see that sending will work.If you use
peer.write()or pipe to the stream instead, you shouldn't have any issues. Note that we getpeer.write()because we inherit from thestream.Duplexclass.You can see how we handle backpressure here: https://github.com/feross/simple-peer/blob/00d6b40f3758ffe26551bfae6fa18a9b17edf01f/index.js#L361 but that property is not exposed.