8

I have a problem with PeerJS server. I used "Deploy to Heroku" button from here: https://github.com/peers/peerjs-server

I have no idea how can I connect with deployed cloud. I can't find clear documentatnion about PeerJS Server.

I don't know what is the host, port, and path for my app.

var peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});

Please advice.

Damian
  • 111
  • 1
  • 3

3 Answers3

8

This how it worked for me:

var peer = new Peer('someid', {
                secure: true, 
                host: 'your-app-name.herokuapp.com', 
                port: 443,
    });
xims
  • 1,570
  • 17
  • 22
  • I am getting,,, "peerjs/id?ts=16303228229380.2362624806656488:1 Failed to load resource: the server responded with a status of 404 (Not Found)" – Neeleshwar Kumar Aug 30 '21 at 11:27
  • 1
    Sounds like your host is set to just 'peerjs' and not to a full URL that can be accessed. – xims Aug 30 '21 at 23:07
3

Your host is simply the web address to your Heroku app. For instance, if your Heroku app is named peerjsapp, then host would be 'peerjsapp.herokuapp.com'. You can find the name of your app on your Heroku dashboard. The port is usually 9000, but can be 443 if you're using HTTPS (make sure to also pass in secure:true if you're using HTTPS). You don't need to include the path unless you've changed it; if you're running the default server config, leaving out the path on your client will automatically connect. Finally, since you're hosting your own server, you don't need an ID.

mt_xing
  • 631
  • 7
  • 22
  • 3
    With the default config, `PeerJS` tries to bind to port 443 and `Heroku` goes no no, those are system ports `Access denied`. Anyone else facing this? Worse still, `Heroku` only exposes a single port. I have tried using the `ExpressPeerServer` but following the code on the `docs` always gives me a `404` on the client side. – Dev Yego Nov 15 '20 at 13:45
  • I get a `401 access denied` as well when using `new Peer('someid', { host: my-peer-server.herokuapp.com/', secure:true, port: 443 })` – Null Salad Dec 29 '20 at 21:31
0

• This is how I think you should do it:

const myPeer = new Peer(undefined, {
  secure: true,
  host: '0.peerjs.com',
  port: '443'
})

• EXPLANATION:

After deploying your app to Heroku, typed 'peerjs' into the console to search for the peerjs object, from which you can navigate and find the key-value pair of

CLOUD_HOST: "0.peerjs.com"

CLOUD_PORT: "443"

The next step is just to match your own host and port with these values.

This is how I do it Console Screenshot

• NOTE:

For the secure: true part I have tried and the app works both with and without it. So it's on you to choose to include it or not. I have also found out on https://peerjs.com/docs.html this same information, check it out if you want more detailed documentation.