|
@@ -1,5 +1,4 @@
|
|
|
var util = require('./util');
|
|
|
-var express = require('express');
|
|
|
var bodyParser = require('body-parser');
|
|
|
var WebSocketServer = require('ws').Server;
|
|
|
var url = require('url');
|
|
@@ -7,11 +6,18 @@ var url = require('url');
|
|
|
var app = exports = module.exports = {};
|
|
|
|
|
|
/** Initialize WebSocket server. */
|
|
|
-app._initializeWSS = function() {
|
|
|
+app._initializeWSS = function(server) {
|
|
|
var self = this;
|
|
|
|
|
|
+ if (this.mountpath instanceof Array) {
|
|
|
+ throw new Error("This app can only be mounted on a single path");
|
|
|
+ }
|
|
|
+
|
|
|
+ var path = this.mountpath;
|
|
|
+ var path = path + (path[path.length - 1] != '/' ? '/' : '') + 'peerjs';
|
|
|
+
|
|
|
// Create WebSocket server as well.
|
|
|
- this._wss = new WebSocketServer({ path: this.options.path + 'peerjs', server: this._server});
|
|
|
+ this._wss = new WebSocketServer({ path: path, server: server});
|
|
|
|
|
|
this._wss.on('connection', function(socket) {
|
|
|
var query = url.parse(socket.upgradeReq.url, true).query;
|
|
@@ -139,13 +145,13 @@ app._initializeHTTP = function() {
|
|
|
this.use(util.allowCrossDomain);
|
|
|
|
|
|
// Retrieve guaranteed random ID.
|
|
|
- this.get(this.options.path + ':key/id', function(req, res, next) {
|
|
|
+ this.get('/:key/id', function(req, res, next) {
|
|
|
res.contentType = 'text/html';
|
|
|
res.send(self._generateClientId(req.params.key));
|
|
|
});
|
|
|
|
|
|
// Server sets up HTTP streaming when you get post an ID.
|
|
|
- this.post(this.options.path + ':key/:id/:token/id', function(req, res, next) {
|
|
|
+ this.post('/:key/:id/:token/id', function(req, res, next) {
|
|
|
var id = req.params.id;
|
|
|
var token = req.params.token;
|
|
|
var key = req.params.key;
|
|
@@ -167,7 +173,7 @@ app._initializeHTTP = function() {
|
|
|
});
|
|
|
|
|
|
// Get a list of all peers for a key, enabled by the `allowDiscovery` flag.
|
|
|
- this.get(this.options.path + ':key/peers', function(req, res, next) {
|
|
|
+ this.get('/:key/peers', function(req, res, next) {
|
|
|
var key = req.params.key;
|
|
|
if (self._clients[key]) {
|
|
|
self._checkAllowsDiscovery(key, function(isAllowed) {
|
|
@@ -213,13 +219,13 @@ app._initializeHTTP = function() {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- this.post(this.options.path + ':key/:id/:token/offer', handle);
|
|
|
+ this.post('/:key/:id/:token/offer', handle);
|
|
|
|
|
|
- this.post(this.options.path + ':key/:id/:token/candidate', handle);
|
|
|
+ this.post('/:key/:id/:token/candidate', handle);
|
|
|
|
|
|
- this.post(this.options.path + ':key/:id/:token/answer', handle);
|
|
|
+ this.post('/:key/:id/:token/answer', handle);
|
|
|
|
|
|
- this.post(this.options.path + ':key/:id/:token/leave', handle);
|
|
|
+ this.post('/:key/:id/:token/leave', handle);
|
|
|
};
|
|
|
|
|
|
/** Saves a streaming response and takes care of timeouts and headers. */
|