Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/will123195/p2p-broadcast
Simple P2P message broadcasting
https://github.com/will123195/p2p-broadcast
Last synced: about 2 months ago
JSON representation
Simple P2P message broadcasting
- Host: GitHub
- URL: https://github.com/will123195/p2p-broadcast
- Owner: will123195
- Created: 2017-09-20T03:33:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-25T04:26:37.000Z (over 2 years ago)
- Last Synced: 2024-10-06T08:41:47.458Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 5
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# p2p-broadcast
Simple P2P message broadcasting
## Install
```
npm install p2p-broadcast
```## Usage
```js
const node = new Node({
port: 6000,
seedHosts: ['example.com:1234'],
minPeers: 3,
maxPeers: 10,
debug: console.log,
validate: message => {} // will ignore message if error is thrown
})
```All options are optional.
## Example
```js
import { Node } from 'p2p-broadcast'const seedHosts = ['localhost:6000']
const onConnect = ({ peer }) => console.log(`Connected to ${peer.node.host}`)const a = new Node({ port: 6000 })
const b = new Node({ seedHosts })
const c = new Node({ port: 6001, seedHosts, onConnect })const onBeep = n => ({ id, name, data, peer, hops }) => {
console.log(n, name, data)
}a.on('beep', onBeep('a'))
b.on('beep', onBeep('b'))
c.on('beep', onBeep('c'))c.broadcast('beep', { hello: 'world' })
// --- output ---
// a beep { hello: 'world' }
// b beep { hello: 'world' }
```## Network Topology
New nodes join the network to form a [partial mesh network topology](https://en.wikipedia.org/wiki/Network_topology#Mesh).