Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ipfs-pubsub-room

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-pubsub-room

IPFS pub-sub room

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
63
decreased by-52.99%
Maintainers
1
Weekly downloads
 
Created
Source

ipfs-pubsub-room

made by Protocol Labs Freenode

Build Status

Creates a room based on an IPFS pub-sub channel. Emits membership events, listens for messages, broadcast and direct messeges to peers.

(Demo video)

js-ipfs

This package has been tested with js-ipfs version 0.28.0.

Install

$ npm install ipfs-pubsub-room

Use

const Room = require('ipfs-pubsub-room')
const IPFS = require('ipfs')
const ipfs = new IPFS({
  EXPERIMENTAL: {
    pubsub: true
  },
  config: {
    Addresses: {
      Swarm: [
        '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
      ]
    }
  }
})

// IPFS node is ready, so we can start using ipfs-pubsub-room
ipfs.on('ready', () => {
  const room = Room(ipfs, 'room-name')

  room.on('peer joined', (peer) => {
    console.log('Peer joined the room', peer)
  })

  room.on('peer left', (peer) => {
    console.log('Peer left...', peer)
  })

  // now started to listen to room
  room.on('subscribed', () => {
    console.log('Now connected!')
  })
})

API

Room (ipfs:IPFS, roomName:string, options:object)

  • ipfs: IPFS object. Must have pubsub activated
  • roomName: string, global identifier for the room
  • options: object:
    • pollInterval: interval for polling the pubsub peers, in ms. Defaults to 1000.
const room = Room(ipfs, 'some-room-name')

room.broadcast(message)

Broacasts message (string or buffer).

room.sendTo(peer, message)

Sends message (string or buffer) to peer.

room.leave()

Leaves room, stopping everything.

room.getPeers()

Returns an array of peer identifiers (strings).

room.hasPeer(peer)

Returns a boolean indicating if the given peer is present in the room.

room.on('message', (message) => {})

Listens for messages. A message is an object containing the following properties:

  • from (string): peer id
  • data (Buffer): message content

room.on('peer joined', (peer) => {})

Once a peer has joined the room.

room.on('peer left', (peer) => {})

Once a peer has left the room.

room.on('subscribed',() => {})

Once your program has subscribed the topic and announced through IPFS pubsub.

License

ISC

Keywords

FAQs

Package last updated on 03 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc