Callback Listeners

Add Callback Event 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.

Helper Object#

For getting the logged-in user display name in the SDK, You need to implement the following helper object in your code. The helper should have the following methods implemented.

function getDisplayName() {}

This should return the display name of the logged-in user.

Sample Implementation:#

let callbackObject = {
...,
helper: {
getDisplayName: () => return displayName
}
}

Incoming Call Listener#

When a user receives the incoming call, this callback event called.

function incomingCallListener(response) {}

Sample Response:#

// Response Structure
{
allUsers:["USER1_JID", "USER2_JID",...],
callMode: "onetoone|onetomany",
callTime: 1681905421215,
callType: "audio|video",
from: "USER_JID|FROM_USER_JID",
groupId: null|GROUP_ID,
localUser: BOOLEAN,
roomId: "wmupbheao",
roomLink: "ndy-bmkb-eui"
status: "calling",
to: "FROM_USER_JID|GROUP_JID",
toUsers: ["USER_JID"],
userDetails: {},
userJid: "FROM_USER_JID",
usersStatus: [{}]
}

Response Property Details:#

ArgumentsDescription
allUsersJID's of the users in the call.
callTimeCall intiated time in timestamp format.
callTypeDescribe the audio or video call.
groupIdContain the group ID If the call is group call. Otherwise, the value will be NULL.
localUserTo determine local user or not
roomIdCall room ID.
roomLinkCall room Link.
statusStatus of the call(calling, ringing, connecting, connected).
toUsersArray of User JID of callee users.
userDetailsUser details object of the callee users.
userJidUser JID who intiated the call
usersStatusArray of users with the details of the call.
fromOne to one call User JID of callee users / One to many call User JID who intiated the call.
toOne to one call User JID who intiated the call / One to many call Group JID.
callModeMode of call.

Call Status Listener#

Handles Call Status, triggered whenever user call status changes.

function callStatusListener(response) {}

Sample Response:#

// Response Structure
{
localUser: 'BOOLEAN',
sessionStatus: null|'closed',
status: "ringing|connecting|connected|busy|engaged|ended|reconnecting|disconnected|hold",
userJid: "FROM_USER_JID",
usersStatus: "USERS_ARRAY_OF_OBJECT"
}

Response Property Details:#

PropertyDescription
statususer call status.
userJidFrom user JID
localUserUser JID is current logged in user or another user.
sessionStatusDescribe whether the call is closed or not.
If the value is CLOSED means, no user in the call & call is disconnected completely. Otherwise call is in progress.
usersStatusArray of users with call details.

Possible Status:#

StatusDescription
ringingCallee user received the incoming call payload & Acknowledged it.
connectingUser attended the received the call
connectedConnection is established between the users
reconnectingThere is a problem in connection between users
engagedWhen a user is in another call
busyWhen a user disconnect the in ringing state
disconnectedUser disconnect from the call
endedWhen another user ended the call
holdWhen user hold the call

User Track Listener#

In this listener, Receive the local & remote users audio & video tracks. We have localUser property to differentiate the remote & local users.

function userTrackListener(response) {}

Sample Response:#

// Response Structure
{
localUser: 'BOOLEAN',
track: 'TRACK_OBJECT',
trackType: "audio|video",
userJid: "FROM_USER_JID",
usersStatus: "USERS_ARRAY_OF_OBJECT"
}

Response Property Details:#

PropertyDescription
localUserIdentify whether the track is belongs to local or remote user
true - Local user
false - Remote user.
trackTrack object
trackTypeContain audio or video to identify type of track.
userJidFrom user JID
usersStatusArray of users with call details.

Sample Javascript code to play the track#

<html>
<audio id="audio" autoplay playsinline></audio>
<video id="video" autoplay playsinline></video>
<script>
//let track = TRACK_OBJECT from the callback method
//let element = ELEMENT_OBJECT in which you need to play the audio/video
let stream = new MediaStream([track]);
try {
element.srcObject = stream;
} catch (e) {
try {
element.src = URL.createObjectURL(stream);
} catch (e) {
console.error("Error attaching stream to element", e);
}
}
</script>
</html>

You need to supply the track object which was received in the callback method to the audio/video element based on the track type that you have received.

note

You need to have multiple Audio and Video tag element to play all user's audio and video.

warning

For the Audio/Video call, you shouldn't play your own Audio track.

Mute Status Listener#

Whenever a user mute/unmute the video/audio, this event listener will be called with mute/unmute status details.

function muteStatusListener(response) {}

Sample Response:#

// Response Structure
{
isMuted: 'BOOLEAN',
trackType: "audio|video",
userJid: "FROM_USER_JID"
}

Response Property Details:#

PropertyDescription
isMutedIndetify whether the track is muter/unmuted.
true - Muted
false - Unmuted.
trackTypeContain audio or video to identify type of track is muted/unmuted.
userJidFrom user JID.

Call Switch Listener#

When a user Request, Cancel, Accept & Decline a video call switch process, this event listener will be called with status information.

function callSwitchListener(response) {}

Sample Response:#

// Response Structure
{
localUser: 'BOOLEAN',
status: "request|cancel|accept|decline|timeout",
userJid: "FROM_USER_JID",
usersStatus: "USERS_ARRAY_OF_OBJECT"
}

Response Property Details:#

PropertyDescription
statusStatus of the call switch process.
userJidFrom user JID.
localUserUser JID is current logged in user or another user
usersStatusArray of users with the details of the call.

Possible Status:#

StatusDescription
requestWhen a user initiate the call switch request, the current user will receive the request status
cancelWhen a user who initiate the call switch cancel the request, the current user will receive the cancel status
acceptWhen a user accept the request, the call switch initiator will receive the accept status
declineWhen a user decline the request, the call switch initiator will receive the decline status
timeoutNo response from user

Invite Users Listener#

When a user who is already in the call invite the new users and the rest of the users who are already in call will receive the invited users details in this callback event listener.

The invited users will receive the incoming call in ["incomingCallListener"] callback listener.

function inviteUsersListener(response) {}

Sample Response:#

// Response Structure
{
allUsers: ["USER1_JID", "USER2_JID",...],
callTime: 1681905421215,
callType: "audio|video",
groupId: null|'GROUP_ID',
inviteUsers: [], // Users JID who are invited
roomId: "awhiyay",
status: "inviteusers",
toUsers: [], // Users JID Who are all the in call currently
userJid: "FROM_USER_JID"
}

Response Property Details:#

PropertyDescription
allUsersArray of User JID of caller & callee users.
callTimeCall intiated time in timestamp format.
callTypeDescribe the audio or video call.
groupIdContain the group ID If the call is group call. Otherwise, the value will be NULL.
roomIdCall room ID.
inviteUsersArray of User JID who are invited.
statusStatus of the call.
toUsersArray of User JID who are all in the call currently.
userJidUser JID who intiated the call

Missed Call Listener#

When a user already in call & the same user receives a call from the third user, this second call will be consider as a missed call & at this time this event will be called with second call details.

function missedCallListener(response) {}

Sample Response:#

// Response Structure
{
callTime: 1681905421215,
callType: "audio|video",
groupId: null|`GROUP_ID`,
roomId: "wmupbheao",
status: "calling",
toUsers: ["USER_JID"]
userJid: "FROM_USER_JID"
}

Response Property Details:#

PropertyDescription
callTimeCall intiated time in timestamp format.
callTypeDescribe the audio or video call.
groupIdContain the group ID If the call is group call. Otherwise, the value will be NULL.
roomIdCall room ID.
statusStatus of the call(calling).
toUsersArray of User JID of callee users.
userJidUser JID who intiated the call

Media Error Listener#

When user deny the audio/video browser permission or audio/video devices are not able to read by browser, at the time this event will be called with error details.

function mediaErrorListener(response) {}

Sample Response:#

// Response Structure
{
action: "makeCall",
device: "camera",
error: "NotAllowedError",
statusCode: "STATUS_CODE"
message: "Permission denied",
userJid: "FROM_USER_JID"
}

Response Property Details:#

PropertyDescription
actionIn which action error occurred(makeCall, answerCall, videoUnMute, callSwitch).
deviceName of the device which has error (mic, camera, mic & camera)
errorDescribe the error type
statusCodeStatus Code
messageError meesage

Possible Error:#

ErrorDescription
NotAllowedErrorPermission denied.
NotFoundErrorRequested device not found or readable.

Call Speaking Listener#

Handles the audio level, triggered whenever there is a change in the audio level of the current user or any other users on the call.

function callSpeakingListener(response) {}

Sample Speaking Response:#

// Response Structure
{
isSpeaking: "true|false"
localUser: "true|false"
userJid: "FROM_USER_JID"
volumeLevel: 3
}

Response Property Details:#

PropertyDescription
userJidSpeaking user JID
isSpeakingWhether the user is speaking or not
localUserSpeaking user JID is current logged in user or another user.
volumeLevelVolume level is at which the user is speaking. Based on this level you can show the mic indicator for a particular user. Possible values will be between 0 to 10. When the value is 0, it’s referred to as the silent. When the value is 10, it’s referred to as the loudest.

Call Users Update Listener#

When there is an update in the users list of the call, callUsersUpdateListener() will be triggered with the list of the users on the call. You can update the UI based on this callback. When the list is empty, then the call is ended. So you can discard your UI.

function callUsersUpdateListener(response) {}

Sample Call Users Update Response:#

// Response Structure
{
userJid: "FROM_USER_JID",
localUser: true,
usersList: ["USER_JID", "USER_JID"]
}

Response Property Details:#

PropertyDescription
userJidUser JID of current user
localUserUser JID is current logged in user or another user
usersListList of users on the call

Call User Joined Listener#

Call user joined listener callUserJoinedListener() will be triggered when a new user joined into the call. You can use this method to show user joined toast in the UI.

function callUserJoinedListener(response) {}

Sample Call User Joined Response:#

// Response Structure
{
userJid: "USER_JID",
localUser: false
}

Response Property Details:#

PropertyDescription
userJidUser JID of the user who joined the call
localUserUser JID is current logged in user or another user.

Call User Left Listener#

Call user left listener callUserLeftListener() will be triggered when a user left the call. You can use this method to show user left toast in the UI.

function callUserLeftListener(response) {}

Sample Call User Left Response:#

// Response Structure
{
userJid: "USER_JID",
localUser: false
}

Response Property Details:#

PropertyDescription
userJidUser JID of the user who left the call
localUserUser JID is current logged in user or another user.