I get the error in the title in the console of my server. Of course, I tried without running my own server at first, but then it just failed silently (i.e. it seemed to connect but the connection never opened). All of this is running on localhost.
Client-side code:
var peer
var conn
if (window.location.pathname == '/client') {
peer = new Peer('tactiks_guestb', {
host: 'localhost',
port: 8081,
path: '/peerjs'
})
conn = peer.connect('tactiks_hostb')
conn.on('open', () => {
conn.send('hi!');
});
this.peer = peer
this.conn = conn
conn.on('error', console.log)
peer.on('error', console.log)
} else {
peer = new Peer('tactiks_hostb', {
host: 'localhost',
port: 8081,
path: '/peerjs'
})
this.peer = peer
peer.on('error', console.log)
peer.on('connection', (conn) => {
conn.on('error', console.log)
this.conn = conn
conn.on('data', (data) => {
console.log(data)
})
})
}
Server-side code:
var express = require('express')
var app = express()
srv = app.listen(8081)
var ExpressPeerServer = require('peer').ExpressPeerServer;
var ps = ExpressPeerServer(srv, {
debug: true
})
app.use('/peerjs', ps)
ps.on('connection', (id) => {
console.log(id)
console.log(srv._clients)
})
@kahrkunne Which version do you use on client/server?
I am getting this same error in the server. I am using Peer Server version 0.2.10 and Peerjs version 1.1.0 on the client. The server is running in Electron and the client is running in the browser (testing both Chrome 77.0.3865.120 and Firefox 69.0.3).
The error happens when the client calls peer.connect(peerID); to connect with the server.
The error is coming from peer\lib\util.js:27, which traces back to peer\lib\server.js line 91
The if statement always resolves to else and displays util.prettyError, even in cases where the message is a CANDIDATE or OFFER.
socket.on("message", function(data) {
try {
var message = JSON.parse(data);
if (
["LEAVE", "CANDIDATE", "OFFER", "ANSWER"].indexOf(message.type) !== -1
) {
self._handleTransmission(key, {
type: message.type,
src: id,
dst: message.dst,
payload: message.payload
});
} else {
util.prettyError("Message unrecognized");
}
} catch (e) {
self._log("Invalid message", data);
throw e;
}
});
util.prettyError("Message unrecognized");
}
} catch (e) {
self._log("Invalid message", data);
throw e;
}
UPDATE: I updated all of my dependencies and ran this again. I'm still getting the error, but it appears to be happening only on HEARTBEAT now. CANDIDATE and OFFER are working as expected.
["LEAVE", "CANDIDATE", "OFFER", "ANSWER"] in this array add missing message name ....in case of Peerjs ,HEARTBEAT is not there.
So after adding HEARTBEAT as ["LEAVE", "CANDIDATE", "OFFER", "ANSWER","HEARTBEAT" ] has resolved my issue.
Is this issue going to be fixed anytime soon?
Most helpful comment
["LEAVE", "CANDIDATE", "OFFER", "ANSWER"] in this array add missing message name ....in case of Peerjs ,HEARTBEAT is not there.
So after adding HEARTBEAT as ["LEAVE", "CANDIDATE", "OFFER", "ANSWER","HEARTBEAT" ] has resolved my issue.