@cfware/peer-cluster
Websocket all-to-all connectivity cluster.
Install @cfware/peer-cluster
This module requires node.js 12 or above with support for ESM modules. This
has only been tested/used with esm
.
npm i --save esm @cfware/peer-cluster
Usage
import {createServer} from 'http';
import pEvent from 'p-event';
import {PeerCluster} from '@cfware/peer-cluster';
(async () => {
const httpd = createServer();
httpd.listen(0);
await pEvent(httpd, 'listening');
const peerCluster = new PeerCluster({
peerId: 'server1',
origin: `ws://localhost:${httpd.address().port}/`,
respond404: true
});
httpd.on('upgrade', (req, sock, head) => {
cluster.tryUpgrade(req, sock, head);
});
})();
Running tests
Tests are provided by xo and ava.
npm install
npm test