> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Connection Status

CometChat SDK provides you with a mechanism to get real-time status of the connection to CometChat web-socket servers.

Connection Status provides you with the below 3 methods to get the status of the connection to CometChat web-socket servers:

| Delegate Method    | Information                                                                                                                                      |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| inConnecting       | This method is triggered when CometChat SDK is trying to establish a connection to the web-socket server.                                        |
| onConnected        | This method is called when CometChat SDK has successfully established a connection and is now connected.                                         |
| onDisconnected     | This method is called when the CometChat SDK gets disconnected due to any issue while maintaining the connection like network fluctuations, etc. |
| onFeatureThrottled | CometChat automatically toggles off certain features to prevent performance loss for end-users under various circumstances.                      |
| onConnectionError  | This method is called when the CometChat SDK encounters an error while maintaining the connection, such as network fluctuations, etc.            |

Once the connection is broken, the disconnected callback is triggered, the SDK automatically tries to establish the connection again, thus going into the connecting state and triggering the `connecting` method. Once the attempt to connect is successful, the `connected` method is triggered thus letting the developer know that the connection is established and is active.

To receive real-time connection status, you need to register `ConnectionListener` wherever you wish to receive the real-time status. You can use the `addConnectionListener()` method to do so.

<Tabs>
  <Tab title="Connection Listener">
    ```javascript theme={null}
    var 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>

  <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");
        },
      })
    );
    ```
  </Tab>
</Tabs>

<Note>
  We recommend you to add the Connection Listener in your method on app startup, preferably in the index.js file. Once you have successfully initialized CometChat.
</Note>

You can also get the current connection status by using `getConnectionStatus` property provided by CometChat SDK

<Tabs>
  <Tab title="Get Connection Status">
    ```javascript theme={null}
    var connectionStatus = CometChat.getConnectionStatus();
    ```
  </Tab>

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

The `CometChat.getConnectionStatus` method will return either of the below 4 values:

1. `CometChat.CONNECTION_STATUS.CONNECTED` (connected)
2. `CometChat.CONNECTION_STATUS.CONNECTING` (connecting)
3. `CometChat.CONNECTION_STATUS.DISCONNECTED` (disconnected)
4. `CometChat.CONNECTION_STATUS.FEATURE_THROTTLED `(featureThrottled)
