peerjs-server: Error during WebSocket handshake: Unexpected response code: 200
I saw similar errors for code 400 and 404, but this one seems strange. After all, I would think a 200 code would mean “everything’s ok” right?
"peer": "^0.5.1",
"peerjs": "^1.2.0"
On server side:
import { ExpressPeerServer } from 'peer'
const PeerController = {}
PeerController.initialize = function (app) {
const peerServer = ExpressPeerServer(app, { debug: true, path: '/peerjs' })
peerServer.on('connection', (client, foo) => {
console.log(client, foo)
})
return peerServer
}
export default PeerController
const app = express()
app.use('/peer', PeerController.initialize(app))
And on the client side (a Vue application):
import Peer from 'peerjs'
export default {
name: 'Meet',
data () {
return {
peer: null
}
},
mounted () {
this.peer = new Peer('12345', {
host: '/',
port: '3000',
path: '/peer/',
debug: 3
})
this.peer.on('error', (err) => {
console.debug(err)
})
this.peer.on('open', function (id) {
console.log(id)
})
}
}
vendor.3921cbfb.js:18 WebSocket connection to 'ws://localhost:3000/peer/peerjs?key=peerjs&id=12345&token=697lo3pxz52' failed: Error during WebSocket handshake: Unexpected response code: 200
I noticed that it was 404ing initially until I added the path: '/peerjs' in the ExpressPeerServer constructor, because it seems that no matter what the client library tries to hit that endpoint. Not a huge worry, but after I solved the 404 issue I now get an “error” with a 200 code. Any advice? Thank you very much…
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (9 by maintainers)
@baggachipz Anyway, join to our telegram chat) https://t.me/joinchat/ENhPuhTvhm8WlIxTjQf7Og
Looks like using the look-ahead regex worked. Might be handy to also allow passing in app instead of server, so that this is easier to handle. But thank you for your assistance!
Having the same issue, I’m using NextJS so I’ve created a custom server.ts where I use ExpressJS and I bind the ExpressPeerServer to the route /peerjs and the websocket connection fails with a 404
@afrokick I was having the same issue (peerjs 1.2.0 and peer server 0.5.1) with the following configs:
and
Looking at networking requests on the client, the GET request to
localhost:9000/peer/peerjs/idsucceeds but the websocket connection tolocalhost:9000/peer/peerjsdoes not work.I then rolled back the peer server to v0.5.0 and retried, and the client was able to connect to the server. Hope this helps!