RIF Communications PubSub
![](https://img.shields.io/badge/Node.js-%3E%3D10.0.0-orange.svg?style=flat-square)
Library for creating a PubSub room with libp2p
This project extends the ipfs-pubsub-room, rewriting it in typescript and adding libp2p node.
Table of Contents
Install
npm
> npm install @rsksmart/rif-communications-pubsub
WARNING: This package still have not been released!
Usage
Example of usage:
import { Room, createLibP2P } from '@rsksmart/rif-communications-pubsub'
const libp2p = await createLibP2P()
const room = createRoom(libp2p, 'my_topic')
room.on('peer joined', (peer: string) => {
console.log('Peer joined the room ', peer)
})
room.on('peer left', (peer: string) => {
console.log('Peer left the room', peer)
})
room.on('message', ({from, data}: {from: string, data: Buffer}) => {
console.log('New message from ', peer, ' content ', data)
})
room.on('unsubscribed', () => {
console.log('Unsubscribed from the room room')
})
API
const room = createRoom(topic)
room.leave()
async room.broadcast(message: string | buffer)
room.peerId
room.peers
room.hasPeer(cid: string)
room.on('peer joined', (cid: string) => {})
room.on('peer left', (cid: string) => {})
room.on('message', (message: {from: string, data: Buffer}) => {})
room.on('unsubscribed', () => {})
License
MIT