4 spaces to 2 spaces
This commit is contained in:
parent
563eb46f04
commit
1bbce52ae9
136
lib/index.js
136
lib/index.js
@ -5,95 +5,95 @@ var http = require('http');
|
|||||||
var https = require('https');
|
var https = require('https');
|
||||||
|
|
||||||
function ExpressPeerServer(server, options) {
|
function ExpressPeerServer(server, options) {
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
util.extend(app, proto);
|
util.extend(app, proto);
|
||||||
|
|
||||||
options = app._options = util.extend({
|
options = app._options = util.extend({
|
||||||
debug: false,
|
debug: false,
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
key: 'peerjs',
|
key: 'peerjs',
|
||||||
ip_limit: 5000,
|
ip_limit: 5000,
|
||||||
concurrent_limit: 5000,
|
concurrent_limit: 5000,
|
||||||
allow_discovery: false,
|
allow_discovery: false,
|
||||||
proxied: false
|
proxied: false
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
// Connected clients
|
// Connected clients
|
||||||
app._clients = {};
|
app._clients = {};
|
||||||
|
|
||||||
// Messages waiting for another peer.
|
// Messages waiting for another peer.
|
||||||
app._outstanding = {};
|
app._outstanding = {};
|
||||||
|
|
||||||
// Mark concurrent users per ip
|
// Mark concurrent users per ip
|
||||||
app._ips = {};
|
app._ips = {};
|
||||||
|
|
||||||
if (options.proxied) {
|
if (options.proxied) {
|
||||||
app.set('trust proxy', options.proxied);
|
app.set('trust proxy', options.proxied);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.on('mount', function() {
|
||||||
|
if (!server) {
|
||||||
|
throw new Error('Server is not passed to constructor - '+
|
||||||
|
'can\'t start PeerServer');
|
||||||
}
|
}
|
||||||
|
|
||||||
app.on('mount', function() {
|
// Initialize HTTP routes. This is only used for the first few milliseconds
|
||||||
if (!server) {
|
// before a socket is opened for a Peer.
|
||||||
throw new Error('Server is not passed to constructor - '+
|
app._initializeHTTP();
|
||||||
'can\'t start PeerServer');
|
app._setCleanupIntervals();
|
||||||
}
|
app._initializeWSS(server);
|
||||||
|
});
|
||||||
|
|
||||||
// Initialize HTTP routes. This is only used for the first few milliseconds
|
return app;
|
||||||
// before a socket is opened for a Peer.
|
|
||||||
app._initializeHTTP();
|
|
||||||
app._setCleanupIntervals();
|
|
||||||
app._initializeWSS(server);
|
|
||||||
});
|
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function PeerServer(options, callback) {
|
function PeerServer(options, callback) {
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var path = options.path || '/';
|
var path = options.path || '/';
|
||||||
var port = options.port || 80;
|
var port = options.port || 80;
|
||||||
|
|
||||||
delete options.path;
|
delete options.path;
|
||||||
|
|
||||||
if (path[0] !== '/') {
|
if (path[0] !== '/') {
|
||||||
path = '/' + path;
|
path = '/' + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path[path.length - 1] !== '/') {
|
||||||
|
path += '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
var server;
|
||||||
|
if (options.ssl) {
|
||||||
|
if (options.ssl.certificate) {
|
||||||
|
// Preserve compatibility with 0.2.7 API
|
||||||
|
options.ssl.cert = options.ssl.certificate;
|
||||||
|
delete options.ssl.certificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path[path.length - 1] !== '/') {
|
server = https.createServer(options.ssl, app);
|
||||||
path += '/';
|
delete options.ssl;
|
||||||
}
|
} else {
|
||||||
|
server = http.createServer(app);
|
||||||
|
}
|
||||||
|
|
||||||
var server;
|
var peerjs = ExpressPeerServer(server, options);
|
||||||
if (options.ssl) {
|
app.use(path, peerjs);
|
||||||
if (options.ssl.certificate) {
|
|
||||||
// Preserve compatibility with 0.2.7 API
|
|
||||||
options.ssl.cert = options.ssl.certificate;
|
|
||||||
delete options.ssl.certificate;
|
|
||||||
}
|
|
||||||
|
|
||||||
server = https.createServer(options.ssl, app);
|
if (callback) {
|
||||||
delete options.ssl;
|
server.listen(port, function() {
|
||||||
} else {
|
callback(server);
|
||||||
server = http.createServer(app);
|
});
|
||||||
}
|
} else {
|
||||||
|
server.listen(port);
|
||||||
|
}
|
||||||
|
|
||||||
var peerjs = ExpressPeerServer(server, options);
|
return peerjs;
|
||||||
app.use(path, peerjs);
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
server.listen(port, function() {
|
|
||||||
callback(server);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
server.listen(port);
|
|
||||||
}
|
|
||||||
|
|
||||||
return peerjs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
ExpressPeerServer: ExpressPeerServer,
|
ExpressPeerServer: ExpressPeerServer,
|
||||||
PeerServer: PeerServer
|
PeerServer: PeerServer
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user