https://github.com/seriousben/socket.io-raft
Work-In-Progress - Adapter to enable broadcasting of events to multiple separate socket.io server nodes without third-party dependencies.
https://github.com/seriousben/socket.io-raft
raft raft-consensus-algorithm socket-io socket-io-adapter websocket
Last synced: 3 months ago
JSON representation
Work-In-Progress - Adapter to enable broadcasting of events to multiple separate socket.io server nodes without third-party dependencies.
- Host: GitHub
- URL: https://github.com/seriousben/socket.io-raft
- Owner: seriousben
- License: mit
- Created: 2018-12-02T22:15:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-02T22:45:42.000Z (over 6 years ago)
- Last Synced: 2024-04-14T13:57:18.829Z (about 1 year ago)
- Topics: raft, raft-consensus-algorithm, socket-io, socket-io-adapter, websocket
- Language: JavaScript
- Homepage:
- Size: 60.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socket.io-raft
[](http://badge.fury.io/js/socket.io-raft)
Adapter to enable broadcasting of events to multiple separate socket.io server nodes without third-party dependencies.
This adapter leverages the [Raft](https://ramcloud.stanford.edu/raft.pdf) consensus algorithm to broadcast messages around.
**No need to manage a Redis cluster only for websockets!**
## How to use
```js
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://localhost:8001', 'tcp://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:
```js
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
- [x] Broadcast support
- [ ] Room support
- [ ] Robustness
- [ ] Persistent rooms leveraging the Raft log