Audio/Video Calling

To use Audio/Video Chat functionality, you must have downloaded Audio/Video Chat enabled SDK. To start using Audio/Video Chat functionality you must have Audio/Video Chat instance which can be obtained as follows:

AVChat avchat =  AVChat.getAVChatInstance(context)

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

sendAVChatRequest(String userid,Callbacks callback )

e.g:

avchat.sendAVChatRequest(“15”, new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

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

{ "id":"15"}

2. Accept Audio/Video Chat request
If any user has sent you call request, you can accept it by using acceptAVChatRequest() function. The syntax is as follows:

acceptAVChatRequest(String userid,Callbacks callback )

e.g :

avchat.acceptAVChatRequest("15", new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

Pass the userid 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 Chat request
You can reject any incoming call request by using rejectAVChatRequest() function. The syntax is as follows:

rejectAVChatRequest(String userid,Callbacks callback )

e.g

avchat.rejectAVChatRequest("15", new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

Pass the userid 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:

cancelAVChatRequest(String userid,Callbacks callback )

e.g

avchat.cancelAVChatRequest("15", new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

Pass the userid 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:

startAVChatCall(String userid,RelativeLayout container,Callbacks callback )

e.g

avchat.startAVChatCall("15", container, new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

Here the container is the relative layout in which video will be displayed. There is no success callback fired here.

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

endAVChatRequest(String userid,Callbacks callback )

e.g

avchat.endAVChatCall(“15”, new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

Pass the userid with whom the call is going on. You will get success response containing the user id with whom the call is ended.

{ "id":"15"}

7. Send busy response
The AVChat 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:

sendBusyTone(String userid,Callbacks callback )

e.g

avchat.sendBusyTone("15", new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

Pass the userid 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:

sendNoAnswerCall(String userid,Callbacks callback )

e.g

avchat.sendNoAnswerCall(“15”, new Callbacks() {
	@Override
	public void successCallback(JSONObject response) {
	}
	@Override
	public void failCallback(JSONObject response) {
	}
});

Pass the userid 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:

toogleAudio(Boolean flag)

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 toggleVideo() function. The syntax is as follows:

toogleVideo(Boolean flag)

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

12. Rotation handling
As you know Android devices are sensitive to the rotation, you need to handle the rotation specially while having Audio/Video call, so that you don’t find any difficulties and have smooth transition while rotating the device. You need to use following function to do so:

removeVideoOnRotation()
 and 
addVideoOnRotation()

e.g

@Override
protected void onPause() {
    super.onPause();
    avchat.removeVideoOnRotation(layoutcontainer);
}

@Override
protected void onResume() {
    super.onResume();
    avchat.addVideoOnRotation(layoutcontainer);
}

Pass the container which you have used in the function startAVChatCall() function.

Not finding what you need?

The CometChat team is here to help!