Help for custom server setup

2,148 views
Skip to first unread message

websnake.s...@gmail.com

unread,
Apr 30, 2014, 6:34:21 AM4/30/14
to pee...@googlegroups.com
Hi everybody,
I'm trying to setup a custom server on a windows machine, I have installed node.js and PeerJs.

I have read the instructions here: https://github.com/peers/peerjs-server

But there's something I don't understand, for example.... to publish the video chat test page like this:

http://cdn.peerjs.com/demo/videochat/

on my custom server, what should I do?

Where do I put the lines of code that I see on the instruction page?

I need to generate the Id? If yes, how can I generate the Id?

Srikanta Patanjali

unread,
May 3, 2014, 9:31:07 AM5/3/14
to pee...@googlegroups.com, websnake.s...@gmail.com
Hi, you need to create a html page (typically index.html) which contains the code mentioned in the instruction. The file can be uploaded into the webserver where your domain is parked.

Yes, its advisable to generate your own api to get the user id. That is mentioned again in the instructions or you can take a look at the source of the demo applications.


Cheers,
Srikanta

websnake.s...@gmail.com

unread,
May 5, 2014, 12:31:22 PM5/5/14
to pee...@googlegroups.com, websnake.s...@gmail.com
Hi Srikanta,
many thanks for your help, sure I have to upload a page with the demo code in my domain, but I think I should modify the code to use my custom server and I don't understand how.

I try to explain step by step


Install the library:
$> npm install peer

[Ok, done]

---------------

Run the server:
$> peerjs --port 9000 --key peerjs

[Ok, done]

---------------

Or, create a custom server:
var PeerServer = require('peer').PeerServer;
var server = new PeerServer({port: 9000, path: '/myapp'});

[Where should I put this code?]

---------------

Connecting to the server from PeerJS:

<script>
// No API key required when not using cloud server
var peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
</script>

[I think I don't need this code]

---------------

Using HTTPS: Simply pass in PEM-encoded certificate and key.

var fs = require('fs');
var PeerServer = require('peer').PeerServer;

var server = new PeerServer({
port: 9000,
ssl: {
key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
certificate: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')
}
});

[Where should I put this code?]

---------------

Michelle Bu

unread,
May 5, 2014, 12:47:29 PM5/5/14
to websnake.s...@gmail.com, peerjs
Responses inline.


>
> Or, create a custom server:
> var PeerServer = require('peer').PeerServer;
> var server = new PeerServer({port: 9000, path: '/myapp'});
>
> [Where should I put this code?]
>

You don't need this part if you just ran with via command line, which
it looks like you did.

>
> Connecting to the server from PeerJS:
>
> <script>
> // No API key required when not using cloud server
> var peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
> </script>
>
> [I think I don't need this code]
>

This is actually the most important part. You need to include (see
'Include the Library' step on https://github.com/peers/peerjs) the
peer.js script in your HTML, then instantiate a new peer object in the
browser in order to connect to other peers.

>
> Using HTTPS: Simply pass in PEM-encoded certificate and key.
>
> var fs = require('fs');
> var PeerServer = require('peer').PeerServer;
>
> var server = new PeerServer({
> port: 9000,
> ssl: {
> key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
> certificate: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')
> }
> });
>

You don't need this part if you're using the command line tool.

websnake.s...@gmail.com

unread,
May 7, 2014, 12:41:45 PM5/7/14
to pee...@googlegroups.com, websnake.s...@gmail.com, miche...@berkeley.edu
Hi Michelle,
I really appreciate your support,

Here's what I've done:

On the root of my application I've put only the code that I have dowloaded from here:

https://github.com/peers/peerjs

I've changed the line that you have suggested me

from this: var peer = new Peer({ key: 'lwjd5qra8257b9', debug: 3});

to this: var peer = new Peer('', {host: 'localhost', port: 9000});

Because I've read this in the site:
If no ID is given, one will be generated by the brokering server.

and I've read this on the forum:
there's no "/" route provided by the peer server.
You should just be able to use peer.js and pass in {host:'localhost', port:9000} to the `Peer` constructor.


Now, when I execute the page with the video chat example I see this error:

Could not get an ID from the server.
If you passed in a path to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer.

thank you

Michelle Bu

unread,
May 8, 2014, 4:44:57 PM5/8/14
to Daniele Pitone, peerjs
Are you running your own peer server on localhost:9000?
Michelle

websnake.s...@gmail.com

unread,
May 9, 2014, 6:21:10 AM5/9/14
to pee...@googlegroups.com, Daniele Pitone, miche...@berkeley.edu
Thank you again Michelle,

yes, we are running peer server on localhost:9000,

we've executed code: $> peerjs --port 9000 --key peerjs on Node.js Command prompt

and the response was: Started PeerServer, port: 9000, path: / (v. 0.2.5)

When I navigate with the browser on http://localhost:9000

I see this message:

{"code":"ResourceNotFound","message":"/ does not exist"}

I don't know if it's normal


websnake.s...@gmail.com

unread,
May 14, 2014, 4:43:20 AM5/14/14
to pee...@googlegroups.com, Daniele Pitone, miche...@berkeley.edu
Hi everybody,

problem solved!

The solution is change localhost with the real address of my domain in this line of code:

from

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

to
var peer = new Peer('', {host: 'www.mydomain.com', port: 9000});

Now it works, thank you!


Reply all
Reply to author
Forward
0 new messages