ConnectionListener class provided by the CometChat SDK
With offline support enabled, your app keeps working without a connection: cached chats are shown instantly, and messages you send with a
MessageSentListener are queued and delivered automatically on reconnect. See Show Cached Data and Send While Offline.
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.
In order to use the ConnectionListeners, you need to add the ConnectionListeners using the addConnectionListener method provided by the SDK. You can add multiple listeners as shown below. Just make sure you add listeners with unique IDs.
- Java
- Kotlin
getConnectionStatus property provided by CometChat SDK
- Java
- Kotlin
-
CometChatConstants.WS_STATE_CONNECTED(connected); -
CometChatConstants.WS_STATE_CONNECTING(connecting) -
CometChatConstants.WS_STATE_DISCONNECTED(disconnected) -
CometChatConstants.WS_STATE_FEATURE_THROTTLED(featureThrottled)
Know more about CometChat SDK connection behaviour click here