PubSub.Client

View as Markdown

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

Example usage:

1import { PubSub } from "@signalwire/js";
2
3const pubSubClient = new PubSub.Client({
4 token: "<your chat token>", // get this from the REST APIs
5});
6
7await pubSubClient.subscribe(["mychannel1", "mychannel2"]);
8
9pubSubClient.on("message", (message) => {
10 // prettier-ignore
11 console.log("Received", message.content,
12 "on", message.channel,
13 "at", message.publishedAt);
14});
15
16await pubSubClient.publish({
17 channel: "mychannel1",
18 content: "hello world",
19});

Constructor

Creates a new PubSub client.

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

Parameters

token
stringRequired

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

Methods

Events