update README

This commit is contained in:
afrokick 2019-04-01 16:17:39 +03:00
parent 6f509b848c
commit 86882a74f0
3 changed files with 53 additions and 90 deletions

View File

@ -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: 3. Run the server:
```bash
```javascript $> node ./src/index.js --port 9000 --path /myapp
var PeerServer = require('peer').PeerServer;
var server = PeerServer({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 const peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
var 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 ```bash
var fs = require('fs'); $> node ./src/index.js --port 9000 --path /myapp --sslKeyPath /path/to/your/ssl/key/here.key --sslCertPath /path/to/your/ssl/certificate/here.crt
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')
}
});
``` ```
#### 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 ```bash
var PeerServer = require('peer').PeerServer; $> node ./src/index.js --port 9000 --path /myapp --proxied true
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) { ... });
``` ```
## Problems? ## Problems?

View File

@ -1,10 +1,24 @@
const convict = require('convict'); const convict = require('convict');
module.exports = convict({ module.exports = convict({
debug: { logger: {
doc: 'Enable debug mode', level: {
format: Boolean, doc: 'The log level. See log4js',
default: false format: [
'ALL',
'MARK',
'TRACE',
'DEBUG',
'INFO',
'WARN',
'ERROR',
'FATAL',
'OFF'
],
default: 'ERROR',
env: 'LOG_LEVEL',
arg: 'logLevel'
}
}, },
env: { env: {
doc: 'The application environment.', doc: 'The application environment.',
@ -27,27 +41,35 @@ module.exports = convict({
key: { key: {
doc: 'The key to check incoming clients', doc: 'The key to check incoming clients',
format: String, format: String,
default: 'peerjs' default: 'peerjs',
env: 'APP_KEY',
arg: 'key'
}, },
path: { path: {
doc: '', doc: '',
format: String, format: String,
default: '/myapp' default: '/myapp',
env: 'APP_PATH',
arg: 'path'
}, },
concurrent_limit: { concurrent_limit: {
doc: 'Max connections', doc: 'Max connections',
format: 'duration', format: 'duration',
default: 5000 default: 5000,
arg: 'concurrentLimit'
}, },
allow_discovery: { allow_discovery: {
doc: 'Allow discovery of peers', doc: 'Allow discovery of peers',
format: Boolean, format: Boolean,
default: false default: false,
arg: 'allowDiscovery'
}, },
proxied: { proxied: {
doc: 'Set true if server running behind proxy', doc: 'Set true if server running behind proxy',
format: Boolean, format: Boolean,
default: false default: false,
env: 'APP_PROXIED',
arg: 'proxied'
}, },
cleanup_out_msgs: { cleanup_out_msgs: {
doc: '', doc: '',
@ -58,12 +80,14 @@ module.exports = convict({
key_path: { key_path: {
doc: 'The path to the private key file', doc: 'The path to the private key file',
format: String, format: String,
default: '' default: '',
arg: 'sslKeyPath'
}, },
cert_path: { cert_path: {
doc: 'The path to the cert file', doc: 'The path to the cert file',
format: String, format: String,
default: '' default: '',
arg: 'sslCertPath'
} }
} }
}); });

View File

@ -1,6 +1,8 @@
const log4js = require('log4js'); const log4js = require('log4js');
const config = require('../../../config');
const logger = log4js.getLogger(); const logger = log4js.getLogger();
logger.level = 'ALL';
logger.level = config.get('logger.level');
module.exports = logger; module.exports = logger;