@xmpp-plugins/roster

1.2.0 • Public • Published

roster

roster management for @xmpp/client.

Supports Node.js and browsers.

Roster push is currently not supported.

Install

npm install @xmpp-plugins/roster

Usage

import { client, xml } from "@xmpp/client"
import setupRoster from "@xmpp-plugins/roster"

const xmpp = client({service: 'wss://xmpp.example.com'})
const roster = setupRoster(xmpp)

roster.on('set', ({item, version}) => {
  console.log(`Roster version ${version} received`, item)
})

const { version, items } = await roster.get()
console.log(`Current roster version is ${version}`)

Get

Retrieve the roster.

version is optional and refers to roster version.

roster.get(version).then(roster => {
  if (!roster) {
    // the roster hasn't changed since last version
    return
  }

  const { version, items } = roster
  console.log(version, roster)
})

Set

Add or update a roster entry.

roster.set({jid: 'foo@bar', name: 'Foo Bar'}).then(() => {
  console.log('success')
})

Remove

Remove a roster entry.

roster.remove(jid).then(() => {
  console.log('success')
})

Set event

Emitted when a roster entry was added or updated.

roster.on('set', ({item, version}) => {
  console.log(item)
  console.log(version)
})

Remove event

Emitted when a roster entry was removed.

roster.on('remove', ({jid, version}) => {
  console.log(jid.toString(), 'removed')
  console.log(version)
})

References

RFC-6121: Managing the Roster

Readme

Keywords

Package Sidebar

Install

npm i @xmpp-plugins/roster

Weekly Downloads

5

Version

1.2.0

License

ISC

Unpacked Size

102 kB

Total Files

9

Last publish

Collaborators

  • ggozad
  • wichert