Skip to main content

Overview

Events allow for a decoupled, flexible architecture where different parts of the application can interact without having to directly reference each other. This makes it easier to create complex, interactive experiences, as well as to extend and customize the functionality provided by the CometChat UI Kit. Both Components and Composite Components have the ability to emit events. These events are dispatched in response to certain changes or user interactions within the component. By emitting events, these components allow other parts of the application to react to changes or interactions, thus enabling dynamic and interactive behavior within the application.

User Events

CometChatUserEvents emits events when the logged-in user executes some action on another user It contains the following properties and methods

observer

This is a List of Dictionary that contains components listening to user events in key value pairs

Type

[String: CometChatUserEventListener]()

addListener

this method stores the passed listenerClass against the passed id in the usersListener.

Signature

Uses

Parameters


removeListener

this method removes the entry with the passed id from the usersListener.

Signature

Parameters


onUserBlock

This method is used to perform some task when the logged-in user has blocked a user

Signature

Parameters


onUserUnblock

This method is used to perform some task when the logged-in user has unblocked a blocked user.

Signature

Parameters

Return Type

void

Emitting User Events

There are two types of user event listeners, one is for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged in user and second, the events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side user events to inform other UI components in your project that a user has been blocked or unblocked, the methods being used are static and hence they can be called without having to create an instance of CometChatUserEvents class.

Listening to User Events

Here we will go through how anyone can listen to these client-side User Events to update the state of the UI accordingly.

Group Events

CometChatGroupEvents emits events when the logged-in user executes some action on a group or group member It contains the following properties and methods:

observer

This is a List of Dictionary that contains components listening to group events in key value pairs

Type

[String: CometChatGroupEventListener]()

addListener

this method stores the passed listenerClass against the passed listenerId in the observer.

Signature

Parameters


removeListener

this method removes the entry with the passed listenerId from the observer.

Signature

Parameters


onGroupCreate

This method is used to perform some task when the logged-in user has created a group

Signature

Parameters


onCreateGroupClick

This method is used to perform some task when the logged-in user click on Create group button

Signature


onGroupDelete

This method is used to perform some task when the logged-in user has deleted a group.

Signature

Parameters


onGroupMemberLeave

This method is used to perform some task when the logged-in user has left a group.

Signature

Parameters


onGroupMemberChangeScope

This method is used to perform some task when the logged-in user has changed the scope of a member of a group.

Signature

Parameters


onGroupMemberBan

This method is used to perform some task when the logged-in user has banned a user from the group.

Signature

Parameters


onGroupMemberKick

This method is used to perform some task when the logged-in user has kicked a user from the group.

Signature

Parameters


onGroupMemberUnban

This method is used to perform some task when the logged-in user has unbanned a banned user from a group.

Signature

Parameters


onGroupMemberJoin

This method is used to perform some task when the logged-in user has joined a group.

Signature

Parameters


onGroupMemberAdd

This method is used to perform some task when the logged-in user has added new members to the group

Signature

Parameters


onOwnershipChange

This method is used to perform some task when the logged-in user has transferred their ownership of a group.

Signature

Parameters


Emitting Group Events

There are two types of group event listeners, one is for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged in user and second, the events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side group events to inform other UI components in a project that a group has been created or deleted or new members have been added to the group, the logged in user themselves have joined a group, members being banned by the logged in user or the change of ownership or scope of a group member, the methods being used are static and hence they can be called without having to create an instance of CometChatGroupEvents class.

Listening to Group Events

Here we will go through how anyone can listen to these client-side Group Events to update the state of the UI accordingly.

Conversation Events

CometChatConversationEvents emits events when the logged-in user executes some action on a conversation object It contains the following properties and methods

observer

This is a List of Dictionary that contains components listening to user events in key value pairs

Type

[String: CometChatConversationEventListener]()

addListener

this method stores the passed listenerClass against the passed listenerId in the observer.

Signature

Parameters


removeListener

this method removes the entry with the passed id from the observer.

Signature

Parameters

Return Type

void

onConversationDelete

This method is used to perform some task when the logged-in user has deleted a conversation

Signature

Parameters


Emitting Conversation Events

Here we will go through how to emit events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side conversation events to inform other UI components in a project that a conversation has been deleted, the methods being used are static and hence they can be called without having to create an instance of CometChatConversationEvents class.

Listening to Conversation Events

Here we will go through how anyone can listen to these client-side Conversation Events to update the state of the UI accordingly.

Message Events

CometChatMessageEvents emits events when the logged-in user executes some action involving any message object. It contains the following properties and methods:

observer

This is a List of Dictionary that contains components listening to message events in key value pairs

Type

[String: CometChatMessageEventListener]()

addListener

this method stores the passed listenerClass against the passed id in the observer.

Signature

Parameters


removeListener

this method removes the entry with the passed id from the observer.

Signature

Parameters


onMessageSent

This method is used to perform some task when the logged-in user has sent a message

Signature

Parameters


onMessageEdit

This method is used to perform some task when the logged-in user has edited a message

Signature

Parameters


onMessageDelete

This method is used to perform some task when the logged-in user has deleted a message

Signature

Parameters


onMessageRead

This method is used to perform some task when the logged-in user has read a message

Signature

Parameters


onLiveReaction

This method is used to perform some task when the logged-in user has a sent a transient message

Signature

Parameters


onViewInformation

This method is used to perform some task when the logged-in user click on detail button.

Signature


onParentMessageUpdate

This method is used to perform some task when the logged-in user updates a message that has replies.

Signature


Emitting Message Events

There are two types of message event listeners, one is for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged in user; and second, the events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side message events to inform other UI components in a project.

Listening to Message Events

Here we will go through how anyone can listen to these client-side Message Events to update the state of the UI accordingly.

Call Events

CometChatCallEvents emits events when the logged-in user executes some action involving any call object. It contains the following properties and methods:

observer

This is a List of Dictionary that contains components listening to call events in key value pairs

Type

[String:CometChatCallEventListener]()

addListener

This method stores the passed listenerClass against the passed id in the addListener.

Signature


removeListener

This method removes the entry with the passed id from the observer.

Signature


onIncomingCallAccepted

This method is used to perform some task when the logged-in user accepts the incoming call

Signature


onIncomingCallRejected

This method is used to perform some task when the logged-in user rejects the incoming call

Signature


onCallInitiated

This method is used to perform some task when the logged-in user initiates a call

Signature


onCallEnded

This method is used to perform some task when the ongoing or outgoing call ends.

Signature


onOutgoingCallAccepted

This method is used to perform some task when the outgoing call is accepted.

Signature


onOutgoingCallRejected

This method is used to perform some task when the outgoing call is rejected.

Signature


Emitting Call Events

There are two types of call event listeners, one for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged-in user; and another for events specific to the UI Kit, which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contain how to emit such client-side call events to inform other UI components in a project.

Listening to Call Events

Here we will go through how anyone can listen to these client-side Call Events to update the state of the UI accordingly.