Chat Lifecycle
Table of contents
Overview
Through chat progress, it can be in various states, each has it’s own meaning. The hosting app can react to chat states and control it’s flow, by listening to chat states changes.
In order to listen to chat lifecycle events, set your implemention of ChatEventListener
, to the ChatController
.
// on ChatController construction:
val chatController = ChatController.Builder(context)
.chatEventListener(listener)...build(...)
// or later in time:
chatController.chatEventListener = listener
Lifecycle Events
States handling code sample:
@Override
public void onChatStateChanged(@NotNull StateEvent stateEvent) {
switch (stateEvent.getState()) {
case StateEvent.Started:
// do something
case StateEvent.Unavailable:
// do something
case StateEvent.Ended:
// do something
case StateEvent.InQueue:
// fetching the queue position from the event:
InQueueEvent queueEvent = (InQueueEvent) stateEvent;
int queuePosition = queueEvent.getPosition();
case StateEvent.Idle:
// no more active chats, we can remove chat fragment
case StateEvent.ChatWindowLoaded:
// do something
case StateEvent.ChatWindowDetached:
// removing chat fragment from its activity
}
}