npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@xmpp/component

v0.14.0

Published

XMPP component for JavaScript

Downloads

2,315

Readme

component

Much like a client, a component is an entity that connects to an XMPP server. However components are granted special permissions. If you'd like to extend an XMPP server with additional features a component is a good choice.

See XEP-0114: Jabber Component Protocol for details.

@xmpp/component package includes a minimal set of features to connect /authenticate securely and reliably.

Install

npm install @xmpp/component @xmpp/debug

Example

import { component, xml, jid } from "@xmpp/component";
import debug from "@xmpp/debug";

const xmpp = component({
  service: "xmpp://localhost:5347",
  domain: "component.localhost",
  password: "mysecretcomponentpassword",
});

debug(xmpp, true);

xmpp.on("error", (err) => {
  console.error(err);
});

xmpp.on("offline", () => {
  console.log("offline");
});

xmpp.once("stanza", async (stanza) => {
  if (stanza.is("message")) {
    await xmpp.stop();
  }
});

xmpp.on("online", async (address) => {
  console.log("online as", address.toString());

  // Sends a chat message to itself
  const message = xml(
    "message",
    { type: "chat", to: address },
    xml("body", {}, "hello world"),
  );
  await xmpp.send(message);
});

await xmpp.start();

xml

See xml package

jid

See jid package

component

  • options <Object>

    • service <string> The service to connect to, accepts an URI. eg. xmpp://localhost:5347
    • domain <string> Domain of the component. eg. component.localhost
    • password <string> Password to use to authenticate with the service.
    • timeout <number Number of miliseconds to wait before timing out (default is 2000)

Returns an xmpp object.

xmpp

xmpp is an instance of EventEmitter.

status

online indicates that xmpp is authenticated and addressable. It is emitted every time there is a successfull (re)connection.

offline indicates that xmpp disconnected and no automatic attempt to reconnect will happen (after calling xmpp.stop()).

Additional status:

  • connecting: Socket is connecting
  • connect: Socket is connected
  • opening: Stream is opening
  • open: Stream is open
  • closing: Stream is closing
  • close: Stream is closed
  • disconnecting: Socket is disconnecting
  • disconnect: Socket is disconnected

You can read the current status using the status property.

const isOnline = xmpp.status === "online";

You can listen for status change using the status event.

Event status

Emitted when the status changes.

xmpp.on("status", (status) => {
  console.debug(status);
});

Event error

Emitted when an error occurs. For connection errors, xmpp will reconnect on its own using @xmpp/reconnect however a listener MUST be attached to avoid uncaught exceptions.

  • <Error>
xmpp.on("error", (error) => {
  console.error(error);
});

Event stanza

Emitted when a stanza is received and parsed.

// Simple echo bot example
xmpp.on("stanza", (stanza) => {
  console.log(stanza.toString());
  if (!stanza.is("message")) return;

  const { to, from } = stanza.attrs;
  stanza.attrs.from = to;
  stanza.attrs.to = from;
  xmpp.send(stanza);
});

Event online

Emitted when connected, authenticated and ready to receive/send stanzas.

xmpp.on("online", (address) => {
  console.log("online as", address.toString());
});

Event offline

Emitted when the connection is closed an no further attempt to reconnect will happen, usually after xmpp.stop().

xmpp.on("offline", () => {
  console.log("offline");
});

start

Starts the connection. Attempts to reconnect will automatically happen if it cannot connect or gets disconnected.

xmpp.on("online", (address) => {
  console.log("online", address.toString());
});
await xmpp.start();

Returns a promise that resolves if the first attempt succeed or rejects if the first attempt fails.

stop

Stops the connection and prevent any further auto reconnect.

xmpp.on("offline", () => {
  console.log("offline");
});
await xmpp.stop();

disconnect

Like stop but will not prevent auto reconnect.

xmpp.on("disconnect", () => {
  console.log("disconnect");
});
await xmpp.disconnect();

Returns a promise that resolves once the stream closes and the socket disconnects.

send

Sends a stanza.

await xmpp.send(xml("presence"));

Returns a promise that resolves once the stanza is serialized and written to the socket or rejects if any of those fails.

sendMany

Sends multiple stanzas.

Here is an example sending the same text message to multiple recipients.

const message = "Hello";
const recipients = ["[email protected]", "[email protected]"];
const stanzas = recipients.map((address) =>
  xml("message", { to: address, type: "chat" }, xml("body", null, message)),
);
await xmpp.sendMany(stanzas);

Returns a promise that resolves once all the stanzas have been sent.

If you need to send a stanza to multiple recipients we recommend using Extended Stanza Addressing instead.

xmpp.reconnect

See @xmpp/reconnect.