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 methodsobserver
This is a List of Dictionary that contains components listening to user events in key value pairsType
[String: CometChatUserEventListener]()
addListener
this method stores the passed listenerClass against the passed id in the usersListener.Signature
Uses
- Swift
Parameters
removeListener
this method removes the entry with the passed id from the usersListener.Signature
- Swift
Parameters
onUserBlock
This method is used to perform some task when the logged-in user has blocked a userSignature
- Swift
Parameters
onUserUnblock
This method is used to perform some task when the logged-in user has unblocked a blocked user.Signature
- Swift
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.- Swift
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.- Swift
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 pairsType
[String: CometChatGroupEventListener]()
addListener
this method stores the passed listenerClass against the passed listenerId in the observer.Signature
- Swift
Parameters
removeListener
this method removes the entry with the passed listenerId from the observer.Signature
- Swift
Parameters
onGroupCreate
This method is used to perform some task when the logged-in user has created a groupSignature
- Swift
Parameters
onCreateGroupClick
This method is used to perform some task when the logged-in user click on Create group buttonSignature
- Swift
onGroupDelete
This method is used to perform some task when the logged-in user has deleted a group.Signature
- Swift
Parameters
onGroupMemberLeave
This method is used to perform some task when the logged-in user has left a group.Signature
- Swift
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
- Swift
Parameters
onGroupMemberBan
This method is used to perform some task when the logged-in user has banned a user from the group.Signature
- Swift
Parameters
onGroupMemberKick
This method is used to perform some task when the logged-in user has kicked a user from the group.Signature
- Swift
Parameters
onGroupMemberUnban
This method is used to perform some task when the logged-in user has unbanned a banned user from a group.Signature
- Swift
Parameters
onGroupMemberJoin
This method is used to perform some task when the logged-in user has joined a group.Signature
- Swift
Parameters
onGroupMemberAdd
This method is used to perform some task when the logged-in user has added new members to the groupSignature
- Swift
Parameters
onOwnershipChange
This method is used to perform some task when the logged-in user has transferred their ownership of a group.Signature
- Swift
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.- Swift
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.- Swift
Conversation Events
CometChatConversationEvents emits events when the logged-in user executes some action on a conversation object It contains the following properties and methodsobserver
This is a List of Dictionary that contains components listening to user events in key value pairsType
[String: CometChatConversationEventListener]()
addListener
this method stores the passed listenerClass against the passed listenerId in the observer.Signature
- Swift
Parameters
removeListener
this method removes the entry with the passed id from the observer.Signature
- Swift
Parameters
Return Type
void
onConversationDelete
This method is used to perform some task when the logged-in user has deleted a conversationSignature
- Swift
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.- Swift
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.- Swift
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 pairsType
[String: CometChatMessageEventListener]()
addListener
this method stores the passed listenerClass against the passed id in the observer.Signature
- Swift
Parameters
removeListener
this method removes the entry with the passed id from the observer.Signature
- Swift
Parameters
onMessageSent
This method is used to perform some task when the logged-in user has sent a messageSignature
- Swift
Parameters
onMessageEdit
This method is used to perform some task when the logged-in user has edited a messageSignature
- Swift
Parameters
onMessageDelete
This method is used to perform some task when the logged-in user has deleted a messageSignature
- Swift
Parameters
onMessageRead
This method is used to perform some task when the logged-in user has read a messageSignature
- Swift
Parameters
onLiveReaction
This method is used to perform some task when the logged-in user has a sent a transient messageSignature
- Swift
Parameters
onViewInformation
This method is used to perform some task when the logged-in user click on detail button.Signature
- Swift
onParentMessageUpdate
This method is used to perform some task when the logged-in user updates a message that has replies.Signature
- Swift
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.- Swift
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.- Swift
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 pairsType
[String:CometChatCallEventListener]()
addListener
This method stores the passed listenerClass against the passed id in the addListener.Signature
- Swift
removeListener
This method removes the entry with the passed id from the observer.Signature
- Swift
onIncomingCallAccepted
This method is used to perform some task when the logged-in user accepts the incoming callSignature
- Swift
onIncomingCallRejected
This method is used to perform some task when the logged-in user rejects the incoming callSignature
- Swift
onCallInitiated
This method is used to perform some task when the logged-in user initiates a callSignature
- Swift
onCallEnded
This method is used to perform some task when the ongoing or outgoing call ends.Signature
- Swift
onOutgoingCallAccepted
This method is used to perform some task when the outgoing call is accepted.Signature
- Swift
onOutgoingCallRejected
This method is used to perform some task when the outgoing call is rejected.Signature
- Swift
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.- Swift
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.- Swift