peers / peerjs

Simple peer-to-peer with WebRTC.
https://peerjs.com
MIT License
12.27k stars 1.42k forks source link

Error when sending RN #642

Open henworx-angelone opened 4 years ago

henworx-angelone commented 4 years ago

So far Peer.js works in react-native. I have only the problem as soon as I want to send a message that the connection is broken and gives me the following error:

DC #: dc_6igjvuv7fhg Error when sending: (TypeError) Data must be either string, ArrayBuffer, or ArrayBufferView.

Tested with RN 6.0.0 - 6.2.0.

In addition, although I can establish a connection, I do not get feedback from the connection.

    localPeer.on('connection', conn => {
      conn.on('open', () => {
        console.log(conn.dataChannel);
        conn.on('data', data => {
          console.log(data);
            conn.send("String");
        });
        console.log(conn.dataChannel);
      });
    });

     var conn = localPeer.connect ('he8b');
     console.log (conn);
     conn.on ('open', () => {
       console.log ("works"); // THIS NOT WORKS NOW!
     });

I don't have these problems in the browser.

My installed packages:

     "js-binarypack": "0.0.9",
     "ns-binarypack": "0.0.5",
     "peerjs": "^ 1.2.0",
     "peerjs-js-binarypack": "^ 1.0.1",
     "react": "16.11.0",
     "react-native": "0.62.0",
     "react-native-incall-manager": "^ 3.2.7",
     "react-native-peerjs": "^ 1.0.4",
     "react-native-webrtc": "^ 1.75.3"

when i send a message from the browser it also arrives, but only when i start the connection from the browser

akshaya-rao-s commented 4 years ago

Did you solve this? I am still having this issue.

wfmarques commented 3 years ago

So is not a fix but for my case forcing the connection serialization type to "json" works.

let conn = this.peer.connect(destPeerId) conn.serialization = "json"