# ipfs-pubsub-room

> IPFS pub-sub room

Latest version **3.0.0** (published 2022-06-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install ipfs-pubsub-room
pnpm add ipfs-pubsub-room
yarn add ipfs-pubsub-room
bun add ipfs-pubsub-room
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2022-06-23 |
| First published | 2017-06-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 38.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 287 |
| Author | Pedro Teixeira |
| Maintainers | achingbrain, pgte |
| Keywords | ipfs, pubsub, p2p, room, broadcast |

## Links

- npm: https://www.npmjs.com/package/ipfs-pubsub-room
- Repository: https://github.com/ipfs-shipyard/ipfs-pubsub-room
- Homepage: https://github.com/ipfs-shipyard/ipfs-pubsub-room#readme
- Issues: https://github.com/ipfs-shipyard/ipfs-pubsub-room/issues
- npm.io page: https://npm.io/package/ipfs-pubsub-room

## Dependencies (4)

- [it-pipe](https://npm.io/package/it-pipe.md) ^2.0.3
- [hyperdiff](https://npm.io/package/hyperdiff.md) ^2.0.5
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [lodash.clonedeep](https://npm.io/package/lodash.clonedeep.md) ^4.5.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2022-06-23
- 2.0.2 — 2022-06-23
- 2.0.1 — 2020-01-28
- 2.0.0 — 2020-01-24
- 1.4.1 — 2019-01-25
- 1.4.0 — 2018-07-16
- 1.3.0 — 2018-06-01
- 1.2.1 — 2018-05-03
- 1.2.0 — 2018-03-12
- 1.1.5 — 2017-12-30
- 1.1.4 — 2017-12-15
- 1.1.3 — 2017-12-12
- 1.1.2 — 2017-12-07
- 1.1.1 — 2017-12-07
- 1.1.0 — 2017-12-05
- … 17 more at https://npm.io/package/ipfs-pubsub-room/versions

## README

# ipfs-pubsub-room

[![made by Protocol Labs](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)
[![Freenode](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Build Status](https://travis-ci.com/ipfs-shipyard/ipfs-pubsub-room.svg?branch=master)](https://travis-ci.com/ipfs-shipyard/ipfs-pubsub-room)

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

([Demo video](https://t.co/HNYQGE4D4P))

## Install

```bash
$ npm install ipfs-pubsub-room
```

## Use

Creating a pubsub room from a LibP2P node

```js
const Room = require('ipfs-pubsub-room')
const Libp2p = require('libp2p')

const libp2p = new Libp2p({ ... })
await libp2p.start()

// libp2p node is ready, so we can start using ipfs-pubsub-room
const room = Room(libp2p, 'room-name')
```

Creating a pubsub room from an IPFS node

```js
const Room = require('ipfs-pubsub-room')
const IPFS = require('ipfs')

const ipfs = await IPFS.create({ ... })
const room = Room(ipfs, 'room-name')
```

Once we have a room we can listen for messages

```js
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 (libp2p:LibP2P, roomName:string, options:object)

* `libp2p`: LibP2P node. 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.

```js
const room = Room(libp2p, 'some-room-name')
```

## room.broadcast(message)

Broacasts message (string or Uint8Array).

## room.sendTo(cid, message)

Sends message (string or Uint8Array) to peer.

## async room.leave()

Leaves room, stopping everything.

## room.getPeers()

Returns an array of peer identifiers (strings).

## room.hasPeer(cid)

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` (Uint8Array): message content

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

Once a peer has joined the room.

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

Once a peer has left the room.

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

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

## License

ISC

---
_Source: https://npm.io/package/ipfs-pubsub-room · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
