Event Listeners

Event Listeners are used to handle events received from the ChatCamp server.

Event listeners enables you to receive events from ChatCamp backend in real time. You may use event listener to execute a specific workflow for any server side event. Each event listener contains various callback methods. You may override these callback methods to react to a particular chat event.

Channel Listeners

Channel listeners are designed to handle events of a channel, group or open both.

let channelListener = new cc.ChannelListener();


channelListener.onOpenChannelMessageReceived = function(openChannel, message) {
  //triggered when a message in an open channel is received
}

channelListener.onOpenChannelMessageUpdate = function(openChannel, message) {
  //triggered when a message in an open channel is updated
}

channelListener.onGroupChannelMessageReceived = function(groupChannel, message) {
  //triggered when a message in a group channel is received
}

channelListener.onGroupChannelMessageUpdated = function(groupChannel, message) {
  //triggered when a message in a group channel is updated
}

channelListener.onGroupChannelTypingStatusChanged = function(groupChannel) {
// triggered when typing status is updated
}

channelListener.onGroupChannelReadStatusUpdated = function(groupChannel) {
  //triggered when read status is updated
}
channelListener.onGroupChannelUpdated = function(groupChannel) {
  // trigered when a group channel is update
}
channelListener.onGroupChannelParticipantJoined = function(groupChannel, participant){
  // triggered when a participants joins a group channel
}
channelListener.onGroupChannelParticipantLeft = function(groupChannel, participant){
  // triggered when a participant leaves a group channel
}

channelListener.onTotalGroupChannelCount = function(count, totalCountFilterParams){
  // triggered when a total group channel count of the current user changes
}

cc.addChannelListener(CHANNEL_LISTENER_ID, channelListener);

CHANNEL_LISTENER_ID is a unique channel listener id and it is a string.

You may remove a channel listener by using its id as shown below.

cc.removeChannelListener(CHANNEL_LISTENER_ID);

Connection Listener

Connection Listeners are designed to handle events related to the connection status of your application with ChatCamp Cloud.

let connectionListener = new cc.ConnectionListener();

connectionListener.onConnectionChanged = function(isConnected){
  // triggered when connection status is changed
}

cc.addConnectionListener(CONNECTION_LISTENER_ID, connectionListener);

CONNECTION_LISTENER_ID is a unique connection listener id and it is a string.

You may remove a connection listener by using its id as shown below.

cc.removeConnectionListener(CONNECTION_LISTENER_ID);

User Listener

Connection Listeners are designed to handle events related to the current user of your application.

let userListener = new cc.UserListener();

userListener.onTotalUnreadGroupChannelCount = function(count, totalCountFilterParams){
  // triggered when total unread channel count of current user changes
}

userListener.onTotalUnreadMessageCount = function(count, totalCountFilterParams){
  // triggered when total unread messages count of current user changes
}

cc.addUserListener(USER_LISTENER_ID, userListener);

USER_LISTENER_ID is a unique user listener id and it is a string.

You may remove a user-listener by using its id as shown below.

cc.removeUserListener(USER_LISTENER_ID);