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 to prevent memory leaks.
Always remove listeners when they’re no longer needed (e.g., on component unmount). Failing to remove listeners can cause memory leaks and duplicate event handling. For React Native, use useEffect cleanup functions to handle listener removal automatically.
CometChat provides 4 listeners viz.
  1. User Listener
  2. Group Listener
  3. Message Listener
  4. Call Listener
With offline support enabled, four more listeners report what the SDK does on the device; see Offline listeners.

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 interactive messages.
With offline support enabled, MessageListener also receives onMessagesSynced after the SDK catches up on reconnect. It carries only updates to already-cached messages that changed while offline (reactions, edits, deletes and receipts). Messages that arrived while offline still come through the typed callbacks such as onTextMessageReceived. See Stay in Sync.
To add the MessageListener:
Remove the listener when no longer needed:
Pin and unpin are conversation-wide — every participant receives them. Save and unsave are private multi-device: they reach the saving user’s other sessions, not the device that performed the save, which already has the message resolved from the saveMessage() promise. Each callback carries the full updated message, so getPinnedAt() / getSavedAt() are readable without a further fetch. See Pin A Message and Save A Message.
Conversation pins use a separate ConversationListener, with onConversationPinned and onConversationUnpinned. It fires on the user’s other devices and for admin pins, not on the device that pinned. See Pin A Conversation.

Call Listener

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

Offline listeners

With offline support enabled (SDK 4.2.0 or newer), these listeners report what the SDK does on the device rather than events from the server. Each is documented with examples on its own page.

Next Steps

User Presence

Track when users come online or go offline

Receive Messages

Handle incoming messages in real time

Typing Indicators

Show when users are typing

Connection Status

Monitor SDK connection state changes