ssl options, closes #13
This commit is contained in:
parent
c0130c418b
commit
70ee781154
27
README.md
27
README.md
@ -10,22 +10,35 @@ PeerServer helps broker connections between PeerJS clients. Data is not proxied
|
|||||||
|
|
||||||
### Run PeerServer
|
### Run PeerServer
|
||||||
|
|
||||||
Install the library
|
Install the library:
|
||||||
|
|
||||||
npm install peer
|
npm install peer
|
||||||
|
|
||||||
Run the server
|
Run the server:
|
||||||
|
|
||||||
var PeerServer = require('peer').PeerServer;
|
var PeerServer = require('peer').PeerServer;
|
||||||
var server = new PeerServer({ port: 9000 });
|
var server = new PeerServer({ port: 9000 });
|
||||||
|
|
||||||
Connecting to the server from PeerJS
|
Connecting to the server from PeerJS:
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// No API key requried when not using cloud server
|
// No API key required when not using cloud server
|
||||||
var peer = new Peer('someid', {host: 'localhost', port: 9000});
|
var peer = new Peer('someid', {host: 'localhost', port: 9000});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
## Problems?
|
## Problems?
|
||||||
|
|
||||||
Discuss PeerJS on our Google Group:
|
Discuss PeerJS on our Google Group:
|
||||||
|
@ -9,20 +9,29 @@ function PeerServer(options) {
|
|||||||
if (!(this instanceof PeerServer)) return new PeerServer(options);
|
if (!(this instanceof PeerServer)) return new PeerServer(options);
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
this._app = restify.createServer();
|
|
||||||
this._httpServer = this._app;
|
|
||||||
|
|
||||||
this._options = util.extend({
|
this._options = util.extend({
|
||||||
port: 80,
|
port: 80,
|
||||||
debug: false,
|
debug: false,
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
key: 'peerjs',
|
key: 'peerjs',
|
||||||
ip_limit: 5000,
|
ip_limit: 5000,
|
||||||
concurrent_limit: 5000
|
concurrent_limit: 5000,
|
||||||
|
ssl: {}
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
util.debug = this._options.debug;
|
util.debug = this._options.debug;
|
||||||
|
|
||||||
|
// Set up HTTPS server if key and certificate are provided.
|
||||||
|
var secure = this._options.ssl.key && this._options.ssl.certificate;
|
||||||
|
// Print warning if only one of the two is given.
|
||||||
|
if (Object.keys(this._options.ssl).length === 1) {
|
||||||
|
util.prettyError('Warning: PeerServer will not run on an HTTPS server'
|
||||||
|
+ ' because either the key or the certificate has not been provided.');
|
||||||
|
}
|
||||||
|
|
||||||
|
this._options.ssl['name'] = 'PeerServer';
|
||||||
|
this._app = restify.createServer(this._options.ssl);
|
||||||
|
|
||||||
// Connected clients
|
// Connected clients
|
||||||
this._clients = {};
|
this._clients = {};
|
||||||
|
|
||||||
@ -50,7 +59,7 @@ PeerServer.prototype._initializeWSS = function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Create WebSocket server as well.
|
// Create WebSocket server as well.
|
||||||
this._wss = new WebSocketServer({ path: '/peerjs', server: this._httpServer });
|
this._wss = new WebSocketServer({ path: '/peerjs', server: this._app});
|
||||||
|
|
||||||
this._wss.on('connection', function(socket) {
|
this._wss.on('connection', function(socket) {
|
||||||
var query = url.parse(socket.upgradeReq.url, true).query;
|
var query = url.parse(socket.upgradeReq.url, true).query;
|
||||||
@ -253,7 +262,7 @@ PeerServer.prototype._initializeHTTP = function() {
|
|||||||
this._app.post('/:key/:id/:token/leave', handle);
|
this._app.post('/:key/:id/:token/leave', handle);
|
||||||
|
|
||||||
// Listen on user-specified port.
|
// Listen on user-specified port.
|
||||||
this._httpServer.listen(this._options.port);
|
this._app.listen(this._options.port);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Saves a streaming response and takes care of timeouts and headers. */
|
/** Saves a streaming response and takes care of timeouts and headers. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user