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:

Javascript
Copy

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:

Javascript
Copy

newMessagesCallback got a parameter of array of single comment object, not an object of comment.

Sending 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:

Javascript
Copy

Sending Online Status

You can set online or offline by passing isOnline status. Set true to indicate user is online, and set false to indicate that user is offline. The result will be on presenceCallback: function (data, userId) . Below are the code for publish online or offline:

Javascript
Copy

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:

JSON
Copy

Then you can send event using this following method publishEvent:

Javascript
Copy

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:

JSON
Copy

After sending an event, then you need to listen the event with related roomId, for example:

Javascript
Copy

You need unlisten the event with related roomId, for example:

Javascript
Copy

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:

Javascript
Copy

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:

Javascript
Copy

This is an complete version how to use Qiscus Event Handler, for example:

Javascript
Copy

Here's event handler table:

MethodWhen to call
newMessagesCallbackWhen a user successfully send a message
commentDeletedCallbackWhen a message has been deleted
commentDeliveredCallbackWhen a message successfully delivered to a user
commentReadCallbackWhen a message has been read by user
presenceCallbackWhen user change it online status
typingCallbackWhen user is still typing or not
onReconnectCallbackWhen Chat SDK realtime adapter successfully reconnected to server
roomClearedCallbackWhen successfully cleared a room messages
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard