peerjs
peerjs copied to clipboard
Error when sending RN
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
Did you solve this? I am still having this issue.
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"
Did you ever manage to solve this? I'm running into the same error, but if I set serialization to "json" brings up: SyntaxError: JSON Parse error: Unexpected character: o
If I do serialization: none, then I'm able to receive a message from web and run it through Buffer.from(data).toString(), sending doesn't crash, but the client(the web app) receives 0.