3

I recently tried implementing p2p file transfer using Webrtc by splitting large files into array buffers and then sending them over the data channel. The code was working a month ago, but now it is suddenly throwing me this error.

Uncaught RTCError: Failure to send data 
Uncaught Error: The error you provided does not contain a stack trace.

Here's the code snippet to send the file.

    function sendFile() {
    const peer = peerRef.current;
    const stream = file.stream();
    const reader = stream.getReader();

    reader.read().then(obj => {
        handlereading(obj.done, obj.value);
    });

    function handlereading(done, value) {
        if (done) {
            console.log("done");
            peer.write(JSON.stringify({ done: true, fileName: file.name }));
            return;
        }

        peer.write(value);
        reader.read().then(obj => {
            handlereading(obj.done, obj.value);
            console.log("yolo");
        })
    }

}

The code works fine on other browsers like firefox or the mobile Samsung browser.

You can also check my main repo here and live app here (to reproduce the error)

Dev
  • 103
  • 1
  • 7

0 Answers0