Quick Reference for AI Agents & Developers
- Add listener:
CometChat.addConnectionListener("UNIQUE_ID", self as CometChatConnectionDelegate) - Remove listener:
CometChat.removeConnectionListener("UNIQUE_ID") - Delegate methods:
connecting(),connected(),disconnected() - Related: Setup · WebSocket Connection · Overview
CometChatConnectionDelegate class.
Connection Status provides you with the below 3 methods to get the status of the connection to CometChat web-socket servers:
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 Delegate methods you must add protocol conformance CometChatConnectionDelegate as CometChat.conectiondelegate = self . Here is the example of CometChatConnectionDelegate:
- Swift
- Objective C
Sample Payload - CometChatConnectionDelegate Events
Sample Payload - CometChatConnectionDelegate Events
connecting() Event:
Event Trigger: SDK is attempting to establish WebSocket connection
connected() Event:
Event Trigger: WebSocket connection successfully established
disconnected() Event:
Event Trigger: WebSocket connection lost
Connection Flow:
We recommend you to add the Connection Status delegate in your AppDelegate and in your app’s first view controller that opens when you log in.
getConnectionStatus property provided by CometChat SDK
- Swift
Sample Payload - getConnectionStatus
Sample Payload - getConnectionStatus
Method:
Response:
Possible Values:
CometChat.getConnectionStatus method will return either of the below 3 values:
- connecting
- connected
- disconnected