|
@@ -4,111 +4,48 @@
|
|
|
|
|
|
PeerServer helps broker connections between PeerJS clients. Data is not proxied through the server.
|
|
PeerServer helps broker connections between PeerJS clients. Data is not proxied through the server.
|
|
|
|
|
|
-## [http://peerjs.com](http://peerjs.com)
|
|
|
|
|
|
+## [https://peerjs.com](https://peerjs.com)
|
|
|
|
|
|
### Run PeerServer
|
|
### Run PeerServer
|
|
|
|
|
|
-Install the library:
|
|
|
|
-
|
|
|
|
|
|
+1. Clone app:
|
|
```bash
|
|
```bash
|
|
-$> npm install peer
|
|
|
|
|
|
+$> git clone https://github.com/peers/peerjs-server.git
|
|
```
|
|
```
|
|
|
|
|
|
-Run the server:
|
|
|
|
-
|
|
|
|
|
|
+2. Install dependencies:
|
|
```bash
|
|
```bash
|
|
-$> peerjs --port 9000 --key peerjs
|
|
|
|
|
|
+$> npm install
|
|
```
|
|
```
|
|
|
|
|
|
-Or, create a custom server:
|
|
|
|
-
|
|
|
|
-```javascript
|
|
|
|
-var PeerServer = require('peer').PeerServer;
|
|
|
|
-var server = PeerServer({port: 9000, path: '/myapp'});
|
|
|
|
|
|
+3. Run the server:
|
|
|
|
+```bash
|
|
|
|
+$> node ./src/index.js --port 9000 --path /myapp
|
|
```
|
|
```
|
|
|
|
|
|
Connecting to the server from PeerJS:
|
|
Connecting to the server from PeerJS:
|
|
|
|
|
|
```html
|
|
```html
|
|
<script>
|
|
<script>
|
|
- // No API key required when not using cloud server
|
|
|
|
- var peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
|
|
|
|
|
|
+ const peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
|
|
</script>
|
|
</script>
|
|
```
|
|
```
|
|
|
|
|
|
-Using HTTPS: Simply pass in PEM-encoded certificate and key.
|
|
|
|
|
|
+Using HTTPS: Simply pass in paths to PEM-encoded certificate and key.
|
|
|
|
|
|
-```javascript
|
|
|
|
-var fs = require('fs');
|
|
|
|
-var PeerServer = require('peer').PeerServer;
|
|
|
|
-
|
|
|
|
-var server = PeerServer({
|
|
|
|
- port: 9000,
|
|
|
|
- ssl: {
|
|
|
|
- key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
|
|
|
|
- cert: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')
|
|
|
|
- }
|
|
|
|
-});
|
|
|
|
|
|
+```bash
|
|
|
|
+$> node ./src/index.js --port 9000 --path /myapp --sslKeyPath /path/to/your/ssl/key/here.key --sslCertPath /path/to/your/ssl/certificate/here.crt
|
|
```
|
|
```
|
|
|
|
|
|
#### Running PeerServer behind a reverse proxy
|
|
#### Running PeerServer behind a reverse proxy
|
|
|
|
|
|
-Make sure to set the `proxied` option, otherwise IP based limiting will fail.
|
|
|
|
|
|
+Make sure to set the `proxied` option.
|
|
The option is passed verbatim to the
|
|
The option is passed verbatim to the
|
|
[expressjs `trust proxy` setting](http://expressjs.com/4x/api.html#app-settings)
|
|
[expressjs `trust proxy` setting](http://expressjs.com/4x/api.html#app-settings)
|
|
if it is truthy.
|
|
if it is truthy.
|
|
|
|
|
|
-```javascript
|
|
|
|
-var PeerServer = require('peer').PeerServer;
|
|
|
|
-var server = PeerServer({port: 9000, path: '/myapp', proxied: true});
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-### Combining with existing express app
|
|
|
|
-
|
|
|
|
-```javascript
|
|
|
|
-var express = require('express');
|
|
|
|
-var app = express();
|
|
|
|
-var ExpressPeerServer = require('peer').ExpressPeerServer;
|
|
|
|
-
|
|
|
|
-app.get('/', function(req, res, next) { res.send('Hello world!'); });
|
|
|
|
-
|
|
|
|
-// =======
|
|
|
|
-
|
|
|
|
-var server = app.listen(9000);
|
|
|
|
-
|
|
|
|
-var options = {
|
|
|
|
- debug: true
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-var peerserver = ExpressPeerServer(server, options);
|
|
|
|
-
|
|
|
|
-app.use('/api', peerserver);
|
|
|
|
-
|
|
|
|
-// == OR ==
|
|
|
|
-
|
|
|
|
-var server = require('http').createServer(app);
|
|
|
|
-var peerserver = ExpressPeerServer(server, options);
|
|
|
|
-
|
|
|
|
-app.use('/peerjs', peerserver);
|
|
|
|
-
|
|
|
|
-server.listen(9000);
|
|
|
|
-
|
|
|
|
-// ========
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-### Events
|
|
|
|
-
|
|
|
|
-The `'connection'` event is emitted when a peer connects to the server.
|
|
|
|
-
|
|
|
|
-```javascript
|
|
|
|
-peerserver.on('connection', function(id) { ... });
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-The `'disconnect'` event is emitted when a peer disconnects from the server or
|
|
|
|
-when the peer can no longer be reached.
|
|
|
|
-
|
|
|
|
-```javascript
|
|
|
|
-peerserver.on('disconnect', function(id) { ... });
|
|
|
|
|
|
+```bash
|
|
|
|
+$> node ./src/index.js --port 9000 --path /myapp --proxied true
|
|
```
|
|
```
|
|
|
|
|
|
## Problems?
|
|
## Problems?
|