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
To start with Audio call, you need to sent request to other user. The syntax is as follows:

Customui.sendAudioChatRequestToUser(userID,successCallback,failCallback);

The success response will send you following response containing the user id to whom you have sent the request:

{ "id":"15", "callid":"bf1e7055f8e15d6f8662c7c4b6f8adb9"}

Callid is the identity assigned to your call, you need to maintain this callid and use it when you start or end the call.
You may get callid empty “” in successCallback.

2. Accept call request
If any user has sent you a call request, you can accept it by using acceptAudioChatRequest() function. The syntax is as follows:

Customui.acceptAudioChatRequestOfUser(userID,callID,successCallback,failCallback);

Pass the user id from whom you have received the request. You will get success response containing the user id whose request you have accepted.

{ "id":"15"}

3. Reject call request
You can reject any incoming call request by using rejectAudioChatRequest() function. The syntax is as follows:

Customui.rejectAudioChatRequestOfUser(userID,callID,successCallback,failCallback);

Pass the user id from whom you have received the request. Pass the callid you receive from the request you received in onAvchatMessageReceived() callback. You will get success response containing the user id whose request you have rejected.

{ "id":"15"}

4. Cancel request
You can cancel the call request which you have sent by using the function cancelAudioChatRequest() function, the syntax is as follows:

Customui.cancelAudioChatRequestWithUser(userID,successCallback,failCallback);

Pass the user id to whom you have made the request. You will get success response containing the user id whose request you have cancelled.

{ "id":"15"}

5. Start the call
Once the call request is accepted by other user or by you, you can start the call by using the function startAudioChatCall(). The syntax is as follows:

Customui.startAudioChatWithCallID(callID,container,successCallback,failCallback);

Here the container is the relative layout. You have to pass the correct callid you received while sending the request or when someone sends you the request. There is no success callback fired here.

6. End call
You can end the call by using endAudioChatCall() function. The syntax is as follows:

Customui.endAudioChatWithUser(userID,callID,successCallback,failCallback);

Pass the user id with whom the call is going on and callid of current on-going call. You will get success response containing the user id with whom the call is ended.

{ "id":"15"}

7. Send busy response
The Audiochat calling is limited to only one user, so if any other user calls you while you are having a call going on, then you can send the busy response to the user by using sendBusyTone() function. The syntax is as follows:

 Customui.prototype.sendBusyCallToUser = function(userID,successCallback,failCallback);

Pass the user id with whom you wish to sent the busy tone. You will get success response containing the user id.

{ "id":"15"}

8. Send no answer response
You can implement functionality like if the call is not accepted for a particular time period the you can send no answer response to callee. For this, you can use sendNoAnswerCall() function. The syntax is as follows:

Customui.sendNoAnswerCallOfUser(userID,callID,successCallback,failCallback)

Pass the user id with whom you wish to sent no answer response. You will get success response containing the user id.

{ "id":"15"}

9. Toggle audio
While having Audio call you can turn on/off the audio, so that other user can not listen to your voice. For this, you can use the toggleAudio() function. The syntax is as follows:

Customui.toggleAudio(audioControlFlag,successCallback,failCallback)

10. Switch Speakers
While having Audio call, you can switch the audio between the main speaker and callee speaker (ear speaker), this will enhance your Audio call experience. For this, you can use switchSpeakers() function. The syntax is as follows:

 Customui.switchSpeakerAudio(successCallback,failCallback);

This will toggle between the main speaker and ear speaker. In success callback you will get jsonObject response as follows:

{ "audio_route":"ear speaker" } 
OR
{ "audio_route":"main speaker" }

Not finding what you need?

The CometChat team is here to help!