Skip to main content
Real-time listeners let you receive live events — messages, presence changes, group updates, and call signals — as they happen. The pattern is the same for all four listener types:
  1. Register a listener with a unique ID using addXListener()
  2. Handle events in the callback methods
  3. Remove the listener with removeXListener() when it’s no longer needed
Each listener ID must be unique. Re-registering with the same ID replaces the previous listener. Always remove listeners on component unmount or page navigation to prevent memory leaks.
Always remove listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.
CometChat provides 4 listeners viz.
  1. User Listener
  2. Group Listener
  3. Message Listener
  4. Call Listener
  5. AI Assistant Listener
  6. Ongoing Call Listener (Calls SDK)

User Listener

Receive online/offline presence events for users. To add the UserListener:
Remove the listener when no longer needed:

Group Listener

Receive events when group members join, leave, are kicked/banned, or have their scope changed. To add the GroupListener:
Remove the listener when no longer needed:

Message Listener

Receive events for incoming messages, typing indicators, read/delivery receipts, message edits/deletes, reactions, and moderation results.
Remove the listener when no longer needed:

Call Listener

Receive events for incoming and outgoing call state changes. To add the CallListener:
Remove the listener when no longer needed:

AI Assistant Listener

The AIAssistantListener provides real-time streaming events from AI Agent runs. These events are received as the agent processes a user’s message, before the final persisted messages arrive via the MessageListener.
To remove the listener:

Ongoing Call Listener (Calls SDK)

The OngoingCallListener provides real-time callbacks for active call session events. It is part of the CometChat Calls SDK (not the Chat SDK) and is used with CallSettingsBuilder.setCallListener() or CometChatCalls.addCallEventListener(). All three calling flows — Call Session, Standalone Calling, and Ringing — use the same OngoingCallListener.

Callbacks

Callback Parameter Shapes

user object (received by onUserJoined, onUserLeft): onUserListUpdated(userList) — receives an array of user objects with the same shape as above. onUserMuted(event): onCallSwitchedToVideo(event): onMediaDeviceListUpdated(deviceList): onRecordingStarted(event): onRecordingStopped(), onCallEnded(), onSessionTimeout(), onCallEndButtonPressed(), onScreenShareStarted(), onScreenShareStopped() — receive no arguments.

Login Listener

Receive events when the user’s authentication state changes — login success/failure and logout success/failure.
Remove the listener when no longer needed:

Connection Listener

Receive events when the WebSocket connection state changes.
Remove the listener when no longer needed:

Next Steps

Receive Messages

Handle incoming messages in real-time

Typing Indicators

Show when users are typing

User Presence

Track online/offline status of users

Connection Status

Monitor SDK connection state changes