# Realize Group Calling
This guide introduces how to implement group audio and video calls. The API call sequence of group calls is shown in the figure below:
# Initialize
Call JCMediaDevice create (opens new window) and JCCall create (opens new window) to initialize modules needed to implement multi-party calls:
//Initialize
-(bool)initialize {
//1. Media class
JCMediaDevice *mediaDevice = [JCMediaDevice create:client callback:self];
//2. Media channel lass
JCMediaChannel *mediaChannel = [JCMediaChannel create:client mediaDevice:mediaDevice callback:self];
...
}
Among them:
- The callback in the JCMediaDevice create is the proxy object of the JCMediaDeviceCallback (opens new window) protocol, which is used to notify the upper layer of media device related events. Therefore, you need to specify the proxy object of callback first, and then implement the JCMediaDeviceCallback in the proxy object.
The main methods in the JCMediaDeviceCallback are as follows:
//Camera changes
-(void)onCameraUpdate;
//Audio output changes
-(void)onAudioOutputTypeChange:(NSString*)audioOutputType;
//Sound interruption recovery
-(void)onAudioInerruptAndResume:(BOOL)interrupt;
- The callback in the JCMediaChannel create method is the proxy object of the JCMediaChannelCallback (opens new window) protocol, which is used to notify the relevant events in the channel to the upper layer. Therefore, you need to specify the proxy object of the callback first, and then implement the JCMediaChannelCallback method in the proxy object.
The main methods in JCMediaChannel are as follows:
//The callback of MediaChannel state change
-(void)onMediaChannelStateChange:(JCMediaChannelState)state oldState:(JCMediaChannelState)oldState;
//The callback of joining ChannelReason
-(void)onJoin:(bool)result reason:(JCMediaChannelReason)reason channelId:(NSString*)channelId;
//The callback of leaving the ChannelReason
-(void)onLeave:(JCMediaChannelReason)reason channelId:(NSString*)channelId;
//The callback of channel Stop result
-(void)onStop:(bool)result reason:(JCMediaChannelReason)reason;
//The callback of ParticipantJoin
-(void)onParticipantJoin:(JCMediaChannelParticipant*)participant;
//The callback of ParticipantLeft
-(void)onParticipantLeft:(JCMediaChannelParticipant*)participant;
//The callback of ParticipantUpdate
-(void)onParticipantUpdate:(JCMediaChannelParticipant*)participant participantChangeParam:(JCMediaChannelParticipantChangeParam *)participantChangeParam;
//The volume change of participants
-(void)onParticipantVolumeChange:(JCMediaChannelParticipant*)participant;
# Join a channel
Call enableUploadAudioStream (opens new window) in JCMediaChannel (opens new window) to enable the audio stream. Return true to indicate normal execution of the call flow, and false to indicate abnormal call:
// 1. Enable the audio stream [mediaDeviceChannel enableUploadAudioStream:true];
Call the join (opens new window) method to create and join a channel. You need to pass in the following parameters in the method:
channelIdOrUri: Channel ID or channel Uri. When uriMode in param is set to true, it means channel Uri, and others mean channel ID. Users with the same channel ID or Uri will enter the same channel.
joinParam: Join parameters, fill in nil if no. See JCMediaChannelJoinParam (opens new window) object for details:
// Join a channel [mediaChannel join:@"222" joinParam:nil];
The onJoin (opens new window) callback triggers after joining the channel:
// The callback of joining ChannelReason -(void)onJoin:(bool)result reason:(JCMediaChannelReason)reason channelId:(NSString*)channelId { if (result) { // Join successful } else { // Join failed } }
# Leave a channel
Call the leave (opens new window) method to leave the current channel:
[mediaChannel leave];
After leaving the channel, they receive the onLeave (opens new window) callback, and other members receive the onParticipantLeft (opens new window) callback at the same time.
# 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
[mediaChannel 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 JCMediaChannelReason (opens new window) for the enumeration value of the reason for failure.