Skip to content

A scalable signaling solution for WebRTC using socket.io, NodeJS cluster, and Redis.

License

Notifications You must be signed in to change notification settings

lazorfuzz/signalbuddy

Repository files navigation

SignalBuddy

A scalable signaling server for WebRTC using socket.io, NodeJS cluster, and Redis. Made for use with liowebrtc and react-liowebrtc.

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, even on different servers, will still be able to join the same rooms and broadcast data to one another.

What is a signaling server?

WebRTC needs to be facilitated with signaling; a service that acts as a matchmaker for peers before they establish direct video/audio/data channels. Signaling can be done in any way, e.g. via good old fashioned carrier pigeons. Signaling services only need to fulfill the absolute minimal role of matchmaking peers, however SignalBuddy comes with some extra perks, like the ability to segment peers into rooms, and STUN/TURN server dispensing.

Startup Guide

First, install and start Redis. Once Redis is listening on the default port (6379), cd into the signalbuddy project.

After cd'ing into the signalbuddy project:

npm install

Build the project:

npm run build

Start in dev mode:

npm run start

If all goes well, your console should display a message like this:

Listening at http://localhost:8888/

If you open the URL in a web browser, you should see an output displaying which worker process you're currently connected to. Exempli gratia:

worker: 4

Production

To run in production mode:

NODE_ENV=production node dist/server.js

Most likely, you'll want the server to be secured with SSL. You can either pass in the paths to your key/cert through the environment variables PRIV_KEY and CERT:

NODE_ENV=production PRIV_KEY=/etc/example/privKey.pem CERT=/etc/example/cert.pem node dist/server.js

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.

Running with pm2

cd dist
NODE_ENV=production pm2 start server.js --name signalbuddy

Running with Docker

docker build -t signalbuddy .
docker run -d --restart=on_failure -p 8888:8888 -e REDIS_ENDPOINT=localhost -e REDIS_PORT=6379 signalbuddy

About

A scalable signaling solution for WebRTC using socket.io, NodeJS cluster, and Redis.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published