Skip to content

Work-In-Progress - Adapter to enable broadcasting of events to multiple separate socket.io server nodes without third-party dependencies.

License

Notifications You must be signed in to change notification settings

seriousben/socket.io-raft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

socket.io-raft

NPM version

Adapter to enable broadcasting of events to multiple separate socket.io server nodes without third-party dependencies.

This adapter leverages the Raft consensus algorithm to broadcast messages around.

No need to manage a Redis cluster only for websockets!

How to use

const io = require('socket.io')(3000);
const raftAdapter = require('socket.io-raft');
// Setup a three node raft cluster (localhost:8000 to localhost:8002)
io.adapter(raftAdapter({ port: 8000, peers: ['tcp:https://localhost:8001', 'tcp:https://localhost:8002'] }));

By running socket.io with the socket.io-raft adapter you can run multiple socket.io instances in different processes or servers that can all broadcast and emit events to and from each other.

So any of the following commands:

io.emit('hello', 'to all clients');
io.to('room42').emit('hello', "to all clients in 'room42' room");

io.on('connection', (socket) => {
  socket.broadcast.emit('hello', 'to all clients except sender');
  socket.to('room42').emit('hello', "to all clients in 'room42' room except sender");
});

will properly be broadcast to the clients using the Raft Concensus protocol.

API

To be documented.

TODO

  • Broadcast support
  • Room support
  • Robustness
  • Persistent rooms leveraging the Raft log

About

Work-In-Progress - Adapter to enable broadcasting of events to multiple separate socket.io server nodes without third-party dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published