Making a call

Call feature is essential for the modern day communication. Call sdk allows users to make a audio/video call with the another sdk users.

warning

Before making the call, make sure you have implemented the helper object.

Make a voice call#

Initiate a call by providing the callee’s user JID into the makeVoiceCall method. Once the call initiated successfully, a callStatusListener callback will be triggered and callee user call status will be received here.

caution

If One to one call feature is unavailable for your plan, then it will throw 403 exception

SDK.makeVoiceCall(['USER_JID'], null, metadata, (success, error) => {
if (error) {
// Error occured while making the call
}
if (success) {
// Call has been made successfully
}
});

Request Params#

ParamDescriptionTypeRequired
USER_JIDUser JIDArraytrue
GROUP_IDGroup Id - For one to one calls, provide null.Stringfalse
metadatametadata - is an optional parameter to provide Metadata of call. Maximum size is 3. Example : {key : value}Objectfalse
callbackCallback method to handle success and error while making the callMethodfalse
note

A metadata object key and value should both be strings.

success#

{
statusCode: 200, // Number - status code
message: "", // String - Success/Error Message
callType: "", // String - Call Type - "audio"
roomId: "" // String - Unique room ID
}
note

To receive the user track, a userTrackListener callback should already be registered in the caller's client app. Whenever you make the call to a user, you will receive your own track and the callee's track in the same callback method. To differentiate the user, You can use the 'localUser' and 'userJid' param. You will receive both Audio and Video track in the same callback method.

Sample Javascript code to play the track#

<html>
<audio id="audio" autoplay playsinline></audio>
<script>
//let track = TRACK_OBJECT from the callback method
//let element = ELEMENT_OBJECT in which you need to play the audio
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 element based on the track type that you have received.

warning

You shouldn't play your own Audio track.

Make a video call#

Initiate a call by providing the callee’s user JID into the makeVideoCall method. Once the call initiated successfully, a callback callStatusListener will be triggered and callee user call status will be received here.

caution

If One to one call feature is unavailable for your plan, then it will throw 403 exception

SDK.makeVideoCall(['USER_JID'], null, metadata, (success, error) => {
if (error) {
// Error occured while making the call
}
if (success) {
// Call has been made successfully
}
});

Request Params#

ParamDescriptionTypeRequired
USER_JIDUser JIDArraytrue
GROUP_IDGroup Id - For one to one calls, provide null.Stringfalse
metadatametadata - is an optional parameter to provide Metadata of call. Maximum size is 3. Example : {key : value}Objectfalse
callbackCallback method to handle success and error while making the callMethodfalse
note

A metadata object key and value should both be strings.

success#

{
statusCode: 200, // Number - status code
message: "", // String - Success/Error Message
callType: "", // String - Call Type - "video"
roomId: "" // String - Unique room ID
}
note

To receive the user track, a userTrackListener callback should already be registered in the caller's client app. Whenever you make the call to a user, you will receive your own track and the callee's track in the same callback method. To differentiate the user, You can use the 'localUser' and 'userJid' param. You will receive both Audio and Video track in the same callback method.

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 element based on the track type that you have received.

warning

You shouldn't play your own Audio track.

Make a group voice call#

Initiate a call by providing the callee’s user JID & Group ID into the makeVoiceCall method. Once the call initiated successfully, a callStatusListener callback will be triggered and callee user call status will be received here.

caution

If GroupCall feature is unavailable for your plan, then it will throw 403 exception

SDK.makeVoiceCall(['USER1_JID', 'USER2_JID'...], 'GROUP_ID', metadata, (success, error) => {
if (error) {
// Error occured while making the call
}
if (success) {
// Call has been made successfully
}
});

Request Params#

ParamDescriptionTypeRequired
USER_JIDUser's JIDArraytrue
GROUP_IDGroup IDStringtrue
metadatametadata - is an optional parameter to provide Metadata of call. Maximum size is 3. Example : {key : value}Objectfalse
callbackCallback method to handle success and error while making the callMethodfalse
note

A metadata object key and value should both be strings.

success Format#

{
statusCode: 200, // Number - status code
message: "", // String - Success/Error Message
callType: "", // String - Call Type - "audio"
roomId: "" // String - Unique room ID
}
note

To receive the user track, a userTrackListener callback should already be registered in the caller's client app. You will receive all users Audio track in the same callback method. To differentiate the user, You can use the 'localUser' and 'userJid' param.

note

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

Make a group video call#

Initiate a call by providing the callee’s user JID & Group ID into the makeVideoCall method. Once the call initiated successfully, a callback callStatusListener will be triggered and callee user call status will be received here.

caution

If GroupCall feature is unavailable for your plan, then it will throw 403 exception

await SDK.makeVideoCall(['USER1_JID', 'USER2_JID'...], 'GROUP_ID', metadata, (success, error) => {
if (error) {
// Error occured while making the call
}
if (success) {
// Call has been made successfully
}
});

Request Params#

ParamDescriptionTypeRequired
USER_JIDUser's JIDArraytrue
GROUP_IDGroup IDStringtrue
metadatametadata - is an optional parameter to provide Metadata of call. Maximum size is 3. Example : {key : value}Objectfalse
callbackCallback method to handle success and error while making the callMethodfalse
note

A metadata object key and value should both be strings.

success#

{
statusCode: 200, // Number - status code
message: "", // String - Success/Error Message
callType: "", // String - Call Type - "video"
roomId: "" // String - Unique room ID
}
note

To receive the user track, a userTrackListener callback should already be registered in the caller's client app. You will receive all users Audio/Video track in the same callback method. To differentiate the user, You can use the 'localUser' and 'userJid' param.

note

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

Receive incoming call#

To receive an incoming call, a incomingCallListener callback should already be registered in the callee’s client app. Whenever a user make call to a user, the callee user will receive the calling data in this callback.

// Callback Response Argument 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 Params#

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.

Answer a call#

To answer a call use the answerCall method.

SDK.answerCall((success, error) => {
if (error) {
// Error occured while answering the call
}
if (success) {
// Call has been answered successfully
}
});

End a call#

To end a call use the endCall method.

SDK.endCall((success, error) => {
if (error) {
// Error occured while ending the call
}
if (success) {
// Call has been ended successfully
}
});

Decline a call#

To decline a call use the declineCall method.

SDK.declineCall((success, error) => {
if (error) {
// Error occured while declining the call
}
if (success) {
// Call has been declined successfully
}
});