To add Audio Calling support in your application,
Include the class <MessageSDKFramework/AudioChat.h> in the .h file of your class.
All the method calls will invoke their respective callback blocks as defined below.
1. Initialize the AudioChat object :
AudioChat *audioChat = [[AudioChat alloc] init];
2. Send call request
Send Audio call request to the userID specified. (Ensure that userID cannot be nil or empty)
- (void)sendAudioChatRequestToUser:(NSString *) userID
success:(void(^)(NSDictionary *)) response
failure:(void(^)(NSError *)) failure;
Return type: void
Callback Blocks:
(i). (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
Eg:
{
callID = "\"474a3e0baf0e3db251a2bc2a6a5b31a5\"";
userID = 5;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio call request
Response: NSError containing error code and message
Usage:
[audioChat sendAudioChatRequestToUser:@”5”
success:^(NSDictionary *response) {
} failure:^(NSError * error) {
}];
3. Accept call request
Accept audio call request when AUDIO_INCOMING_CALL message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AUDIO_INCOMING_CALL message and also userID cannot be nil or empty)
- (void)acceptAudioChatRequestOfUser:(NSString *)userID
callID:(NSString *)callID
success:(void(^)(NSDictionary *response)) response
failure:(void(^)(NSError *error)) failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After sending audio call acknowledgement request successfully
Response: NSDictionary containing id of the user to whom audio call acknowledgement has been sent
Eg:
{
userID = 6;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio call request
Response: NSError containing error code and message
Usage:
[audioChat acceptAudioChatRequestOfUser: @”6”
callID:@"474a3e0baf0e3db251a2bc2a6a5b31a5"
success:^(NSDictionary * response) {
} failure:^(NSError * error) {
}];
4. Start audio call
Start an audio call within the container view. This function has to be called after sending/accepting audio call request only. (Ensure that callID specified here should be the same while sending/accepting the request and also callID cannot be nil or empty)
- (void)startAudioChatWithCallID:(NSString *)callID
inContainerView:(UIView *)container
failure:(void(^)(NSError * error))failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After starting audio call successfully
Response: Callback containing success message
Eg:
{
"Connected user" = 1;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while starting audio call request
Response: NSError containing error code and message
Usage:
[audioChat startAudioChatWithCallID:@”474a3e0baf0e3db251a2bc2a6a5b31a5”
inContainerView:containerView
failure:^(NSError * error) {
}];
5. End call
End audio call with the user corresponding to userID & callID specified. (Ensure that userID & callID specified should be same as given when starting the audio call and also userID & callID cannot be nil or empty)
- (void)endAudioChatWithUser:(NSString *)userID
callID:(NSString *)callID
success:(void(^)(NSDictionary *response))response
failure:(void(^)(NSError *error))failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After ending audio call successfully
Response: NSDictionary containing id of the user with whom audio call has been ended
Eg:
{
callID = 474a3e0baf0e3db251a2bc2a6a5b31a5;
userID = 6;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while ending audio call request
Response: NSError containing error code and message
Usage:
[audioChat endAudioChatWithUser:@"6" callID:@"474a3e0baf0e3db251a2bc2a6a5b31a5" success:^(NSDictionary *response) {
} failure:^(NSError *error) {
}];
6. Cancel call
Cancel audio call after sending a call request. (Ensure that userID specified should be same as given when sending the audio call request and also userID cannot be nil or empty)
- (void)cancelAudioChatRequestWithUser:(NSString *)userID
success:(void(^)(NSDictionary *response))response
failure:(void(^)(NSError *error))failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After cancelling audio call successfully
Response: NSDictionary containing id of the user with whom audio call has been cancelled
Eg:
{
userID = 6;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while cancelling audio call request
Response: NSError containing error code and message
Usage:
[audioChat cancelAudioChatRequestWithUser:@”6”
success:^(NSDictionary *response) {
}failure:^(NSError *error) {
}];
7. Send busy call
Send busy call when AUDIO_INCOMING_CALL_USER_BUSY message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AUDIO_INCOMING_CALL_USER_BUSY message and also userID cannot be nil or empty)
- (void)sendBusyCallToUser:(NSString * )userID
success:(void(^)(NSDictionary *response))response
failure:(void(^)(NSError *error)) failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After sending busy call successfully
Response: NSDictionary containing id of the user to whom busy tone has been sent
Eg:
{
userID = 6;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while sending busy tone
Response: NSError containing error code and message
Usage:
[audioChat sendBusyCallToUser:@”6”
success:^(NSDictionary * response) {
}failure:^(NSError * error) {
}];
8. Reject call
Reject audio call request when AUDIO_INCOMING_CALL message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AUDIO_INCOMING_CALL message and also userID cannot be nil or empty)
- (void)rejectAudioChatRequestOfUser:(NSString *)userID
success:(void(^)(NSDictionary *response))response
failure:(void(^)(NSError *error))failure;
Return type: void
Callback Blocks:
(i). (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
Eg:
{
callID = 474a3e0baf0e3db251a2bc2a6a5b31a5;
userID = 5;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while sending busy tone
Response: NSError containing error code and message
Usage:
[audioChat rejectAudioChatRequestOfUser:@”5”
success:^(NSDictionary * response) {
}failure:^(NSError * error) {
}];
9. Toggle Audio to ON(YES) or OFF(NO) state
- (void)toggleAudio:(BOOL)audioControlFlag;
Return type: void
Usage:
[audioChat toggleAudio:YES];
Please refer error codes for failure responses.
Not finding what you need?
The CometChat team is here to help!