Title
Page icon
Create new category
Edit page index title
Edit category
Edit link
Event Handler
Qiscus Chat SDK provides a simple way to let applications publish and listen some real time event. You can publish typing, read, user status, custom event, and you can handle freely in event handler. This lets you inform users that another participant is actively engaged in communicating with them. Qiscus Chat SDK is using function callback when you initialize Chat SDK. You can define it like this:
Receiving Message
Messages can be received through a newMessagesCallback event. This event is triggered whenever users send a message, you can implement this event, for example:
newMessagesCallback got a parameter of array of single comment object, not an object of comment.
Typing Status
You can have a typing status by publish the typing event. You need to pass typing status. Set 1 to indicate the typing event is active, set 0 to indicate the event is inactive, you can use the code below:
Customizing Real-time Event
You can publish and listen any events such as when participant is listening music, writing document, and many other case that you need to tell an event to other participant in a Chat Room.
Firstly you need passing roomId which ChatRoom you want to set, and the structured data for defining what event you want to send. Example of structured data of writing document event:
Then you can send event using this following method publishEvent:
if you need to stop telling other participant that event is ended, you can send a flag to be false inside your structured data, for example:
After sending an event, then you need to listen the event with related roomId, for example:
You need unlisten the event with related roomId, for example:
Connection to Qiscus Server
You can have control in your App, when you are reconnected, by default Qiscus Chat SDK will try reconnect automatically, and you get the event once it success. Below is the code for the event:
On Message Status Change
After you listen some of events in a ChatRoom, You can receive the real time message status which defined by the event, such as typing, delivered, and read, for example:
This is an complete version how to use Qiscus Event Handler, for example:
Here's event handler table:
Method | When to call |
|---|---|
newMessagesCallback | When a user successfully send a message |
commentDeletedCallback | When a message has been deleted |
commentDeliveredCallback | When a message successfully delivered to a user |
commentReadCallback | When a message has been read by user |
presenceCallback | When user change it online status<br> |
typingCallback | When user is still typing or not<br> |
onReconnectCallback | When Chat SDK realtime adapter successfully reconnected to server |
roomClearedCallback | When successfully cleared a room messages<br> |
Qiscus Technology