peerjs-server icon indicating copy to clipboard operation
peerjs-server copied to clipboard

Path configuration is confusing and inconsistent with frontend PeerJS client config

Open intellix opened this issue 4 years ago • 1 comments

I have a suggestion:

Currently the suggestion is to do something like the following:

const peerServer = ExpressPeerServer(server);
app.use('/peerjs', peerServer);

This actually creates a binding on /peerjs/peerjs because inside the ExpressPeerServer middleware it's adding an app.use(options.path, xyz).

Alongside that, on the client there isn't double paths without being explicit:

const peer = new Peer('123', {
  host: 'localhost',
  port: 9001,
  path: '/peerjs/peerjs',
  secure: false,
  debug: 2,
  config: {
    iceServers,
  },
});

I think it would just be easier to understand if this:

const peerServer = ExpressPeerServer(server);
app.use('/peerjs', peerServer);

Created a binding on just /peerjs. I don't really understand why there's the ability to define an extra path on top.

There shouldn't be any automatic adding of paths anywhere. So you know exactly what you're writing is going to be the endpoint

intellix avatar Jan 19 '21 21:01 intellix

You are correct, this is a big source of confusion, but changing the code simply to correct that would affect all the working code out there. I have found that most of the tutorials, if not all don't actually work. Often due to changes in the code. My suggestion is to improve the manual! I didn't know of this double app.use(....) that you mentioned here, and thanks to you now I do. I solved this by explicitly doing:

const peerServer = ExpressPeerServer(mainServer, {
        debug: true,
        path: '',
        ssl: {},
})

spine001 avatar Jul 21 '21 18:07 spine001