AI Integration Quick Reference
AI Integration Quick Reference
init() when a session exists, and handles reconnection on network drops. This page covers how to disable that and manage the connection yourself.
You’d want manual control when you need to conserve resources by connecting only when the user is actively chatting, or when you need precise control over when real-time events start flowing.
Default Behavior
WhenautoEstablishSocketConnection is true (the default):
CometChat.login()logs the user in, saves their session locally, and opens a WebSocket connection- On app restart,
CometChat.init()automatically reconnects using the saved session - The user immediately starts receiving real-time messages, presence updates, and call events
Manual Connection Management
To take control of the WebSocket connection, setautoEstablishSocketConnection(false) during initialization:
- TypeScript
- JavaScript
connect() and disconnect() to control the WebSocket connection.
Connect
Establishes the WebSocket connection. The user must be logged in first (check withCometChat.getLoggedinUser()). Once connected, real-time events start flowing. Returns void.
- Connect
Disconnect
Breaks the WebSocket connection. Real-time events stop until you callconnect() again. Returns void.
- Disconnect
Next Steps
Connection Status
Monitor the SDK connection state in real time
Login Listener
Listen for login and logout events
All Real-Time Listeners
Complete reference for all SDK event listeners
Setup SDK
SDK installation and initialization guide