# Realize One-to-One Voice Calling
This guide introduces how to implement one-to-one voice calls. The API call sequence of one-to-one voice calls is shown in the figure below:
# Initialize
Call JCMediaDevice.create (opens new window) and JCCall.create (opens new window) to initialize the modules needed for one-to-one calling:
/// Create a new class and implement it
class JCManager : JCClientCallback, JCMediaDeviceCallback,JCCallCallbac{
#region JCMediaDeviceCallback
public void onCameraUpdate(){...}
public void onAudioOutputTypeChange(string audioOutputType){...}
#endregion
#region JCCallCallbac
...
/// Implement the methods in JCCallCallbac
...
#endregion
/// Declare object
JCMediaDevice mMediaDevice;
JCMediaChannel mMediaChannel;
/// Initialization function
public bool initialize(Context context) {
/// 1. Media class
mMediaDevice = JCMediaDevice.create(mClient, this);
/// 2. Call class
mCall = JCCall.create(mClient, mMediaDevice, this);
}
}
# Make a call
Call call (opens new window) to initiate a video call, the parameters that need to be filled are:
userID
Fill in the user ID of the other party.video
Select whether to call a video call, and true means to make a video call, while false means to make a voice call.extraParam (opens new window) is a custom pass-through string, which can be obtained through item.extraParam.
/// Initiate a voice call
mCall.call("userID", isVideo , new JCCall.CallParam("extraParam", "ticket"));
After the call is made, both the caller and the called party will receive the callback onCallItemAdd (opens new window) for the new call, and the call status will change to STATE_PENDING (opens new window) at this time. You can perform logical operations by overriding onCallItemAdd (opens new window):
/// 1. Initiate a voice call
mCall.call("userID", isVideo , new JCCall.CallParam("extraParam", "ticket"));
/// 2. Override callback
public void onCallItemAdd(JCCallItem item) {
/// Business logic
if (item.direction == JCCall.DIRECTION_IN) {
/// If you are the called party
...
}else{
/// If you are the caller
...
}
}
# Answer a call
The called party receives the onCallItemAdd (opens new window) callback, and judges whether it is a video call or a voice call according to the JCCallItem (opens new window) attribute in the callback, and then makes corresponding processing:
public void onCallItemAdd(JCCallItem item) { /// 1. If it is an incoming video call and it is ringing if (item.direction == JCCall.DIRECTION_IN && !item.video) { /// 2. Make corresponding processing, such as "ringing" on the interface ... } }
Call answer (opens new window) to answer the call:
mCall.answer(item, false);
After the call is answered, the call status changes to STATE_CONNECTING.
TIP
If you want to reject the call at this time, please call the interface to hang up the call. In this case, after calling hang up, the call state changes to STATE_CANCELED.
# Hang up a call
Both the calling party and the called party can hang up the call.
Call getActiveCallItem (opens new window) to get the currently active call object:
mCall.getActiveCallItem();
Call term (opens new window) to hang up the current active call:
mCall.term(item, reason, description);
Sample code:
/// 1. Get the current active call
JCCallItem item = mCall.getActiveCallItem();
/// 2. Hang up the current active call
mCall.term(item, JCCall.REASON_NONE, null);