diff --git a/.eslintrc b/.eslintrc index 7b33fc84645a0a6fd6eb2797c9aeaaf9aa7988d7..61bd80c2d67f8028bdc5a727a13f5e80f654e52a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,6 +20,7 @@ "react/prefer-stateless-function": 0, "no-underscore-dangle": 0, "comma-dangle": 0, - "no-use-before-define": 0 + "no-use-before-define": 0, + "no-console": 0 } } diff --git a/.gitignore b/.gitignore index efed01220e27df0fa7dce8fc44c12ec36f887120..bc44ccaa85ca49ca224346f423c5a0335d0ce9a2 100755 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ ecosystem.config.js Dockerfile .drone.yml dist +.jshintignore +.jshintrc diff --git a/README.md b/README.md index c9376813d8dd0909fc6ea1eb70b5b405567d25bc..18d41ce8960573a992382519712137aeb762d517 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A scalable signaling server for WebRTC using socket.io, NodeJS cluster, and Redi ## What is SignalBuddy? -SignalBuddy is an easy-to-scale signaling solution for WebRTC. SignalBuddy automatically detects and scales across the number of CPU cores in its environment. For instance, if the machine you're testing on has four cores, SignalBuddy will launch a cluster of four processes, each a separate instance of itself, all listening on the same port. Using Redis to store state, peers connected to different worker instances will still be able to broadcast and transmit data to one another. +SignalBuddy is an easy-to-scale signaling solution for WebRTC. SignalBuddy automatically detects and scales across the number of CPU cores in its environment. For instance, if the machine you're testing on has four cores, SignalBuddy will launch a cluster of four processes, each a separate instance of itself, all listening on the same port. Using Redis to store state, peers connected to different worker instances, even on different servers, will still be able to join the same rooms and broadcast data to one another. ## Running @@ -53,7 +53,14 @@ Most likely, you'll want the server to be secure. You can either pass in the pat NODE_ENV=production PRIV_KEY=/etc/example/privKey.pem CERT=/etc/example/cert.pem node dist/server.js ``` -Or you can also add your key/cert paths to the production.json file in the config folder. +Or you can add your key/cert paths to the production.json file in the config folder. + +To pass in the Redis endpoint and port, use REDIS_ENDPOINT and REDIS_PORT: +``` +NODE_ENV=production REDIS_ENDPOINT=localhost REDIS_PORT=6379 node dist/server.js +``` + +As with keys and certs, you can also add Redis endpoint details to your JSON config files. --- diff --git a/config/production.json b/config/production.json index 0ac92cbd1b9016ce42a7b21d2ecb5e1c20a0b386..478e33f4debafa9a7a137b6d2f1fda100dc97223 100755 --- a/config/production.json +++ b/config/production.json @@ -6,6 +6,10 @@ "key": null, "cert": null }, + "redis": { + "endpoint": "localhost", + "port": 6379 + }, "rooms": { "/* maxClients */": "/* maximum number of clients per room. 0 = no limit */", "maxClients": 0 diff --git a/dist/server.js b/dist/server.js index 919a96c8484d4291de673881a4c78064f0553eb0..c8ac1603408c314cd55e6c47a5a22cb5554b8654 100755 --- a/dist/server.js +++ b/dist/server.js @@ -60,6 +60,7 @@ if (_cluster2.default.isMaster) { }; for (var i = 0; i < numProcesses; i += 1) { + console.log('Starting worker ' + (i + 1)); spawn(i); } @@ -96,8 +97,8 @@ if (_cluster2.default.isMaster) { // Create an http(s) server instance to that socket.io can listen to if (_getconfig2.default.server.secure) { server = _https2.default.Server({ - key: _fs2.default.readFileSync(_getconfig2.default.server.key), - cert: _fs2.default.readFileSync(_getconfig2.default.server.cert), + key: _fs2.default.readFileSync(process.env.PRIV_KEY || _getconfig2.default.server.key), + cert: _fs2.default.readFileSync(process.env.CERT || _getconfig2.default.server.cert), passphrase: _getconfig2.default.server.password }, serverHandler); } else { @@ -122,7 +123,6 @@ if (_cluster2.default.isMaster) { if (message !== 'sticky-session:connection') { return; } - // Emulate a connection event on the server by emitting the // event with the connection the master sent us. server.emit('connection', connection); diff --git a/package.json b/package.json index 9493fd5ca362fee436aa5734d7e1651c84c28803..1b6817cc6a8556502871cab0b112fef15290026e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "signalbuddy", - "description": "A scalable, socket.io WebRTC signaling solution for LioWebRTC.", + "description": "A scalable socket.io signaling solution for WebRTC using NodeJS cluster and Redis.", "version": "1.0.0", "dependencies": { "farmhash": "^2.1.0", diff --git a/src/server.js b/src/server.js index a7ca1fe2e7cd830857d7dc0b308aa9648ab32ad9..16c1f4379bbd16712c2cbc7e18c44d10cccace76 100755 --- a/src/server.js +++ b/src/server.js @@ -27,6 +27,7 @@ if (cluster.isMaster) { }; for (let i = 0; i < numProcesses; i += 1) { + console.log(`Starting worker ${i + 1}`); spawn(i); }