Audio Calling

To add Audio Calling support in your application,

Include CustomUI.js in your index.html file to access the Custom UI functionality in your Cordova app

All the method calls will invoke their respective callback blocks as defined below.

1. Send call request
Send Audio call request to the userID specified. (Ensure that userID cannot be nil or empty)


function callbackmeth(result){

  alert(result);

}

CustomUI.sendAudioChatRequestToUser("5",callbackmeth);

(i).
Invocation: After audio call request is sent successfully
Response: Callback containing id of the user to whom audio call request has been sent
Eg:

"success"={
  callID = "\"474a3e0baf0e3db251a2bc2a6a5b31a5\"";  
  userID = 5;
}

2. Accept call request
Accept audio call request when AUDIO_INCOMING_CALL message is received in the onAVChatMessageReceived callback block. (Ensure that userID & callID specified should be same as userID & callID received in AUDIO_INCOMING_CALL message respectively. Also userID & callID cannot be nil or empty)


function callbackmeth(result){

  alert(result);

}

CustomUI.acceptAudioChatRequestOfUser("6","474a3e0baf0e3db251a2bc2a6a5b31a5",callbackmeth);

Invocation: After sending audio call acknowledgement request successfully
Response: Callback containing id of the user to whom audio call acknowledgement has been sent
Eg:

"success"={  
 userID = 6;
}

3. Start audio call
Start an audio call within the container view. This function has to be called after sending/accepting audio call request only. (Ensure that userID & callID specified here should be the same while sending/accepting the request. Also userID & callID cannot be nil or empty)


function callbackmeth(result){

  alert(result);

}

CustomUI.startAudioChatWithCallID("6","474a3e0baf0e3db251a2bc2a6a5b31a5",callbackmeth);

Invocation: After starting audio call successfully
Response: Callback containing success message
Eg:

"success"={  
 "Connected user" = "1";
}

4. End call
End audio call with the user corresponding to userID specified. (Ensure that userID specified should be same as given when starting the audio call and also userID cannot be nil or empty)


function callbackmeth(result){

  alert(result);

}

CustomUI.endAudioChatWithUser("6",callbackmeth);

Invocation: After ending audio call successfully
Response: Callback containing id of the user with whom audio call has been ended
Eg:

"success"={  
 callID = 474a3e0baf0e3db251a2bc2a6a5b31a5;
 userID = 6;
}

5. Cancel call
Cancel audio call after sending a call request. (Ensure that userID specified should be same as given when sending the audio call request and also userID cannot be nil or empty)


function callbackmeth(result){
   alert(result);
}

CustomUI.cancelAudioChatRequestWithUser("6",callbackmeth);

Invocation: After cancelling audio call successfully
Response: NSDictionary containing id of the user with whom audio call has been cancelled
Eg:

"success"={  
  userID = 6;
}

6. Send busy call
Send busy call when AUDIO_INCOMING_CALL_USER_BUSY message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AUDIO_INCOMING_CALL_USER_BUSY message and also userID cannot be nil or empty)


function callbackmeth(result){
   alert(result);
}
CustomUI.sendBusyCallToUser("5",callbackmeth);

Invocation: After sending busy call successfully
Response: NSDictionary containing id of the user to whom busy tone has been sent
Eg:

"success"={  
  userID = 6;
}

7. Reject call
Reject audio call request when AUDIO_INCOMING_CALL message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AUDIO_INCOMING_CALL message and also userID cannot be nil or empty)


function callbackmeth(result){
   alert(result);
}

CustomUI.rejectAudioChatRequestOfUser("5",callbackmeth);

Invocation: After rejecting audio call successfully
Response: NSDictionary containing id of the user whose incoming audio call request has been
rejected
Eg:

"success"={ 
 callID = 474a3e0baf0e3db251a2bc2a6a5b31a5; 
 userID = 5;
}

8. Toggle Audio to ON(YES) or OFF(NO) state


function callbackmeth(result){
  alert(result);
}

CustomUI.toggleAudioSDK(true,callbackmeth);

9. Switch audio route to Ear-piece/Speaker


function callbackmeth(result){
  alert(result);
}

CustomUI.switchAudioRoute();

Please refer ‎error codes for failure responses.

Not finding what you need?

The CometChat team is here to help!