Overview
The UI Kit’s core function is to extend the Chat SDK, essentially translating the raw data and functionality provided by the underlying methods into visually appealing and easy-to-use UI components. To effectively manage and synchronize the UI elements and data across all components in the UI Kit, we utilize internal events. These internal events enable us to keep track of changes in real time and ensure that the UI reflects the most current state of data. The CometChat UI Kit has thoughtfully encapsulated the critical Chat SDK methods within its wrapper to efficiently manage internal eventing. This layer of abstraction simplifies interaction with the underlying CometChat SDK, making it more user-friendly for developers.Methods
You can access the methods using theCometChatUIKit
class. This class provides access to all the public methods exposed by the CometChat UI Kit.
Init
This method initializes the settings required for CometChat JavaScript SDK. First, ensure UIKitSettings is set and then call theinit()
method on the app startup.
Make sure you replace the APP_ID, REGION and AUTH_KEY with your CometChat App ID, Region and Auth Key in the below code. The
Auth Key
is an optional property of the UIKitSettings
Class. It is intended for use primarily during proof-of-concept (POC) development or in the early stages of application development. You can use the Auth Token method to log in securely.getLoggedInUser
You can use this method to check if there is any existing session in the SDK. This method should return the details of the logged-in user.Login using Auth Key
This simple authentication procedure is useful when you are creating a POC or if you are in the development phase. For production apps, we suggest you use AuthToken instead of Auth Key.Login using Auth Token
This advanced authentication procedure does not use the Auth Key directly in your client code thus ensuring safety.- Create a User via the CometChat API when the user signs up in your app.
- Create an Auth Token via the CometChat API for the new user and save the token in your database.
- Load the Auth Token in your client and pass it to the
loginWithAuthToken()
method.
Logout
This method is used to end the user session of the logged-in userCreate user
This method takes aUser
object and the Auth Key
as input parameters and returns the created User
object if the request is successful.
Update user
This method takes aUser
object and the Auth Key
as inputs and returns the updated User
object on the successful execution of the request.
Send text message
This method sends a text message in a 1:1 or group chat. You need to pass aTextMessage
object to it.
Send media message
This method sends a media message in a 1:1 or group chat. You need to pass aMediaMessage
object to it.
Make sure you replace the
INPUT FILE OBJECT
with the actual file.