|
@@ -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. */
|