Back to the full WebSockets listWhat are WebSockets?


GitHubStarsLast commitProject createdClosed vsOpen issues
5 years ago
8 years ago
56 / 5


Netflux logo

Isomorphic Javascript peer to peer transport API for client and server.

Secure and fault tolerant full mesh peer to peer network based on RTCDataChannel and WebSocket.

Send/receive String and Uint8Array data types.


version travis

codeclimate Test Coverage documentation

Conventional Changelog semantic-release gitter

Netflux example



npm install netflux

3 peer dependencies to be installed in some cases:

npm install rxjs
npm install uws text-encoding

Why peer dependencies?


Here is a basic usage example for client and server (checkout the documenation for more details).

Bot server is not mandatory. The group may completely be composed of clients only, as well as be composed of servers only or may also be mixed.

Client example

import { WebGroup, WebGroupState } from 'netflux'

// Create instance and set callbacks
const wg = new WebGroup()

wg.onMemberJoin = (id) => {
  console.log(`Member ${id} has joined. Current members list is: `, wg.members)
  // Say hello to the new peer
  wg.sendTo(id, 'Hello, my name is Bob')

wg.onMemberLeave = (id) => {
  console.log(`Member ${id} has left. Remained members are: `, wg.members)

wg.onMessage = (id, data) => {
  console.log(`Message from ${id} group member`, data)

wg.onStateChange = (state) => {
  console.log('The new Group state is ', state)
  switch (state) {
    case WebGroupState.JOINING:
      // Do something
    case WebGroupState.JOINED:
      // Do something... for example invite a bot...
      // Or send message to all peers
      wg.send('Hello everybody. I have just joined the group.')
    case WebGroupState.LEFT:
      // wg.key === ''
      // === 0
      // wg.myId === 0
      // wg.members === []
      // the current wg object is at the same state as if it was instantiated via new WebGroup(...), hence
      // it can be reused to join another group for example.
      // Do something...

// Join the group

Bot example

import { Bot, WebGroupState } from 'netflux'
const http = require('http') // https is also possible
const server = http.createServer()

const bot = new Bot({
  server: server,
  webGroupOptions: {
    // Any WebGroup options like for a client

bot.onWebGroup = (wg) => {
  console.log('The current state is JOINING: ', wg.state === WebGroupState.JOINING)
  // New instance of a WebGroup (Someone has invited this bot).
  // See example above for client as it is the same API.

server.listen(BOT_PORT, _BOT_HOST)
// A client may invite this bot with the following URL: 'ws://BOT_HOST:BOT_PORT'


Netflux used as a transport layer for Multi User Text Editor (MUTE repo) developed by our team. The demo version is available on: