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 muteChatListener = (res) => {};
const initializeObj = {
apiBaseUrl: "https://api-preprod-sandbox.mirrorfly.com/api/v1",
licenseKey: "XXXXXXXXXXXXXXXXX",
isTrialLicenseKey: true,
callbackListeners: {
connectionListener,
presenceListener,
userProfileListener,
mediaUploadListener,
singleMessageDataListener,
muteChatListener,
groupProfileListener
},
};
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
}

Receive Message#

Handles when new message received.

{
createdAt: "2024-04-02 12:34:13.601",
msgType: "", // String - value "receiveMessage"
chatType: "", // String - Chat Type "chat"/"groupchat"
publisherJid: "", // String - Jid - One Who Sends the Message
publisherId: "", // String - Id - One Who Sends the Message
fromUserJid: "", // String - From User Jid
fromUserId: "", // String - From User Id
toUserJid: "", // String - Jid - One Who Receives the Message
toUserId: "", // String - To User Id - One Who Receives the Message
msgBody: {
message: "", // String - Message Body
message_type: "", // String - Message Type text, image, video, audio & file
nickName: "", // String - User Nickname
mentionedUsersIds: [] // Array - Mentioned Ids In case of Group
"media": { // For Media Message Only for message_type ['image', 'video', 'file', 'audio']
"msgId": "bafb7847-a4eb-4800-b77f-b268ee0db376", // String - Message Id
"caption": "", // String - Media Caption
"duration": 0, // String - Duration - For Audio/Videos
"webWidth": 330, // Number
"webHeight": 330, // Number
"androidWidth": 250, // Number
"androidHeight": 250, // Number
"originalWidth": 960, // Number
"originalHeight": 960, // Number
"thumbImage": "", // Base64 - Thumb Image
"file_size": 811814,
"fileName": "", // String - File Name
"file_url": "", // String - File Url
"thumb_image": "", // Base64 - Thumb Image
"local_path": "", // String - Local Path
"is_uploading": 2, // Number - Uploading Status
"is_downloaded": 0 // Number - Downloaded Status
},
"location": { // For Location Message Only ['location']
"mid": "0554ca74-a5c0-4bcc-8cb3-01055d033337",
"latitude": "13.0122057",
"longitude": "80.2094575"
}
"contact": { // For Contact Message Only ['contact']
"mid": "fc524a2f-a342-4c94-827d-e89d0a865503",
"name": "",
"phone_number": [""],
"active_status": ["0"]
}
"nickName": ""
},
metaData: {}, //Object - Meta data for the message
msgId: "", // String - Message Id
topicId: "", //String - Topic Id for the message
msgStatus: "", // Number - Message Status
timestamp: 1681185232284, // Number - TimeStamp - Milliseconds
editedStatus: 0, // Number - Edited status - 0 or 1
}

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

Group Created#

Received when group created.

{
"msgId": "groupCreated116344c8-3c5d-41be-8afc-aca925f43578",
"msgBody": {
"message_type": "notification",
"message": "1",
"notificationContent": "You created this group"
},
"chatType": "groupchat",
"publisherId": "VTyXI0hbnZQSilGvxzf1X6AXm6",
"msgType": "groupCreated",
"timestamp": 1712056731668,
"msgStatus": 0,
"fromUserId": "116344c8-3c5d-41be-8afc-aca925f43578",
"fromUserJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"publisherJid": "VTyXI0hbnZQSilGvxzf1X6AXm6@domain",
"profileDetails": {
"nickName": "Gg full"
}
}

User Added#

Received when user added.

{
"msgId": "7704306614779329674",
"msgBody": {
"message_type": "notification",
"message": "2",
"notificationContent": "You added VTyXI0hbnZQSilGvxzf1X6AXm6vHdC"
},
"chatType": "groupchat",
"publisherId": "VTyXI0hbnZQSilGvxzf1X6AXm6",
"msgType": "groupProfileUpdated",
"profileUpdatedStatus": "userAdded",
"timestamp": 1712056731853,
"msgStatus": 0,
"fromUserId": "116344c8-3c5d-41be-8afc-aca925f43578",
"fromUserJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"toUserId": "VTyXI0hbnZQSilGvxzf1X6AXm6vHdC",
"publisherJid": "VTyXI0hbnZQSilGvxzf1X6AXm6@domain",
"toUserJid": "VTyXI0hbnZQSilGvxzf1X6AXm6vHdC@domain",
"userType": "n",
"userJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain"
}

User Removed#

Received when user removed.

{
"msgId": "11644556668499755749",
"msgBody": {
"message_type": "notification",
"message": "3",
"notificationContent": "You removed vtyxi0hbnzqsilgvxzf1x6axm6vhdc"
},
"chatType": "groupchat",
"publisherId": "vtyxi0hbnzqsilgvxzf1x6axm",
"msgType": "groupProfileUpdated",
"profileUpdatedStatus": "userRemoved",
"timestamp": 1712059828842,
"msgStatus": 0,
"toUserId": "vtyxi0hbnzqsilgvxzf1x6axm6vhdc",
"toUserJid": "vtyxi0hbnzqsilgvxzf1x6axm6vhdc@domain",
"fromUserId": "116344c8-3c5d-41be-8afc-aca925f43578",
"publisherJid": "vtyxi0hbnzqsilgvxzf1x6axm@domain",
"fromUserJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"userJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"userId": "116344c8-3c5d-41be-8afc-aca925f43578"
}

User Updated Profile#

Received when user updated the group profile.

{
"msgId": "259889771358480632",
"msgBody": {
"message_type": "notification",
"message": "4",
"notificationContent": "You updated this group profile"
},
"chatType": "groupchat",
"publisherId": "vtyxi0hbnzqsilgvxzf1x6axm",
"msgType": "groupProfileUpdated",
"profileUpdatedStatus": "profileUpdated",
"timestamp": 1712060428365,
"msgStatus": 0,
"toUserId": "",
"toUserJid": "",
"fromUserId": "116344c8-3c5d-41be-8afc-aca925f43578",
"publisherJid": "vtyxi0hbnzqsilgvxzf1x6axm@domain",
"fromUserJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"userId": "116344c8-3c5d-41be-8afc-aca925f43578",
"userJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain"
}

User Admin#

Received when user admin.

{
"msgId": "731342043013962342",
"msgBody": {
"message_type": "notification",
"message": "5",
"notificationContent": "`Username` is now an admin"
},
"chatType": "groupchat",
"publisherId": "vtyxi0hbnzqsilgvxzf1x6axm",
"msgType": "groupProfileUpdated",
"profileUpdatedStatus": "madeAdmin",
"timestamp": 1712060116402,
"msgStatus": 0,
"toUserId": "wjksd3kwwsz8fbmggtujq9ahu4u2",
"toUserJid": "wjksd3kwwsz8fbmggtujq9ahu4u2@domain",
"userId": "116344c8-3c5d-41be-8afc-aca925f43578",
"userJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"fromUserId": "116344c8-3c5d-41be-8afc-aca925f43578",
"fromUserJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"publisherJid": "vtyxi0hbnzqsilgvxzf1x6axm@domain"
}

User Left#

Received when user left.

{
"msgId": "16921955963619786584",
"msgBody": {
"message_type": "notification",
"message": "6",
"notificationContent": "`Username` left "
},
"chatType": "groupchat",
"publisherId": "vtyxi0hbnzqsilgvxzf1x6axm",
"msgType": "groupProfileUpdated",
"profileUpdatedStatus": "userLeft",
"timestamp": 1712059957492,
"msgStatus": 0,
"toUserId": "vtyxi0hbnzqsilgvxzf1x6axm",
"toUserJid": "vtyxi0hbnzqsilgvxzf1x6axm@domain",
"fromUserId": "116344c8-3c5d-41be-8afc-aca925f43578",
"publisherJid": "vtyxi0hbnzqsilgvxzf1x6axm@domain",
"fromUserJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"userJid": "116344c8-3c5d-41be-8afc-aca925f43578@mix.domain",
"userId": "116344c8-3c5d-41be-8afc-aca925f43578"
}

Note: To handle notification types in UI click here

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": ""
},
"metaData": {}, //Object - Meta data for the message
"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 Group Created#

When a new group is created and a user is added as a participant, triggering the groupProfileListener callback, it also responds to the addition of users with the userAdded

{
"newUserJid": "vtyxi0hbnzqsilgvxzf1x6axm@domain",
"groupJid": "95e9e3b0-872d-47c1-907e-dd18116e52ed@mix.domain",
"groupId": "95e9e3b0-872d-47c1-907e-dd18116e52ed",
"groupName": "Goo",
"msgType": "groupCreated",
"publisherProfile": {
"image": "",
"nickName": "",
"email": "mirrorflyplayer@gmail.com",
"status": "I am in Mirror Fly",
"mobileNumber": ""
},
"timestamp": 1712062398256,
"publisherJid": "vtyxi0hbnzqsilgvxzf1x6axm@domain",
"groupProfile": {
"nickName": "Goo",
"userId": "95e9e3b0-872d-47c1-907e-dd18116e52ed",
"userJid": "95e9e3b0-872d-47c1-907e-dd18116e52ed@mix.domain"
}
}

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

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: 1681185232284, // Number - TimeStamp - Milliseconds
groupProfile: {
nickName: "", // String - Group Nick Name
image: "", // String - Group Image
thumbImage: "" // String - Group ThumbImage
}
}

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

Mute Chat Listener#

Handles Chat Mute Status, triggered when the particular single 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
}