Callback listeners

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

Example Request#

const connectionListener = (res) => {};
const presenceListener = (res) => {};
const userProfileListener = (res) => {};
const messageListener = (res) => {};
const mediaUploadListener = (res) => {};
const mediaDownloadListener = (res) => {};
const singleMessageDataListener = (res) => {};
const groupProfileListener = (res) => {};
const initializeObj = {
apiBaseUrl: "https://api-preprod-sandbox.mirrorfly.com/api/v1",
licenseKey: "XXXXXXXXXXXXXXXXX",
isTrialLicenseKey: true,
callbackListeners: {
connectionListener,
presenceListener,
userProfileListener,
mediaUploadListener,
singleMessageDataListener,
},
};
await SDK.initializeSDK(initializeObj);

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("SDK has connected to the server successfully.");
} else if (response.status === "DISCONNECTED") {
console.log("SDK has disconnected and lost the session. Reconnection was automatically called by the SDK.");
} else if (response.status === "CONNECTIONFAILED") {
console.log("SDK has failed to connect to the server.");
} else if (response.status === "RECONNECTING") {
console.log("SDK has started reconnecting to the server.");
}
}

Sample Response:

{
status: "CONNECTED";
}

Possible Status:

StatusDescription
CONNECTEDConnection Established
DISCONNECTEDDisconnected
CONNECTIONFAILEDConnection Failed

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
}

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);
}

Sample Response:

{
type:"",// string type
msgId:"",//string msgId
fromUserJid:"",//String - from User Jid
fromUserId:"",//string fromUserId
msgType:"",// string msgType
timestamp:'',//number timestamp
msgStatus:'',//number msgStatus
publisherId:""//string publisherId
}

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

Acknowledgement#

An acknowledgement 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 : "", // Number - Message Status
publisherId: "", //​ String - Publisher Id - One Who Sends the Message
timestamp: 1681185232284 // Number - TimeStamp - Milliseconds
}

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: 1681185232284 // Number - TimeStamp - Milliseconds
}

Seen Status#

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: 1681185232284 // Number - TimeStamp - Milliseconds
}

Deleted Message#

Received when message is delete (Delete For Me).

{
chatType: "", // String - Chat Type - "chat" - Single - "groupchat" - Group
fromUserId: "", // String - From User Id
lastMsgId : "" //String
msgIds: [], // Array - Message Ids
msgType: "", // String - value "deleteMessage"
}

Received when message is delete (Delete For Everyone).

{
chatType: "" // String - Chat Type "chat"/"groupchat" - exists only in recipient side
fromUserId: "", // String - From User Id (Without Domain)
fromUserJid: "", // String - From User Jid (With Domain & Resource)
msgId: "", // String - Message Id
msgType: "", // String - value "recallMessage" for recipient, Incase of sender - value is "acknowledge"
timestamp: 1681185232284, // Number - TimeStamp - Milliseconds
type: "", // String - value "recall" - exists only in SingleChat(sender side)
}

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)
lastMsgId: "" // String - Last Message Id for ClearChat. In case of deleteChat means, it will be null
favourite: "" //String - value "0" or "1"
}

Clear/Delete All Chat#

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

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

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"
}

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
progress: '', // number progress percentage
local_path: '', // String - local_path
};

Media Download Listener#

Handles Media Message download progress triggered when media message in download. Receives an Object values.

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

Sample Response:

{
  msgId: '',// String - Message Id
  progress: '',// number progress percentage
  local_path: '',// String - local_path
};

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);
}

Sample Response:

{
"chatType": "chat",
"createdAt": "",//string -Create at date
"deleteStatus": 0,
"deletedBy": "0",
"fromUserId": "",//string-fromUserId
"fromUserJid": "",//string-fromUserJid
"msgBody": {
"nickName": "",
"mid": "",//string-mid
"message": "",//string- Media message
"message_type": "text",
"replyTo": "",
"mentionedUsersIds": ""
},
"msgId": "",//string-mid
"msgStatus": 0,
"msgType": "text",
"profileUpdatedStatus": "",
"publisherId": "",//string-publisherId
"publisherJid": "",//string-publisherJid
"timestamp": "",//number-publisherJid
"userId": "",//string-userId
"userJid": ""//string-userJid
}

Group Profile Listener#

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

function groupProfileListener(response) {
console.log("Group Profile 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:

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