# Realize group voice calling

This guide introduces how to implement group voice calling. The API call sequence of group voice calls is shown in the figure below:

../../../../_images_en/multiaudioworkflow.jpg

# Initialize

Call JCMediaDevice.create (opens new window) and JCCall.create (opens new window) to initialize modules needed to implement group calls:

/// Create a new class and implement it
class JCManager : JCClientCallback, JCMediaDeviceCallback,JCMediaChannelCallbac{

    #region JCMediaDeviceCallback

    public void onCameraUpdate(){...}

    public void onAudioOutputTypeChange(string audioOutputType){...}

    #endregion

    #region JCMediaChannelCallback
    ...
    /// Achieve methods in JCMediaChannelCallback
    ...
    #endregion

    /// Declare object
    JCMediaDevice mMediaDevice;
    JCMediaChannel mMediaChannel;

    /// Initialization function
    public bool initialize(Context context) {

        /// 1. Media class
        mMediaDevice = JCMediaDevice.create(mClient, this);
        /// 2. Media channel lass
        mMediaChannel = JCMediaChannel.create(client, mediaDevice, this);
    }
}

# Join a channel

  1. Call enableUploadAudioStream (opens new window) to enable audio streaming:

    /// 1. Enable the audio stream
    mMediaDeviceChannel.enableUploadAudioStream(true);
    
  2. To create and join a channel, you need to pass in channelIdOrUri and JCMediaChannel.JoinParam (opens new window):

    • channelIdOrUri refers to the channel ID or channel Uri.

    • In JCMediaChannelJoinParam, the uriMode parameter is set to true, which means the incoming channel Uri. When other parameters are set, it means the incoming channel ID. Users who pass in the same channel ID or the same channel Uri will enter the same Channel.

    mMediaChannel.join("222", null);
    
  3. The onJoin (opens new window) callback triggers after joining the channel:

    public void onJoin(bool result, JCMediaChannelReason reason, String channelId) {
        if (result) {
            /// Join the channel successfully
        } else {
            /// Join the channel failed
        }
    }
    

# Leave a channel

Call the leave (opens new window) method to leave the current channel:

mMediaChannel.leave();

After leaving a channel, you will receive the onLeave (opens new window) callback, and other members receive the onParticipantLeft (opens new window) callback at the same time:

/// The callback of leaving the ChannelReason

public void onLeave(JCMediaChannelReason reason, String channelId) {
    ...
}

# Destroy a channel

If you want to destroy a channel, you can call the following interface, and all members will be quit:

/// End a channel
mMediaChannel.stop();

After the channel is stopped, the member that initiated the termination receives the onStop (opens new window) callback, and other members receive the onLeave (opens new window) callback at the same time. Please refer to MediaChannelReason (opens new window) for the enumeration value of the reason for failure:

public void onStop(bool result, JCMediaChannelReason reason) {
    ...
}