Audio/Video Calling

To add Audio/Video 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.
To use Audio Video call functionality, you must download Audio/Video chat enabled SDK.

1. Send Audio/Video call request
To start with Audio video call, you need to send a request to the other user. The syntax is as follows:

Customui.sendAVChatRequestToUser(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 Audio/Video call request
If any user has sent you a call request, you can accept it by using acceptAVChatRequest() function. The syntax is as follows:

 Customui.acceptAVChatRequestOfUser(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 Audio/Video call request
You can reject any incoming call request by using rejectAVChatRequest() function. The syntax is as follows:

Customui.rejectAVChatRequestOfUser = function(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 rejected.

{ "id":"15"}

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

Customui.cancelAVChatRequestWithUser(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 startAVChatCall(). The syntax is as follows:

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

Here the container is the relative layout in which video will be displayed. There is no success callback fired here. 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 endAVChatCall() function. The syntax is as follows:

Customui.endAVChatWithUser(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 Audio/Video 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.sendBusyAVCallToUser(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.sendAVNoAnswerCallOfUser(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/Video 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.toggleAudioSDK (audioControlFlag,successCallback,failCallback);

10. Toggle video
While having Audio/Video call you can turn on/off video, so that other user can not see your video. For this, you can use a toggleVideo() function. The syntax is as follows:

 Customui.toggleVideoSDK = function(videoControlFlag,successCallback,failCallback);

11. Switch camera
While having Audio/Video call you can switch between your front camera and back main camera.This function doesn’t require any parameter.

Customui.switchCameraSDK(successCallback,failCallback);

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

Customui.switchAudioRouteSDK(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!