From 1bbce52ae9cf20a4f8d95aa8dfeeeb2455db7724 Mon Sep 17 00:00:00 2001 From: Michelle Bu Date: Sat, 1 Nov 2014 13:47:55 -0700 Subject: [PATCH] 4 spaces to 2 spaces --- lib/index.js | 136 +++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/lib/index.js b/lib/index.js index dcb85b5..5c928fb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,95 +5,95 @@ var http = require('http'); var https = require('https'); function ExpressPeerServer(server, options) { - var app = express(); + var app = express(); - util.extend(app, proto); + util.extend(app, proto); - options = app._options = util.extend({ - debug: false, - timeout: 5000, - key: 'peerjs', - ip_limit: 5000, - concurrent_limit: 5000, - allow_discovery: false, - proxied: false - }, options); + options = app._options = util.extend({ + debug: false, + timeout: 5000, + key: 'peerjs', + ip_limit: 5000, + concurrent_limit: 5000, + allow_discovery: false, + proxied: false + }, options); - // Connected clients - app._clients = {}; + // Connected clients + app._clients = {}; - // Messages waiting for another peer. - app._outstanding = {}; + // Messages waiting for another peer. + app._outstanding = {}; - // Mark concurrent users per ip - app._ips = {}; + // Mark concurrent users per ip + app._ips = {}; - if (options.proxied) { - app.set('trust proxy', options.proxied); + if (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() { - if (!server) { - throw new Error('Server is not passed to constructor - '+ - 'can\'t start PeerServer'); - } + // Initialize HTTP routes. This is only used for the first few milliseconds + // before a socket is opened for a Peer. + app._initializeHTTP(); + app._setCleanupIntervals(); + app._initializeWSS(server); + }); - // Initialize HTTP routes. This is only used for the first few milliseconds - // before a socket is opened for a Peer. - app._initializeHTTP(); - app._setCleanupIntervals(); - app._initializeWSS(server); - }); - - return app; + return app; } function PeerServer(options, callback) { - var app = express(); + var app = express(); - options = options || {}; - var path = options.path || '/'; - var port = options.port || 80; + options = options || {}; + var path = options.path || '/'; + var port = options.port || 80; - delete options.path; + delete options.path; - if (path[0] !== '/') { - path = '/' + path; + if (path[0] !== '/') { + 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] !== '/') { - path += '/'; - } + server = https.createServer(options.ssl, app); + delete options.ssl; + } else { + server = http.createServer(app); + } - 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; - } + var peerjs = ExpressPeerServer(server, options); + app.use(path, peerjs); - server = https.createServer(options.ssl, app); - delete options.ssl; - } else { - server = http.createServer(app); - } + if (callback) { + server.listen(port, function() { + callback(server); + }); + } else { + server.listen(port); + } - var peerjs = ExpressPeerServer(server, options); - app.use(path, peerjs); - - if (callback) { - server.listen(port, function() { - callback(server); - }); - } else { - server.listen(port); - } - - return peerjs; + return peerjs; } exports = module.exports = { - ExpressPeerServer: ExpressPeerServer, - PeerServer: PeerServer + ExpressPeerServer: ExpressPeerServer, + PeerServer: PeerServer };