For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
ReferenceGuidesClick-to-Call
ReferenceGuidesClick-to-Call
  • Core
    • Overview
  • SignalWire Client
    • Overview
    • Notifications
    • Client
    • Utility functions
  • Video
    • Overview
    • LocalOverlay
    • RoomSession
    • RoomSessionDevice
    • RoomSessionPlayback
    • RoomSessionRecording
    • RoomSessionScreenShare
    • RoomSessionStream
    • RoomDevice
    • RoomScreenShare
  • Chat
    • Overview
    • Client
    • ChatMember
    • ChatMemberEntity
    • ChatMessage
    • ChatMessageEntity
  • PubSub
    • Overview
    • Client
      • Events
    • PubSubMessage
  • WebRTC
    • Overview
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Constructor
  • Parameters
  • Methods
  • Events
PubSub

PubSub.Client

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

Events

Next
Built with

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

disconnect

Disconnect the client

getAllowedChannels

Get channels allowed by the token

publish

Publish a message to a channel

subscribe

Subscribe to channels

unsubscribe

Unsubscribe from channels

updateToken

Replace the client token

on

Subscribe to an event

once

Subscribe to an event once

off

Unsubscribe from an event

removeAllListeners

Remove all event listeners

Events

Events

Events emitted by the PubSub.Client class.