# Call Management

# Call mute

The JCSDK provides two muting methods for muting speakers and muting microphones. Mute speakers will not hear each other, and muted microphones will not hear the other person's voice.

# Mute the speaker

Follow these steps to implement the mute speaker feature:

  1. Call the getSpeakerMute method in the JCCallItem object to get the speaker mute state. Returns true to mute and false to not mute.
  2. Call the muteSpeaker method in JCCall to enable/unmute the speaker.

Sample code:

JCCallItem item = call.getActiveCallItem();
if(item  != null){
  if(item.getSpeakerMute()){
    // Unmute the speaker
    call.muteSpeaker(item, false);
  }else{
    // Turn on speaker mute
    call.muteSpeaker(item, true);
  }
}

# Mute the microphone

Follow these steps to implement the mute microphone feature:

  1. Call the getMicrophoneMute method in the JCCallItem object to get the microphone mute state. Returns true to mute and false to not mute.
  2. Call the muteMicrophone method in JCCall to turn on/off the microphone mute function.

Sample code:

JCCallItem item = call.getActiveCallItem();
if(item != null){
  if(item.getMicrophoneMute()){
    // Unmute the microphone
    call.muteMicrophone(item, false);
  }else{
    // Turn on microphone mute
    call.muteMicrophone(item, true);
  }
}

# Call recording

You can record during a call. Turning on/off recording depends on the current recording status. If recording is in progress or the call is suspended, audio recording cannot be performed. The recording state can be obtained by the getAudioRecord() method in the JCCallItem (opens new window) object.

Turn on/off the recording interface as follows:

/**
 * Voice call recording, decide to turn on/off the recording through the audioRecord state in the JCCallItem object
 *
 * @param item      JCCallItem object
 * @param enable    turn on/off recording
 * @param filePath  recording file path
 * @return          return true to indicate the normal execution of the call flow, and false to indicate call failed
 */
public abstract boolean audioRecord(JCCallItem item, boolean enable, String filePath);

Sample code:

JCCallItem item = call.getCallItems().get(0);
if (item.getAudioRecord()) {
    // End recording
    call.audioRecord(item, false, "your filePath");
} else {
    // Create a recording file path
    String filePath; // The absolute path of the recording file, and the SDK will automatically create a recording file
    if (!TextUtils.isEmpty(filePath)) {
        // Start recording
        call.audioRecord(item, true, filePath);
    }
}

When the recording is turned on/off, the recording status will be changed and reported through the onCallItemUpdate callback:

/**
 * The callback triggers when updating the call status (When the upper layer receives this callback, you can obtain all the information and status of the call according to the JCCallItem object, thereby updating the call-related UI)
 *
 * @param item JCCallItem object
 * @param changeParam update symbol class
 */
void onCallItemUpdate(JCCallItem item, JCCallItem.ChangeParam changeParam);

# Video call recording

When you are in a video call, you can record the current video call. Call videoRecord (opens new window) turn video call recording on/off.

Before you turn on video recording, make sure the following:

  1. Not currently recording.

  2. Make sure that the video stream is being uploaded remotely/locally.

  3. Currently in a non-recording state.

Sample code:

JCCallItem item = call.getActiveCallItem();
if (item != null) {
    if (item.getLocalVideoRecord()) {
        //If local video recording is turned on, turn off local recording
        call.videoRecord(item, false, false, 0, 0, "", false);
    } else if (item.getRemoteVideoRecord()) {
        //If remote video recording is turned on, turn off remote recording
        call.videoRecord(item, false, true, 0, 0, "", false);
    } else {
        String localFilePath = "custom file storage path";
        String remoteFilePath = "custom file storage path";
        if (call.videoRecord(item, true, false, 600, 360, localFilePath, true)) {
            //Start recording local video
        } else {
            //The call failed
        }
        if (call.videoRecord(item, true, true, 600, 360, remoteFilePath, true)) {
            //Start recording remote video
        } else {
            //The call failed
        }

}
}

# Turn on/off call hold

You can call the following method to maintain call hold or release call hold on the call object. Turning on/off call hold depends on the call hold state in the JCCallItem object. The call hold state can be obtained by the getHold (opens new window)method:

/**
 * Call hold, decide to turn on/off call hold through the call hold state in the JCCallItem object
 * Only for audio, the upper layer needs to handle the video logic if it is a video call
 *
 * @param item  JCCallItem object
 * @return      return true to indicate the normal execution of the call flow, and false to indicate call failed
 */
public abstract boolean hold(JCCallItem item);

# Switch active call

Call the following method to change the call on hold to the active call:

/**
 * Switch active call
 *
 * @param item  The JCCallItem object that needs to become active
 * @return      return true to indicate the normal execution of the call flow, and false to indicate call failed
 */
public abstract boolean becomeActive(JCCallItem item);

# Send messages during a call

Call the following interface to realize the function of sending messages during a call:

/**
 * Send data through the channel established by the call
 *
 * @param item      JCCallItem object that needs to send data
 * @param type      user can customize text message types, like text, xml, etc.
 * @param content   text content
 * @return          return true to indicate the normal execution of the call flow, and false to indicate call failed
 */
public abstract boolean sendMessage(JCCallItem item, String type, String content);

When messages are received during a call, an onMessageReceive callback will be received:

/**
 * The callback triggers when receiving messages during a call
 *
 * @param type    message type
 * @param content message content
 * @param item    JCCallItem object
 */
void onMessageReceive(String type, String content, JCCallItem item);

Sample code:

JCCallItem item = call.getActiveCallItem();
call.sendMessage("text", "message content", item);

TIP

Sending picture-type messages in calls is not recommended

During a call, if the call status changes, such as turning on/off mute, turning on/off call hold, active status switching, network change, etc., a callback of updating call status will be triggered:

/**
 * The callback triggers when updating call status (When the upper layer receives this callback, you can obtain all the information and status of the call according to the JCCallItem object, thereby updating the call-related UI)
 *
 * @param item           JCCallItem object(the call status of all calls will be updated if the value of item is null)
 * @param changeParam    update symbol class
 */
void onCallItemUpdate(JCCallItem item, JCCallItem.ChangeParam changeParam);

TIP

The mute state, call hold state and active state can be obtained through JCCallItem (opens new window) object.

Sample code:

public void onCallItemUpdate(JCCallItem item, JCCallItem.ChangeParam changeParam) {
    if (item.getMute()) { // Turn on mute
        ...
    } else if (item.getHold()) { // hang up
        ...
    } else if (item.getHeld()) { // suspended
        ...
    } else if (item.getActive()) { //  active state
        ...
    } else if (item.getUploadVideoStreamSelf()) { // The local end is uploading a video stream
        ...
    } else if (item.getUploadVideoStreamOther()) { // The remote end is uploading a video stream
        ...
    }
}
最后更新时间: 1/17/2023, 5:17:17 PM