Add option
This commit is contained in:
parent
cb4f933e04
commit
4fc23261b3
@ -15,7 +15,8 @@ function PeerServer(options) {
|
|||||||
key: 'peerjs',
|
key: 'peerjs',
|
||||||
ip_limit: 5000,
|
ip_limit: 5000,
|
||||||
concurrent_limit: 5000,
|
concurrent_limit: 5000,
|
||||||
ssl: {}
|
ssl: {},
|
||||||
|
path: '/'
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
util.debug = this._options.debug;
|
util.debug = this._options.debug;
|
||||||
@ -27,6 +28,14 @@ function PeerServer(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._options.ssl['name'] = 'PeerServer';
|
this._options.ssl['name'] = 'PeerServer';
|
||||||
|
|
||||||
|
if (this._options.path[0] !== '/') {
|
||||||
|
this._options.path = '/' + this._options.path;
|
||||||
|
}
|
||||||
|
if (this._options.path[this._options.path.length - 1] !== '/') {
|
||||||
|
this._options.path += '/';
|
||||||
|
}
|
||||||
|
|
||||||
this._app = restify.createServer(this._options.ssl);
|
this._app = restify.createServer(this._options.ssl);
|
||||||
|
|
||||||
// Connected clients
|
// Connected clients
|
||||||
@ -56,7 +65,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._app});
|
this._wss = new WebSocketServer({ path: this._options.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;
|
||||||
@ -180,14 +189,14 @@ PeerServer.prototype._initializeHTTP = function() {
|
|||||||
this._app.use(util.allowCrossDomain);
|
this._app.use(util.allowCrossDomain);
|
||||||
|
|
||||||
// Retrieve guaranteed random ID.
|
// Retrieve guaranteed random ID.
|
||||||
this._app.get('/:key/id', function(req, res, next) {
|
this._app.get(this._options.path + ':key/id', function(req, res, next) {
|
||||||
res.contentType = 'text/html';
|
res.contentType = 'text/html';
|
||||||
res.send(self._generateClientId(req.params.key));
|
res.send(self._generateClientId(req.params.key));
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Server sets up HTTP streaming when you get post an ID.
|
// Server sets up HTTP streaming when you get post an ID.
|
||||||
this._app.post('/:key/:id/:token/id', function(req, res, next) {
|
this._app.post(this._options.path + ':key/:id/:token/id', function(req, res, next) {
|
||||||
var id = req.params.id;
|
var id = req.params.id;
|
||||||
var token = req.params.token;
|
var token = req.params.token;
|
||||||
var key = req.params.key;
|
var key = req.params.key;
|
||||||
@ -241,13 +250,13 @@ PeerServer.prototype._initializeHTTP = function() {
|
|||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
|
|
||||||
this._app.post('/:key/:id/:token/offer', handle);
|
this._app.post(this._options.path + ':key/:id/:token/offer', handle);
|
||||||
|
|
||||||
this._app.post('/:key/:id/:token/candidate', handle);
|
this._app.post(this._options.path + ':key/:id/:token/candidate', handle);
|
||||||
|
|
||||||
this._app.post('/:key/:id/:token/answer', handle);
|
this._app.post(this._options.path + ':key/:id/:token/answer', handle);
|
||||||
|
|
||||||
this._app.post('/:key/:id/:token/leave', handle);
|
this._app.post(this._options.path + ':key/:id/:token/leave', handle);
|
||||||
|
|
||||||
// Listen on user-specified port.
|
// Listen on user-specified port.
|
||||||
this._app.listen(this._options.port);
|
this._app.listen(this._options.port);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user