Audio Call

To add Audio Calling support in your application,

Include the class <MessageSDKFramework/CometChat.h> in the .h file of your class.

Initialize the CometChat object:

CometChat *cometchat =  [[CometChat alloc] init];

Method Available:

Method Description
sendAudioChatRequestToUser The method sends audio call resquest to a user from a logged-in user
acceptAudioChatRequestOfUser The method allows logged-in user to accept an audio call
startAudioChatWithCallID The method allows loggedin user to start audio call
endAudioChatWithUser The method allows you end the call
cancelAudioChatRequestWithUser The method allows initiator to call the outgoing call
sendBusyCallToUser The method allows you to send busy notification to a user
rejectAudioChatRequestOfUser The method allows you to reject an incoming call
toggleAudio The method allows you to mute/unmute audio

sendAudioChatRequestToUser

The method sends audio call resquest to a user from a logged-in user
Method Signature:

 - (void)sendAudioChatRequest:(NSString *)userId
                           isGroup:(BOOL)isGroup
                           success:(void(^)(NSDictionary *response))response
                           failure:(void(^)(NSError *error))failure;

Arguments:

userID:

The userid of a user with whom you want to initiate a call as NSString datatype.

isGroup:

The ID entered in userID parameter is of Group then set this parameter to YES else NO

success

A callback method.

Method Property Description
Method Signature: (void(^)(NSDictionary *response))response
Invocation: After audio call request is sent successfully
Response: NSDictionary containing id of the user to whom audio call request has been sent and callID

Sample Response:

{
  callID = "474a3e0baf0e3db251a2bc2a6a5b31a5";  
  userID = 5;
}

failure

A callback Method.

Method Property Description
Method Signature: (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio call request
Response: NSError containing error code and message

Usage:

[cometchat sendAudioChatRequest: @"5" isGroup:NO
                              success: ^(NSDictionary *response){/* Code Block */}
                              failure: ^(NSError *error){/* Code Block */}
];

acceptAudioChatRequestOfUser

Allows you to accept an audio call request when AUDIO_INCOMING_CALL message is received in the onAVChatMessageReceived callback of subscribeWithMode method of CometChat class.
Method Signature:

 - (void)acceptAudioChatRequest:(NSString *)userId
                        callId:(NSString *)callId
                        success:(void(^)(NSDictionary *response))response
                        failure:(void(^)(NSError *error))failure;

Arguments:

userID:

The userid of a user who has initiated a call with you as NSString datatype.

callID:

The id of the incoming call

success

A callback method.

Method Property Description
Method Signature: (void(^)(NSDictionary *response))response
Invocation: After sending audio call acknowledgement successfully
Response: NSDictionary containing id of the user to whom audio call acknowledgement has been sent

Sample Response:

{  
 userID = 6;
}

failure

A callback Method.

Method Property Description
Method Signature: (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio call acknowledgement
Response: NSError containing error code and message

Usage:

[audioChat acceptAudioChatRequest: @”6”
                                 callID: @"474a3e0baf0e3db251a2bc2a6a5b31a5"
                                success: ^(NSDictionary * response){/* Code Block */}
                                failure: ^(NSError * error){/* Code Block */}
];

startAudioChatWithCallID

Starts an audio call within a container view. This function has to be called after sending/accepting audio call request only.
Method Signature:

 - (void)startAudioChatCall:(NSString *)callId
             containerView:(UIView *)container
             isGroup:(BOOL)isGroup
             connectedUser:(void(^)(NSDictionary *response))response
             failure:(void(^)(NSError *error))failure;

Arguments:

callID:

The id of the call as NSString datatype.

inContainerView

The reference of the UI Container in which audio call UI should be placed as UIView datatype.

isGroup

If the call is being performed in group then set isGroup to YES else NO

failure

A callback Method.

Method Property Description
Method Signature: (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio call request
Response: NSError containing error code and message

Usage:

[audioChat startAudioChatCall: @”474a3e0baf0e3db251a2bc2a6a5b31a5”
                    inContainerView: containerView
                    isGroup:NO
                    failure:^(NSError * error){/* Code Block */}
];

endAudioChatWithUser

Ends an audio call corresponding to userID and callID
Method Signature:

(void)endAudioChatCall: (NSString *)userID
                    callID: (NSString *)callID
                   success: (void(^)(NSDictionary *response))response
                   failure: (void(^)(NSError *error))failure;

Arguments:

userID:

The userid of a user with whom you want to initiate a call as NSString datatype.

callID:

The id of a call as NSString datatype.

success

A callback method.

Method Property Description
Method Signature: (void(^)(NSDictionary *response))response
Invocation: After ending audio call successfully
Response: NSDictionary containing id of the user and callID corresponding to the ended audio call session

Sample Response:

{
  callID = "474a3e0baf0e3db251a2bc2a6a5b31a5";  
  userID = 5;
}

failure

A callback Method.

Method Property Description
Method Signature: (void(^)(NSError *error))failure
Invocation: If an error occurs while ending audio call session
Response: NSError containing error code and message

Usage:

[audioChat endAudioChatCall: @"6"
                         callID: @"474a3e0baf0e3db251a2bc2a6a5b31a5"
                        success: ^(NSDictionary *response){/* Code Block */} 
                        failure: ^(NSError *error){/* Code Block */}
];

cancelAudioChatRequestWithUser

Allows initiator to call the outgoing call
Method Signature:

(void)cancelAudioChatRequest: (NSString *)userID
                             success: (void(^)(NSDictionary *response))response
                             failure: (void(^)(NSError *error))failure;

Arguments:

userID:

The userid of a user with whom you had initiated a call as NSString datatype.

success

A callback method.

Method Property Description
Method Signature: (void(^)(NSDictionary *response))response
Invocation: After cancelling audio call successfully
Response: NSDictionary containing id of the user with whom audio call has been cancelled

Sample Response:

{
  userID = 6;
}

failure

A callback Method.

Method Property Description
Method Signature: (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio call request
Response: NSError containing error code and message

Usage:

[cometchat cancelAudioChatRequest: @"6"
                                  success: ^(NSDictionary *response){/* Code Block */}
                                  failure: ^(NSError *error){/* Code Block */}
];

sendBusyCallToUser

Sends busy call notification to a user who had made a call. You can use this method to notify the user that you are already enganed in another call. The message AUDIO_INCOMING_CALL_USER_BUSY message is received in the onAVChatMessageReceived callback indicates that the logged-in user is busy with another call.
Method Signature:

 (void)sendBusyAudioTone: (NSString * )userID
                  success: (void(^)(NSDictionary *response))response
                  failure: (void(^)(NSError *error)) failure;

Arguments:

userID:

The userid of a user with whom you want to initiate a call as NSString datatype.

success

A callback method.

Method Property Description
Method Signature: (void(^)(NSDictionary *response))response
Invocation: After sending busy call successfully
Response: NSDictionary containing id of the user to whom busy notification has been sent

Sample Response:

{  
  userID = 6;
}

failure

A callback Method.

Method Property Description
Method Signature: (void(^)(NSError *error))failure
Invocation: If an error occurs while sending busy notification
Response: NSError containing error code and message

Usage:

[cometchat sendBusyAudioTone: @"5"
                      success: ^(NSDictionary *response){/* Code Block */}
                      failure: ^(NSError *error){/* Code Block */}
];

rejectAudioChatRequestOfUser

Allows user to reject audio call. You can show an option to reject a call on receiving AUDIO_INCOMING_CALL_USER_BUSY message in the onAVChatMessageReceived callback.
Method Signature:

  (void)rejectAudioChatRequest:(NSString *)userId
                                   callId:(NSString *)callId
                                  success:(void(^)(NSDictionary *response))response
                                  failure:(void(^)(NSError *error))failure;

Arguments:

userID:

The userid of a user with whom you want to initiate a call as NSString datatype.

success

A callback method.

Method Property Description
Method Signature: (void(^)(NSDictionary *response))response
Invocation: After rejecting audio call successfully
Response: NSDictionary containing id of the user whose incoming audio call request has been rejected

Sample Response:

{
  callID = "474a3e0baf0e3db251a2bc2a6a5b31a5";  
  userID = 5;
}

failure

A callback Method.

Method Property Description
Method Signature: (void(^)(NSError *error))failure
Invocation: If an error occurs while sending busy notification
Response: NSError containing error code and message

Usage:

[cometchat rejectAudioChatRequest: @"5"
                                      callId:@"474a3e0baf0e3db251a2bc2a6a5b31a5"
                                     success: ^(NSDictionary *response){/* Code Block */}
                                     failure: ^(NSError *error){/* Code Block */}
];

toggleAudio

The method allows user to mute/unmute Audio
Method Signature:

(void)switchSpeakers;

Usage:

[cometchat switchSpeakers];

Please refer ‎error codes for failure responses.

  • Was this helpful?
  • Yes   No