{"id":13483376,"url":"https://github.com/coast-team/netflux","last_synced_at":"2025-04-09T17:20:14.928Z","repository":{"id":40618977,"uuid":"48050309","full_name":"coast-team/netflux","owner":"coast-team","description":"JavaScript client and server side transport API based on WebRTC \u0026 WebSocket","archived":false,"fork":false,"pushed_at":"2022-01-18T21:13:38.000Z","size":12075,"stargazers_count":208,"open_issues_count":5,"forks_count":16,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-04-26T18:47:51.012Z","etag":null,"topics":["isomorphic","middleware","p2p","peer-network","universal-javascript","webrtc","websockets"],"latest_commit_sha":null,"homepage":"https://coast-team.github.io/netflux","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coast-team.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-15T15:10:27.000Z","updated_at":"2024-04-11T17:03:26.000Z","dependencies_parsed_at":"2022-07-14T04:00:44.577Z","dependency_job_id":null,"html_url":"https://github.com/coast-team/netflux","commit_stats":null,"previous_names":[],"tags_count":85,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coast-team%2Fnetflux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coast-team%2Fnetflux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coast-team%2Fnetflux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coast-team%2Fnetflux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coast-team","download_url":"https://codeload.github.com/coast-team/netflux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248074922,"owners_count":21043490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["isomorphic","middleware","p2p","peer-network","universal-javascript","webrtc","websockets"],"created_at":"2024-07-31T17:01:10.571Z","updated_at":"2025-04-09T17:20:14.900Z","avatar_url":"https://github.com/coast-team.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Libraries","Developer Resources"],"sub_categories":["JavaScript Libraries"],"readme":"# Netflux\n\n![Netflux logo][logo]\n\nIsomorphic Javascript **peer to peer** transport API for client and server.\n\nSecure and fault tolerant full mesh peer to peer network based on **RTCDataChannel** and **WebSocket**.\n\nSend/receive **String** and **Uint8Array** data types.\n\nDocumentation: \u003chttps://coast-team.github.io/netflux\u003e\n\n[![version](https://img.shields.io/npm/v/netflux.svg?style=flat-square)](https://www.npmjs.com/package/netflux)\n[![travis](https://travis-ci.org/coast-team/netflux.svg?branch=master)](https://travis-ci.org/coast-team/netflux)\n\n[![codeclimate](https://codeclimate.com/github/coast-team/netflux/badges/gpa.svg)](https://codeclimate.com/github/coast-team/netflux)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/65c5d6308e7e58edd7b0/test_coverage)](https://codeclimate.com/github/coast-team/netflux/test_coverage)\n[![documentation](https://coast-team.github.io/netflux/badge.svg)](https://coast-team.github.io/netflux)\n\n[![Conventional Changelog](https://img.shields.io/badge/changelog-conventional-brightgreen.svg?)](http://conventional-changelog.github.io)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)\n[![gitter](https://img.shields.io/badge/GITTER-join%20chat-green.svg?style=flat-square)](https://gitter.im/coast-team/netflux?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n![Netflux example][netflux_example]\n\n## Features\n\n- Peer to peer full mesh network tolerant to connection failures.\n- Same API for clients (Chrome, Firefox) and servers (NodeJS).\n- Send private or broadcast messages with [String][string], [Uint8Array][uint8array] data types.\n- Send large amounts of data (over the limit of ~16kb used in RTCDataChannel).\n- Automatic rejoin the group when connection lost.\n- Hide the connection nature ( [WebSocket][websocket] or [RTCDataChannel][rtcdatachannel]) from API consumer.\n- All connections are encrypted.\n- Full control over WebRTC servers: Signaling, STUN and TURN.\n  - Deploy your own Signaling server ([Sigver][sigver]) or use the one provided by default.\n  - Configure STUN and TURN servers.\n- Small Signaling server payload.\n- Signaling server is only used to establish connection between two peers, no user data is passing through it.\n- TypeScript declaration files are included.\n- Simple and familiar API usage.\n- Multiple bundles to suit your workflow:\n  - For NodeJS\n    - `dist/netflux.node.es5.cjs.js` commonjs format, es5 code (see _package.json#main_).\n    - `dist/netflux.node.es5.esm.js` ES module format, es5 code (see _package.json#module_).\n  - For browsers\n    - `dist/netflux.browser.es5.umd.js` UMD format, es5 code\n    - `dist/netflux.browser.es5.esm.js` ES module format, es5 code (see _package.json#browser_).\n    - `dist/netflux.browser.es2015.esm.js` ES module format, es2015 code (see _package.json#es2015_).\n    - `dist/netflux.browser.esnext.esm.js` ES module format, esnext code (see _package.json#esnext_).\n\n## Install\n\n```shell\nnpm install netflux\n```\n\n3 peer dependencies to be installed in some cases:\n\n- `rxjs` is necessary for both NodeJS and browsers if you want to take advantage of EcmaScript modules, tree-shaking etc. Otherwise it is already included into `dist/netflux.browser.es5.umd.js` and `dist/netflux.node.es5.cjs.js` bundles.\n\n```shell\nnpm install rxjs\n```\n\n- `uws` and `text-encoding` if you target NodeJS (developing a bot):\n\n```shell\nnpm install uws text-encoding\n```\n\n**Why peer dependencies?**\n\n- Reduce the installation size by omitting unused dependencies.\n- Take advantage of new standards and techniques: EcmaScript modules, bundle tools like Webpack, Rollup etc.\n\n## Usage\n\nHere is a basic usage example for client and server (checkout the [documenation](https://coast-team.github.io/netflux) for more details).\n\n\u003e 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.\n\n### Client example\n\n```javascript\nimport { WebGroup, WebGroupState } from 'netflux'\n\n// Create instance and set callbacks\nconst wg = new WebGroup()\n\nwg.onMemberJoin = (id) =\u003e {\n  console.log(`Member ${id} has joined. Current members list is: `, wg.members)\n  // Say hello to the new peer\n  wg.sendTo(id, 'Hello, my name is Bob')\n}\n\nwg.onMemberLeave = (id) =\u003e {\n  console.log(`Member ${id} has left. Remained members are: `, wg.members)\n}\n\nwg.onMessage = (id, data) =\u003e {\n  console.log(`Message from ${id} group member`, data)\n}\n\nwg.onStateChange = (state) =\u003e {\n  console.log('The new Group state is ', state)\n  switch (state) {\n    case WebGroupState.JOINING:\n      // Do something\n      break\n    case WebGroupState.JOINED:\n      // Do something... for example invite a bot...\n      wg.invite('BOT_SERVER_WEB_SOCKET_URL')\n      // Or send message to all peers\n      wg.send('Hello everybody. I have just joined the group.')\n      break\n    case WebGroupState.LEFT:\n      // wg.key === ''\n      // wg.id === 0\n      // wg.myId === 0\n      // wg.members === []\n      // the current wg object is at the same state as if it was instantiated via new WebGroup(...), hence\n      // it can be reused to join another group for example.\n      // Do something...\n      break\n  }\n}\n\n// Join the group\nwg.join('MY_UNIQUE_KEY_FOR_THE_GROUP')\n```\n\n### Bot example\n\n```javascript\nimport { Bot, WebGroupState } from 'netflux'\nconst http = require('http') // https is also possible\nconst server = http.createServer()\n\nconst bot = new Bot({\n  server: server,\n  webGroupOptions: {\n    // Any WebGroup options like for a client\n  },\n})\n\nbot.onWebGroup = (wg) =\u003e {\n  console.log('The current state is JOINING: ', wg.state === WebGroupState.JOINING)\n  // New instance of a WebGroup (Someone has invited this bot).\n  // See example above for client as it is the same API.\n}\n\nserver.listen(BOT_PORT, _BOT_HOST)\n// A client may invite this bot with the following URL: 'ws://BOT_HOST:BOT_PORT'\n```\n\n## Demo\n\nNetflux used as a transport layer for Multi User Text Editor ([MUTE repo](https://github.com/coast-team/mute)) developed by our team. The demo version is available on: \u003chttps://coedit.re\u003e.\n\n[websocket]: https://developer.mozilla.org/en/docs/Web/API/WebSocket\n[rtcdatachannel]: https://developer.mozilla.org/en/docs/Web/API/RTCDataChannel\n[string]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String\n[uint8array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\n[sigver]: https://github.com/coast-team/sigver\n[logo]: manual/asset/logo_760px.png\n[netflux_example]: manual/asset/example.png\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoast-team%2Fnetflux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoast-team%2Fnetflux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoast-team%2Fnetflux/lists"}