> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Connection Status

> Monitor real-time WebSocket connection status and respond to connectivity changes using the CometChat React Native SDK.

<Accordion title="AI Integration Quick Reference">
  ```javascript theme={null}
  // Get current status: "connecting" | "connected" | "disconnected"
  const status = CometChat.getConnectionStatus();

  // Listen for connection changes
  CometChat.addConnectionListener("LISTENER_ID", new CometChat.ConnectionListener({
    onConnected: () => console.log("Connected"),
    inConnecting: () => console.log("Connecting..."),
    onDisconnected: () => console.log("Disconnected")
  }));

  // Cleanup
  CometChat.removeConnectionListener("LISTENER_ID");
  ```
</Accordion>

The CometChat SDK maintains a WebSocket connection to CometChat servers for real-time events. You can check the current connection state and listen for changes — useful for showing connectivity indicators in your UI or queuing operations while offline.

When the connection drops, the SDK automatically attempts to reconnect, cycling through `disconnected` → `connecting` → `connected`.

## Connection States

| Value                | Callback               | Description                                                 |
| -------------------- | ---------------------- | ----------------------------------------------------------- |
| `"connected"`        | `onConnected()`        | SDK has an active connection to CometChat servers           |
| `"connecting"`       | `inConnecting()`       | SDK is attempting to establish or re-establish a connection |
| `"disconnected"`     | `onDisconnected()`     | SDK is disconnected due to network issues or other errors   |
| `"featureThrottled"` | `onFeatureThrottled()` | A feature has been throttled due to rate limiting           |

## Get Current Status

Use `getConnectionStatus()` to check the current connection state at any time:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    const connectionStatus: string = CometChat.getConnectionStatus();
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const connectionStatus = CometChat.getConnectionStatus();
    ```
  </Tab>
</Tabs>

## Listen for Connection Changes

Register a `ConnectionListener` to receive real-time connection state updates. We recommend adding this on app startup (e.g., in `App.tsx`) after `CometChat.init()` completes.

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    let listenerID: string = "UNIQUE_LISTENER_ID";
    CometChat.addConnectionListener(
      listenerID,
      new CometChat.ConnectionListener({
        onConnected: () => {
          console.log("ConnectionListener => On Connected");
        },
        inConnecting: () => {
          console.log("ConnectionListener => In connecting");
        },
        onDisconnected: () => {
          console.log("ConnectionListener => On Disconnected");
        },
        onFeatureThrottled: () => {
          console.log("ConnectionListener => On Feature Throttled");
        },
        onConnectionError: () => {
          console.log("ConnectionListener => On Connection Error");
        },
      })
    );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    let listenerID = "UNIQUE_LISTENER_ID";
    CometChat.addConnectionListener(
      listenerID,
      new CometChat.ConnectionListener({
        onConnected: () => {
          console.log("ConnectionListener => On Connected");
        },
        inConnecting: () => {
          console.log("ConnectionListener => In connecting");
        },
        onDisconnected: () => {
          console.log("ConnectionListener => On Disconnected");
        },
        onFeatureThrottled: () => {
          console.log("ConnectionListener => On Feature Throttled");
        },
        onConnectionError: () => {
          console.log("ConnectionListener => On Connection Error");
        },
      })
    );
    ```
  </Tab>
</Tabs>

<Warning>
  Always remove connection listeners when they're no longer needed (e.g., on component unmount). Failing to remove listeners can cause memory leaks and duplicate event handling.
</Warning>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="WebSocket Management" icon="plug" href="/sdk/react-native/managing-web-sockets-connections-manually">
    Manually manage WebSocket connections
  </Card>

  <Card title="All Real-Time Listeners" icon="tower-broadcast" href="/sdk/react-native/real-time-listeners">
    Complete reference for all SDK listeners
  </Card>

  <Card title="Setup SDK" icon="gear" href="/sdk/react-native/setup-sdk">
    Install and initialize the CometChat SDK
  </Card>

  <Card title="Key Concepts" icon="book" href="/sdk/react-native/key-concepts">
    Review the fundamental building blocks of CometChat
  </Card>
</CardGroup>
