Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Event handler
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Add or remove a user event handler

To receive information about events related to users connected to the Sendbird server, add a user event handler with its UNIQUE_HANDLER_ID by calling sb.addUserEventHandler().

If you want to stay informed of changes related to users and notify the changes to different client apps, define and register multiple channel event handlers using the UNIQUE_HANDLER_ID.


User event types

List of user events

MethodInvoked whenNotified devices

onTotalUnreadMessageCountUpdated()

There has been an update on the total number of a user's unread messages because the user read messages in group channels.

The user's devices running client apps. The devices will be notified with the total number of unread messages and the number of unread messages by custom channel type.

To add or remove onTotalUnreadMessageCountUpdated(), visit this page and contact us on Sendbird Dashboard.


Add a user event handler

The following code shows the supported event callback with its parameters and how to add a user event handler to the unique SendbirdChat instance.

const userEventHandler: UserEventHandler = new UserEventHandler({
  onTotalUnreadMessageCountUpdated: (totalCount: number, countByCustomTypes: { [key: string]: number }) => {},
});

sb.addUserEventHandler(UNIQUE_HANDLER_ID, userEventHandler);

Remove a user event handler

The following code shows how to remove the user event handler.

sb.removeUserEventHandler(UNIQUE_HANDLER_ID);