> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Real-time Events

> Subscribe to subchannel topics for live chat thread updates.

Chat real-time event subscriptions keep a thread's live data moving while the user is viewing it. For the current SDK surface, the public chat topic documented here is the subchannel topic.

<Info>
  Conversation and community channel members receive many chat updates through normal SDK live objects and collections. Use a subchannel topic when the screen needs explicit realtime delivery for a specific message thread.
</Info>

## Platform Surface

| Platform   | Public API                                                                               | Cleanup                                          |
| ---------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------ |
| TypeScript | `getSubChannelTopic(subChannel)`, then `subscribeTopic(topic)`                           | Call the returned `Amity.Unsubscriber`           |
| iOS        | `AmitySubChannelTopic(subChannel:)`, then `AmityTopicSubscription().subscribeTopic(...)` | `AmityTopicSubscription().unsubscribeTopic(...)` |
| Android    | `subChannel.subscription().subscribeTopic()`                                             | `subChannel.subscription().unsubscribeTopic()`   |
| Flutter    | `subChannel.subscription().subscribeTopic()`                                             | `subChannel.subscription().unsubscribeTopic()`   |

## Parameters

| Platform   | Parameter    | Required | Description                                                                                                            |
| ---------- | ------------ | -------- | ---------------------------------------------------------------------------------------------------------------------- |
| TypeScript | `subChannel` | Yes      | `Amity.SubChannel` model returned by the SDK. The helper reads its `path` and subscribes to that path with a wildcard. |
| iOS        | `subChannel` | Yes      | `AmitySubChannel` model used to construct `AmitySubChannelTopic`.                                                      |
| Android    | `subChannel` | Yes      | `AmitySubChannel` model exposing the public `subscription()` method.                                                   |
| Flutter    | `subChannel` | Yes      | `AmitySubChannel` model exposing the public `subscription()` method.                                                   |

## Subscribe To A Subchannel

Subscribe when the thread screen becomes active, and unsubscribe when it leaves the screen or switches to another subchannel.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { getSubChannelTopic, subscribeTopic } from '@amityco/ts-sdk';

  function subscribeToSubChannel(subChannel: Amity.SubChannel): Amity.Unsubscriber {
    const topic = getSubChannelTopic(subChannel);

    return subscribeTopic(topic);
  }
  ```

  ```swift iOS theme={null}
  func subscribeToSubChannel(_ subChannel: AmitySubChannel) async throws {
      let topic = AmitySubChannelTopic(subChannel: subChannel)

      try await AmityTopicSubscription().subscribeTopic(topic)
  }

  func unsubscribeFromSubChannel(_ subChannel: AmitySubChannel) async throws {
      let topic = AmitySubChannelTopic(subChannel: subChannel)

      try await AmityTopicSubscription().unsubscribeTopic(topic)
  }
  ```

  ```kotlin Android theme={null}
  import com.amity.socialcloud.sdk.model.chat.subchannel.AmitySubChannel

  fun subscribeToSubChannel(subChannel: AmitySubChannel) {
      subChannel.subscription()
          .subscribeTopic()
          .subscribe({
              showSuccessMessage("Subscribed")
          }, { error ->
              showErrorMessage(error = error)
          })
  }

  fun unsubscribeFromSubChannel(subChannel: AmitySubChannel) {
      subChannel.subscription()
          .unsubscribeTopic()
          .subscribe()
  }
  ```

  ```dart Flutter theme={null}
  Future<void> subscribeToSubChannel(AmitySubChannel subChannel) async {
    await subChannel.subscription().subscribeTopic();
  }

  Future<void> unsubscribeFromSubChannel(AmitySubChannel subChannel) async {
    await subChannel.subscription().unsubscribeTopic();
  }
  ```
</CodeGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Subscribe per visible thread" icon="messages-square">
    Bind the subchannel subscription to the active message thread, not to the entire chat module. Switch the subscription when the user changes threads.
  </Accordion>

  <Accordion title="Keep the model source explicit" icon="box">
    The snippets expect a real `SubChannel` model returned by the SDK. Avoid constructing topic paths manually in app code.
  </Accordion>

  <Accordion title="Use live collections for rendering" icon="refresh-cw">
    After subscribing, render messages from the SDK query or live collection APIs so local cache updates and pagination stay consistent.
  </Accordion>
</AccordionGroup>

## Related Topics

<CardGroup cols={2}>
  <Card title="Messages" href="/social-plus-sdk/chat/messaging-features/messages/query-and-filter-messages" icon="message-square">
    Query and render messages for a subchannel.
  </Card>

  <Card title="Live Objects & Collections" href="/social-plus-sdk/core-concepts/realtime-communication/live-objects-collections/overview" icon="refresh-cw">
    Understand how realtime events update observed SDK data.
  </Card>
</CardGroup>
