---
source_url: https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/watch
title: Watch channels
updated_at: 2026-06-24T11:03:50.851Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Watch channels

Use `onMessageReceived()` to receive messages on a channel without [joining](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/join) as a member. The method subscribes to a [message event listener](https://www.pubnub.com/docs/sdks/javascript/api-reference/configuration#event-listeners) and returns a function to disconnect.

:::warning Deprecated
`connect()` is deprecated as of chat-1-0-0. Use `onMessageReceived()` instead.
:::

##### Under the hood

`onMessageReceived()` calls Pub/Sub API and the JavaScript SDK [subscribe()](https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe#subscribe) and [unsubscribe()](https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe#unsubscribe) methods.

### Method signature

`onMessageReceived()` accepts a callback function as an argument. The Chat SDK invokes this callback whenever someone sends a message on the given channel. This function takes a single argument of a [Message object](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/message).

This method takes the following parameters:

```ts
channel.onMessageReceived(
    callback: (message: Message) => void
): () => void
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| callback | n/a | Yes |  | Callback function passed as a parameter. It defines the custom behavior to be executed whenever someone sends a message on the given channel. |
| > message | Message | Yes |  | Any [Message object](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/message) received on this channel. |

#### Output

| Type | Description |
| --- | --- |
| `() => void` | Function you can call to disconnect (unsubscribe) from the channel and stop receiving `message` events. |

### Sample code

Start receiving messages on the `support` channel.

```ts
// reference the "channel" object
const channel = await chat.getChannel("support")
// invoke the "onMessageReceived()" method
channel.onMessageReceived((message: Message) => {
    console.log(
        "This is my first message on this channel! Nice to meet you all!", message.content.text)
})
```

### Other examples

Stop receiving messages on the `support` channel.

```ts
const channel = await chat.getChannel("support")
const disconnect = channel.onMessageReceived(/* handle message callback */)
// after some time...
disconnect()
```