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?
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?]
---------------
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
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
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!