*** id: 127a92fa-f4ef-452b-aaec-c1e321bf6f05 title: PubSub.Client sidebar-title: Client slug: /js/reference/pubsub/client max-toc-depth: 3 ---------------- You can use the Client object to build a messaging system into the browser. Example usage: ```js import { PubSub } from "@signalwire/js"; const pubSubClient = new PubSub.Client({ 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. ```js import { PubSub } from "@signalwire/js"; const pubSubClient = new PubSub.Client({ token: "" }); ``` ### Parameters SignalWire Chat token that can be obtained from the [REST APIs](/docs/apis/chat/tokens/create-chat-token). ## Methods Disconnect the client Get channels allowed by the token Publish a message to a channel Subscribe to channels Unsubscribe from channels Replace the client token Subscribe to an event Subscribe to an event once Unsubscribe from an event Remove all event listeners ## Events Events emitted by the PubSub.Client class.