Callback listeners

Add all following callback methods while initializing the SDK. Callback listeners are functions that will be called whenever the specified event happens.

Note: Callback Listener name should be the same as described below.

Connection Listener#

Handles Connection Status, triggered whenever connection status changes.

function connectionListener(response) {
if (response.status === "CONNECTED") {
console.log("Connection Established");
} else if (response.status === "DISCONNECTED") {
console.log("Disconnected");
}
// Remaining Cases goes here
}

Sample Response:

{
status: "CONNECTED";
}

Possible Status:

StatusDescription
CONNECTEDConnection Established
DISCONNECTEDDisconnected
CONNECTIONTIMEOUTConnection Timeout
CONNECTIONFAILEDConnection Failed
AUTHENTICATIONFAILEDAuthentication Failed
ERROROCCUREDError

Presence Listener#

Handles Presence Status of Friends, triggered whenever users online/offline status changes.

function presenceListener(response) {
console.log("Presence Listener", response);
}

Sample Response:

{
fromUserJid: "", // String - Jid of the User
status: "", // String - "online"/"unavailable" Status
}

FriendsList Listener#

Handles Friends List (Contacts) Stanzas, triggered when Get Friends method called. Receives an array of object values.

function friendsListListener(response) {
console.log("Friends List", response);
}

Sample Response:

[
{
userJid: "", // String - Jid of the User
userId: "", // String - User Id
name: "", // String - Name of the User (Profile Name)
nickName: "", // String - Display Name of the User (Contact Name)
mobileNumber: "",
image: "", // String - Profile Image of the User
status: "", // String - User Status
isFriend: "", //Boolean
email: "", // String - User Email
isAdminBlocked: false // Boolean - If true - User is blocked by Admin
},
//...
];

User Profile Listener#

Handles User Profile Stanzas, used to get the profile detail of the user. Triggered when Get User Profile method called. Receives object values.

function userProfileListener(response) {
console.log("User Profile Details Listener", response);
}

Sample Response:

{
email: "", // String - User Email
image: "", // String - User Profile Image
fromUser: "", // String - From User Jid
nickName: "", // String - User Nickname
mobileNumber: "", // String - User Mobile Number
status: "", // String - Use Profile Status
userId : "" // String - From User Id (Without Domain)
}

Message Listener#

Handles Message Stanzas, triggered whenever new message related events are received in single/group chat.

function messageListener(response) {
console.log("Message Listener", response);
}

Receive Message#

Handles when new message received.

Sample Response:

{
msgType: "", // String - value "receiveMessage"
chatType: "", // String - Chat Type - "chat" - Single - "groupchat" - Group
publisherJid: "", // String - Jid - One Who Sends the Message
publisherId: "", // String - Id - One Who Sends the Message
fromUserJid: "", // String - From User Jid -
// Will Be Same as PublisherJid in Case of Single Chat
// GroupJid in Case of Group Chat
fromUserId: "", // String - From User Id
toUserJid: "", // String - Jid - One Who Receives the Message
toUserId: "", // String - Jid - One Who Receives the Message
msgBody: {
message: "", // String - Message Body
message_type: "", // String - Message Type text, image, video, audio & file
media: { // For Media Message Only
caption: "", // String - Media Caption
duration: "", // String - Duration - For Audio/Videos
fileName: "", // String - File Name
file_size: "", // Number - File Size
file_url: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
},
msgId: "", // String - Message Id
msgStatus: : "", // Number - Message Status
timestamp: : "", // Number - TimeStamp - 16 Character length
}

For group, message status will be updated only if all the participants sent the delivery/seen status.

Acknowledgment#

An acknowledgment will be sent from the server whenever you sent a message stanzas to the server. For example, when you sent a delivery status to the message that you received, you will get an acknowledgment from the same.

Sample Response:

{
msgType: "", // String - value "acknowledge"
type: "", // String - value "delivery"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
msgId: "", // String - Message Id
msgStatus : "", //
publisherId: "", //โ€‹
timestamp: "" //
}

Delivered Status#

Handles delivery status received from receipient user.

{
fromUserId: "", // String - From User Id/ Group Id (Without Domain)
fromUserJid: "", // String - From User Jid/ Group Jid (With Domain & Resource)
msgId: "", // String - Message Id
msgStatus: 1, // Number - Message Status
msgType: "", // String - value "delivered"
publisherId: "", // String - Publisher Id - One Who Sends the Message
publisherJid: "" // String - Publisher User Jid (With Domain)
timestamp: 0 // Number - TimeStamp - 16 Character length
}

Seen Seen#

Handles seen status received from receipient user.

{
fromUserId: "", // String - From User Id/ Group Id (Without Domain)
fromUserJid: "", // String - From User Jid/ Group Jid (With Domain & Resource)
msgId: "", // String - Message Id
msgStatus: 1, // Number - Message Status
msgType: "", // String - value "seen"
publisherId: "", // String - Publisher Id - One Who Sends the Message
publisherJid: "" // String - Publisher User Jid (With Domain)
timestamp: 0 // Number - TimeStamp - 16 Character length
}

Typing/Gone Status#

Received when user starts/stops typing text message.

Sample Response:

{
msgType: "", // String - value "composing", "gone"
fromUserId: "", // String - From User Id
groupId: "" // String - Group Id / In case of Single Chat - Will be null
}

Deleted Message#

Received when message is delete (Delete For Me).

{
msgType: "", // String - value "deleteMessage"
chatType: "", // String - Chat Type - "chat" - Single - "groupchat" - Group
msgIds: [],
lastMsgId : ""
}

Received when message is delete (Delete For Everyone).

{
msgType: "", // String - value "recallMessage"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
timestamp: 0, // Number - TimeStamp - 16 Character length
msgId: "", // String - Message Id
fromUserId: "", // String - From User Id (Without Domain)
chatType: "" // String - Chat Type "chat"/"groupchat"
}

Clear/Delete Chat#

Received when clear/delete chat method is called.

{
msgType: "", // String - value "clearChat"/"deleteChat"
chatType: "", // String - Chat Type - "chat" - Single - "groupchat" - Group
fromUserId: "" // String - From User Id (Without Domain)
}

Clear/Delete All Chat#

Received when clear all/delete all chat method is called.

{
msgType: "", // String - value "clearAllChat"/"deleteAllChat"
}

Delete Group Chat#

Received when delete group method is called.

{
msgType: "", // String - value "deleteChat"
chatType: "", // String - "groupchat" - Group
fromUserId: "" // String - From User Id (Without Domain)
}

Logout#

When user tries to log in with another device using same credentials, then the 1st user receives logout message. (In order to logout the user).

Note: This is applicable for Same resource (Web) only. User can log in simultaneously with Web and Mobile.

{
msgType: "", // String - value "logout"/"carbonLogout"
}

Carbon Messages#

When user is connected to more than one device, Mobile and Web resources. In order to keep all messages upto date, carbon messsages are used. If the target user is online with multiple resources when the original message is sent, the device with highest priority receives the message and sends a carbon message to other resources. By default carbon will be enabled when SDK is initialized

Carbon Receive Message Sample Response:

{
msgType: "", // String - value "carbonReceiveMessage"
msgStatus: "", // String - Message Status
msgId: "" // String - Message Id
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
timestamp: "", // Number - TimeStamp - 16 Character length
chatType: "", // String - Chat Type "chat"/"groupchat"
msgBody: {
media: { // For Media Message Only
caption: "", // String - Media Caption
duration: "", // String - Duration - For Audio/Videos
fileName: "", // String - File Name
file_size: "", // Number - File Size
file_url: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
message: "", // String - Message Body
message_type: "" // String - Message Type
},
publisherId: "", // String - Publisher Id - One Who Sends the Message
publisherJid: "" // String - Publisher User Jid (With Domain)
}

Carbon Sent Acknowledgment Sample Response:

{
msgType: "", // String - value "carbonSentAcknowledge"
type: "", // String - value "delivery"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
msgId: "" // String - Message Id
}

Carbon Typing/Gone Status Sample Response:

{
msgType: "", // String - value "carbonComposing" & "carbonGone"
fromUserJid: "" // String - From User Jid (With Domain & Resource)
}

Carbon Delivered Sample Response:

{
msgType: "", // String - value "carbonDelivered"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
msgId: "" // String - Message Id
timestamp:"", // Number - TimeStamp - 16 Character length
}

Carbon Seen Sample Response:

{
msgType: "", // String - value "carbonSeen"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
msgId: "" // String - Message Id
timestamp:"", // Number - TimeStamp - 16 Character length
}

Carbon Sent Message Sample Response:

{
msgType: "", // String - value "carbonSentMessage"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
msgId: "" // String - Message Id
toUserJid:"", // String - Jid - One Who Receives the Message
toUserId:"", // String - Jid - One Who Receives the Message
timestamp:"", // Number - TimeStamp - 16 Character length
msgBody: {
media: { // For Media Message Only
caption: "", // String - Media Caption
duration: "", // String - Duration - For Audio/Videos
fileName: "", // String - File Name
file_size: "", // Number - File Size
file_url: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
chatType:"" // String - Chat Type - "chat"/"groupchat"
}

Carbon Clear/Delete Message Sample Response:

{
msgType: "", // String - value "carbonClearChat"/"carbonDeleteChat"
userId: "", // String - From User Id (Without Domain)
chatType: "" // String - Chat Type - "chat"/"groupchat"
}

Carbon Clear/Delete All Sample Response:

{
msgType: "", // String - value "carbonClearAllChat"/"carbonDeleteAllChat"
}

Carbon Delete Message Sample Response: (Delete For Me)

{
msgType: "", // String - value "carbonDeleteMessage"
msgIds: "", // Array - Message Id's that are deleted
chatType: "" // String - Chat Type - "chat"/"groupchat"
}

Carbon Delete Message Sample Response: (Delete For Everyone)

{
msgType: "", // String - value "carbonRecallMessage"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
timestamp: 0, // Number - TimeStamp - 16 Character length
msgId: "", // String - Message Id
fromUserId: "", // String - From User Id (Without Domain)
chatType: "" // String - Chat Type "chat"/"groupchat"
}

Carbon Group Delete Sample Response:

{
msgType: "", // String - value "carbonGroupDelete"
groupId: "", // String - Deleted Group Id
}

Carbon SentSeen Sample Response:

{
msgType: "", // String - value "carbonSentSeen"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
msgId: "" // String - Message Id
timestamp:"", // Number - TimeStamp - 16 Character length
}

Carbon SentRecall Sample Response:

{
msgType: "", // String - value "carbonSentRecall"
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
msgId: "" // String - Message Id
timestamp:"", // Number - TimeStamp - 16 Character length
chatType: "" // String - Chat Type - "chat"/"groupchat"
}

Reply Message Listener#

Handles Reply Message IQs, triggered when Get Reply Message method called. Receives an array of object values.

function replyMessageListener(response) {
console.log("replyMessageListener", response);
}

Sample Response:

[
{
chatType: "", // String - Chat Type - "chat"/"groupchat"
deleteStatus: "", // Number - Delete Status
deletedBy: "", // String - Deleted By
fromUserId: "", // String - Reply From User Id
groupId: "",
oldMsgId: "", // String - Old Message Id
replyMsgContent: "", // String - Reply Message Content
replyMsgId: "", // String - Reply Message Id
},
//...
];

Favourite Message Listener#

Handles Favourites Message lists, triggered when favourites status updated. Receives an array of object values.

function favouriteMessageListener(response) {
console.log("favouriteMessageListener", response);
}

Sample Response:

[
{
msgId: "", // String - Message Id
userId: "", // String - User Id
timestamp: "", // Number - TimeStamp - 16 Character length
msgTo: "", // String - Message To
msgBody: "", // String - Message Body
msgStatus: "", // Number - Message Status
favMsgId: "", // String - Favourite Message Id
favDate: "", // String - Favourite Date
chatType: "", // String - Chat Type - "chat"/"groupchat"
fromNotification: "", // String - From Notification
},
//...
];

Group Profile Listener#

Handles Group Profile Listener, triggered when group activities are requested/updated.

function groupProfileListener(response) {
console.log("Group Profile Listener", response);
}

Group Message Info Listener#

Handles Group Msg Info Listener, triggered when get group message info method triggered.

function groupMsgInfoListener(response) {
console.log("Group Message Info Listener", response);
}

New Participant Added#

Whenever new participant is added to group, groupProfileListener callback will be triggered and the following response will be received.

Sample Response:

{
newUserJid: "", // String - New User Jid (With Domain & Resource)
groupJid:"", // String - Group Jid
groupId:"", // String - Group Id
groupName: "", // String - Group Name
msgType: "", // String - Message Type - value ""userAdded""
userProfile: {
image: "", // String - User Image
nickName: "", // String - User Nick Name
email: "", // String - User Email
status: "", // String - User Status
mobileNumber: "" // String - User Mobile Number
},
newUserId: "", // String - New User Id
publisherProfile: {
image: "", // String - User Image
nickName: "", // String - User Nick Name
email: "", // String - User Email
status: "", // String - User Status
mobileNumber: "" // String - User Mobile Number
},
timestamp: "", // Number - TimeStamp - 16 Character length
publisherJid: "", // String - Publisher User Jid (With Domain & Resource)
}

Group Profile Updated#

Handles Group Profile Data Stanzas, triggered when Set Group Profile method called or new group created. Receives an object values.

Sample Response:

{
publisherJid: "", // String - Publisher User Jid
groupJid: "", // String - Group Jid
msgType: "", // String - Message Type - value "profileUpdated"
timestamp: "", // Number - TimeStamp - 16 Character length
groupProfile: {
nickName: "", // String - Group Nick Name
image: "",
}
}

Participant Removed#

Whenever new participant is removed from group, groupProfileListener callback will be triggered and the following response will be received.

Same response will be handled for Exit Group method as well.

Sample Response:

{
userJid: "", // String - Removed/Left User Jid
groupJid: "", // String - Group Jid
itemId: "", // String - Item Id - Unique Id for the Group Participant
msgType: "", // String - Message Type - value "userRemoved"/"userLeft"
publisherJid: "", // String - Publisher User Jid
timestamp: "" /// Number - TimeStamp - 16 Character length
}

Make Admin#

Received when an member becomes admin of the group.

Sample Response:

{
doneBy: "", // String - Id of the User Who Made Member as a Admin
msgType: "", // String - Message Type - value "madeAdmin"
groupJid: "", // String - Group Jid
newAdminJid: "" // String - Member Id Who Became Admin
}

Group Deleted#

Received when an user deletes the group.

Sample Response:

{
msgType: "", // String - Message Type - value "groupDelete"
groupId: "", // String - Group Id
}

Media Upload Listener#

Handles Media Message upload progress, triggered when media message is sent. Receives an object values.

Also handles the cancel request. Whenever you would like to cancel upload of a media message, you can use source.cancel() method to cancel the media content upload. Each cancel source is unique mapped to message id.

function mediaUploadListener(response) {
response.source.cancel("User Cancel");
}

Sample Response:

{
msgId: "", // String - Message Id
source: "", // String - Cancel Source
progress: "", // Number - Upload Progress Percentage
}

Block User Listener#

Handles User Block/Unblock Status, when user connected with 2 resource if one of the resource blocking/unblocking the user, other resource will be notified with this event.

function blockUserListener(response) {
console.log("blockUserListener", response);
}

Sample Response:

[
{
blockedUserId: "", // String - Blocked/Unblocked User Id
msgType: "", // String - Messge Type - "userBlockStatus"
type: "", // String - Block Type - "block_user"/"unblock_user"
},
//...
];

Single Message Data Listener#

Handles User Block/Unblock Status, when user connected with 2 resource if one of the resource blocking/unblocking the user, other resource will be notified with this event.

function singleMessageDataListener(response) {
console.log("singleMessageDataListener", response);
}

Mute Chat Listener#

Handles Chat Mute Status, triggered when the particular single/group chat is muted/unmuted.

function muteChatListener(response) {
console.log("Mute Chat Listener", response);
}

Sample Response:

{
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
isMuted: false // Boolean
type: "" // String - To identify the response recevied from another resource or not
}

Archive Chat Listener#

Handles Chat Archive Status, triggered when the particular single/group chat is archived/unarchived.

function archiveChatListener(response) {
console.log("Archive Chat Listener", response);
}

Sample Response:

{
fromUserJid: "", // String - From User Jid (With Domain & Resource)
fromUserId: "", // String - From User Id (Without Domain)
isArchived: true // Boolean
type: "" // String - To identify the response recevied from another resource or not
}

Admin User/Group Block/Unblock Listener#

This feature is used to get the users/groups admin blocked status. So that you can check the user/group avail status and communicate them.

function adminBlockListener(response) {
console.log("Archive Chat Listener", response);
}

Sample Response:

{
toUserJid: "", // String - To User Jid (With Domain)
toUserId: "", // String - To User Id (Without Domain)
blockStatus: "1" // "1" - Blocked, "0" - Unblocked
chatType: "" // String - Chat Type - "chat"/"groupchat"
type: "" // String
}

Own User Blocked/Unblocked#

The block/unblock status of own user (Logged In) by Admin will be received, so that you can navigate the user to show stopper screen. Once user blocked by admin, they cannot use the application.

Contact User Blocked/Unblocked#

The block/unblock status of other user by Admin will be received, so that you can show the status as user not available. And you cannot send messages to the blocked users.

Group Chat Blocked/Unblocked#

The block/unblock status of group chat by Admin will be received, so that you will be notified the group profile status. So that we cannot restrict the access to the group.