From ae4920fc4932165388dd37643313c2d46e13ca9a Mon Sep 17 00:00:00 2001 From: lazorfuzz <leontosy@gmail.com> Date: Wed, 26 Sep 2018 19:10:06 -0700 Subject: [PATCH] log workers started --- .eslintrc | 3 ++- .gitignore | 2 ++ README.md | 11 +++++++++-- config/production.json | 4 ++++ dist/server.js | 6 +++--- package.json | 2 +- src/server.js | 1 + 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7b33fc8..61bd80c 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 efed012..bc44cca 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 c937681..18d41ce 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 0ac92cb..478e33f 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 919a96c..c8ac160 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 9493fd5..1b6817c 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 a7ca1fe..16c1f43 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); } -- GitLab