peerjs
peerjs copied to clipboard
PeerJS: Invalid server message connected
Here is the PeerJS part of my code :
let peer = new Peer(Math.floor(Math.random() * 2 ** 16).toString(), {
host: '127.0.0.1', secure: false, port: 8080, debug: 3
});
console.log(peer.id);
setId = () => {
console.log("setId start");
peer.id = document.getElementById("id").value;
console.log(document.getElementById("id").value);
console.log(peer.id);
}
var connex;
actuallyConnect = () => {
connex = peer.connect(document.getElementById("broId").value);
console.log(connex.peer);
}
peer.on('open', (cata) => {
console.log("hi");
})
peer.on("connection", (conn) => {
console.log("connection");
conn.on("data", (data) => {
// Will print 'hi!'
console.log(data);
});
conn.on("open", () => {
console.log("stuff");
conn.send("hello!");
});
});
peer.on('error', function (err) {
console.log(err.type);
});
setId
and actuallyConnect
are triggered by html buttons.
The console outputs :
24764
Live reload enabled
PeerJS: Socket open
PeerJS: Invalid server message connected
What does the last line mean ? I can't connect or change peer id (setId doesn't work for some reason)
Hey @DiuDono.
Your local PeerJS server was probably not running (on that port/path). Does it work againt the cloud server (without host,secure,port
)?
I don’t think your setId
function will work. Ids should be a read-only property. If you need a Peer with a specific id, just .destroy()
the old one and create a new Peer(newId)