*** id: e591d883-8425-4997-b2e1-4518d6c0d6db title: 'on' slug: /js/reference/pubsub/client/on description: on method for the PubSub.Client class. max-toc-depth: 3 ---------------- ### on * **on**(`event`, `fn`) Attaches an event handler to the specified event. #### Parameters | Name | Type | Description | | :------ | :------- | :--------------------------------------------------------------------------------------------------- | | `event` | `string` | Name of the event. See the list of [events](/docs/browser-sdk/v3/js/reference/pubsub/client/events). | | `fn` | Function | An event handler. | #### Example In the below example, we are listening for the `call.state` event and logging the current call state to the console. This means this will be triggered every time the call state changes. ```js call.on("call.state", (call) => { console.log("call state changed:", call.state); }); ```