---title: Client---import MethodOff from ../../_common/_method_off.mdx;import MethodOn from ../../_common/_method_on.mdx;import MethodOnce from ../../_common/_method_once.mdx;import MethodRemoveAllListeners from ../../_common/_method_removealllisteners.mdx;## Constructors### constructor• **new Client**(pubSubOptions)Creates a new PubSub client.#### Parameters| Name | Type | Description || :---------------------- | :------- | :----------------------------------------------------------------- || pubSubOptions | Object | - || pubSubOptions.project | string | SignalWire project id, e.g. a10d8a9f-2166-4e82-56ff-118bc3a4840f || pubSubOptions.token | string | SignalWire API token |#### Examplejsimport { PubSub } from @signalwire/realtime-api;const pubSubClient = new PubSub.Client({ project: , token: ,});## Methods### disconnect▸ **disconnect**(): voidDisconnects this client. The client will stop receiving events and you will need to create a new instance if you want to use it again.#### Returnsvoid#### Examplejsclient.disconnect();---### off ---### on ---### once ---### publish▸ **publish**(params): PromisePublish a message into the specified channel.#### Parameters| Name | Type | Description || :--------------- | :---------------------- | :------------------------------------------------------------------------------------------ || params | Object | - || params.channel | string | Channel in which to send the message. || params.content | any | The message to send. This can be any JSON-serializable object. || params.meta? | Record | Metadata associated with the message. There are no requirements on the content of metadata. |#### ReturnsPromise#### ExamplesPublishing a message as a string:jsawait pubSubClient.publish({ channel: my-channel, content: Hello, world.,});Publishing a message as an object:jsawait pubSubClient.publish({ channel: my-channel, content: { field_one: value_one, field_two: value_two, },});---### removeAllListeners ---### subscribe▸ **subscribe**(channels): PromiseList of channels for which you want to receive messages.Note that the subscribe function is idempotent, and calling it again with a different set of channels _will not_ unsubscribe you from the old ones. To unsubscribe, use [unsubscribe](./pubsub-client.mdx#unsubscribe).#### Parameters| Name | Type | Description || :--------- | :--------------------- | :----------------------------------------------------------------------------------------------------- || channels | string \| string[] | The channels to subscribe to, either in the form of a string (for one channel) or an array of strings. |#### ReturnsPromise#### Examplejsconst pubSubClient = new PubSub.Client({ project: , token: ,});await pubSubClient.subscribe(my-channel);await pubSubClient.subscribe([chan-2, chan-3]);---### unsubscribe▸ **unsubscribe**(channels): PromiseList of channels from which you want to unsubscribe.#### Parameters| Name | Type | Description || :--------- | :--------------------- | :--------------------------------------------------------------------------------------------------------- || channels | string \| string[] | The channels to unsubscribe from, either in the form of a string (for one channel) or an array of strings. |#### ReturnsPromise#### Examplejsawait pubSubClient.unsubscribe(my-channel);await pubSubClient.unsubscribe([chan-2, chan-3]);## Events### message• **message**(message)A new message has been received.#### Parameters| Name | Type | Description || :-------- | :------------------------------------------- | :---------------------------------- || message | [PubSubMessage](./pubsub-pubsubmessage.md) | The message that has been received. |