To add Audio/Video Calling support in your application,
Include the class <CometChatSDK/AVChat.h> in the .h file of your class.
All the method calls will invoke their respective callback blocks as defined below.
1. Initialize the AVChat object :
AVChat *avChat = [[AVChat alloc] init];
2. Send call request
Send Audio Video call request to the userID specified. (Ensure that userID cannot be nil or empty)
- (void)sendAVChatRequestToUser:(NSString *) userID
success:(void(^)(NSDictionary *)) response
failure:(void(^)(NSError *)) failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After audio video call request is sent successfully.
Response: NSDictionary containing id of the user to whom audio video call request has been sent.
Eg:
{
callID = "\"474a3e0baf0e3db251a2bc2a6a5b31a5\"";
userID = 5;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio video call request
Response: NSError containing error code and message
Usage:
[avChat sendAVChatRequestToUser:@”5”
success:^(NSDictionary *response) {
} failure:^(NSError * error) {
}];
3. Accept call request
Accept audio-video call request when AVCHAT_INCOMING_CALL message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AVCHAT_INCOMING_CALL message and also userID cannot be nil or empty)
- (void) acceptAVChatRequestOfUser:(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 video call acknowledgement request successfully
Response: NSDictionary containing id of the user to whom audio video call acknowledgement has been sent
Eg:
{
userID = 6;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio video call request
Response: NSError containing error code and message
Usage:
[avChat acceptAVChatCallWithUser: @”6”
callID:@"474a3e0baf0e3db251a2bc2a6a5b31a5"
success:^(NSDictionary * response) {
} failure:^(NSError * error) {
}];
4. Start audio video call
Start an audio-video call within the container view. This function has to be called after sending/accepting audio-video call request only. (Ensure that userID specified here should be the same while sending/accepting the request and also userID cannot be nil or empty)
- (void)startAVChatCallWithUser:(NSString *)userID
inContainerView:(UIView *)container
failure:(void(^)(NSError * error))failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSError *error))failure
Invocation: If an error occurs while starting audio video call request.
Response: NSError containing error code and message.
Usage:
[avChat startAVChatCallWithUser:@”6”
inContainerView:containerView
failure:^(NSError * error) {
}];
5. End call
End audio-video call with the user corresponding to userID specified. (Ensure that userID specified should be same as given when starting the audio-video call and also userID cannot be nil or empty)
- (void)endAVChatCallWithUser:(NSString *)userID
success:(void(^)(NSDictionary * response)) response
failure:(void(^)(NSError * error)) failure;
Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After ending audio video call successfully.
Response: NSDictionary containing id of the user with whom audio video call has been ended.
Eg:
{
callID = 474a3e0baf0e3db251a2bc2a6a5b31a5;
userID = 6;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while ending audio video call request
Response: NSError containing error code and message
Usage:
[avChat endAVChatCallWithUser:@”6”
success:^(NSDictionary* response) {
}failure:^(NSError* error) {
}];
6. Cancel call
Cancel audio-video call after sending a call request. (Ensure that userID specified should be same as given when sending the audio-video call request and also userID cannot be nil or empty)
- (void)cancelAVChatCallWithUser:(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 video call successfully
Response: NSDictionary containing id of the user with whom audio video call has been cancelled
Eg:
{
userID = 6;
}
(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while cancelling audio video call request
Response: NSError containing error code and message
Usage:
[avChat cancelAVChatCallWithUser:@”6”
success:^(NSDictionary *response) {
}failure:^(NSError *error) {
}];
7. Send busy call
Send busy call when AVCHAT_INCOMING_CALL_USER_BUSY message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AVCHAT_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:
[avChat sendBusyCallToUser:@”6”
success:^(NSDictionary * response) {
}failure:^(NSError * error) {
}];
8. Reject call
Reject audio-video call request when AVCHAT_INCOMING_CALL message is received in the onAVChatMessageReceived callback block. (Ensure that userID specified should be same as the userID received in AVCHAT_INCOMING_CALL message and also userID cannot be nil or empty)
- (void)rejectAVChatCallWithUser:(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 video call successfully
Response: NSDictionary containing id of the user whose incoming audio video 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:
[avChat rejectAVChatCallToUser:@”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:
[avchat toggleAudio:YES];
10. Toggle Video to ON(YES) or OFF(NO) state
- (void)toggleVideo:(BOOL)videoControlFlag;
Return type: void
Usage:
[avchat toggleVideo:YES];
11. Switch between front and rear camera in a Video call
- (void)switchCamera;
Return type: void
Usage:
[avchat switchCamera];
Please refer error codes for failure responses.
Not finding what you need?
The CometChat team is here to help!