PubSub.Client

View as MarkdownOpen in Claude

You can use the Client object to build a messaging system into the browser.

Example usage:

import { PubSub } from "@signalwire/js";
const pubSubClient = new PubSub.Client({
token: "<your chat token>", // get this from the REST APIs
});
await pubSubClient.subscribe(["mychannel1", "mychannel2"]);
pubSubClient.on("message", (message) => {
// prettier-ignore
console.log("Received", message.content,
"on", message.channel,
"at", message.publishedAt);
});
await pubSubClient.publish({
channel: "mychannel1",
content: "hello world",
});

Constructor

Creates a new PubSub client.

import { PubSub } from "@signalwire/js";
const pubSubClient = new PubSub.Client({
token: "<your chat token>"
});

Parameters

token
stringRequired

SignalWire Chat token that can be obtained from the REST APIs.

Methods

Events