Quick Reference
| Delegate Method | Information |
|---|---|
| connecting | This method is triggered when CometChat SDK is trying to establish a connection to the web-socket server. |
| connected | This method is called when CometChat SDK has successfully established a connection and now is connected. |
| disconnected | This method is called when the CometChat SDK gets disconnected due to any issue while maintaining the connection like network fluctuations, etc. |
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.
- JavaScript
- TypeScript
We recommend you to add the Connection Listener in your method on app startup, preferably in the App.tsx file. Once you have successfully initialized CometChat.
getConnectionStatus property provided by CometChat SDK
- JavaScript
- TypeScript
CometChat.getConnectionStatus method will return either of the below 3 values:
connectingconnecteddisconnected
Best Practices
Best Practices
- Register the connection listener early in your app lifecycle (after
CometChat.init()) to catch connection state changes from the start - Use connection status to show a connectivity indicator in your UI (e.g., a banner when disconnected)
- When the status changes to
connectedafter adisconnectedstate, consider refreshing your message list to fetch any messages missed during the disconnection - Avoid making SDK calls (sending messages, fetching data) while the status is
disconnected— queue them and retry onceconnected
Troubleshooting
Troubleshooting
- Listener not firing: Ensure you registered the
ConnectionListenerwith a unique listener ID after callingCometChat.init(). - Stuck in connecting state: Check your network connection and verify that the App ID and region are correct in your
AppSettings. - Frequent disconnections: This is typically caused by network instability. The SDK handles reconnection automatically in auto mode.
onFeatureThrottledfiring: This indicates your app is hitting rate limits. Reduce the frequency of API calls.