p2p-broadcast

    0.5.1 • Public • Published

    p2p-broadcast

    Simple P2P message broadcasting

    Install

    npm install p2p-broadcast
    

    Usage

    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

    import { Node } from 'p2p-broadcast'
     
    const seedHosts = ['localhost:6000']
     
    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' }

    const onConnect = ({ peer }) => console.log(Connected to ${peer.node.host})

    Network Topology

    New nodes join the network to form a partial mesh network topology.

    Keywords

    none

    Install

    npm i p2p-broadcast

    DownloadsWeekly Downloads

    12

    Version

    0.5.1

    License

    MIT

    Unpacked Size

    12.2 kB

    Total Files

    8

    Last publish

    Collaborators

    • will123195