Audio/Video Broadcast

To add Audio/Video Broadcast support in your application,

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

All the method calls will invoke their respective callback blocks as defined below.

1. Initialize the AVBroadcast object :

AVBroadcast *avbroadcast =  [[AVBroadcast alloc] init];

2. Send call request
Send Audio Video Broadcast call request to the userID specified. (Ensure that userID cannot be nil or empty)

- (void)sendAVBroadcastRequestToUser:(NSString *) userID
                             success:(void(^)(NSDictionary *)) response
                             failure:(void(^)(NSError *)) failure;

Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After audio video broadcast call request is sent successfully.
Response: NSDictionary containing id of the user to whom audio video broadcast request has been sent.
Eg:

{
  callID = 2be701b036ff9b6e3085d35049e59483;
  userID = 5;
}

(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while sending audio video broadcast request
Response: NSError containing error code and message
Usage:

[avbroadcast sendAVBroadcastRequestToUser:@”5”
                                  success:^(NSDictionary *response) {
                                } failure:^(NSError * error) {
}];

3. Accept Audio/Video broadcast request
Accept Audio/Video broadcast request when INCOMING_AVBROADCAST_REQUEST message is received in the onAVChatMessageReceived callback block. (Ensure that userID & callID specified should be same as userID & callID received in INCOMING_AVBROADCAST_REQUEST message respectively. Also userID & callID cannot be nil or empty)

- (void)acceptAVBroadcastRequestOfUser:(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 broadcast acknowledgement request successfully.
Response: Callback containing success message.
Eg:

{
    success = 1;
}

(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while accepting audio video broadcast request
Response: NSError containing error code and message
Usage:

[avbroadcast acceptAVBroadcastRequestOfUser:@"5" callID:@"2be701b036ff9b6e3085d35049e59483" success:^(NSDictionary *response) {
                    } failure:^(NSError *error) {
                    }];

4. Start audio video broadcast
Start an audio-video broadcast within the container view. This function has to be called after sending/accepting audio-video broadcast 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)startAVBroadcastWithInitiator:(BOOL)initiator
                               callID:(NSString *)callID
                        containerView:(UIView *)container
                        connectedUser:(void (^)(NSDictionary *response))response
                   changeInAudioRoute:(void (^)(NSDictionary *route))audioRouteInformation
                              failure:(void (^)(NSError *error))failure;

The description of parameters is as follows:
initiator: You have to specify your role in the broadcast. If you are the broadcaster so you will pass true, so your audio and video will be broadcasted, and if you are the listener of broadcast then pass false, so your audio and video will not be broadcasted, you will receive the broadcaster’s audio and video.
callID: This is the call id you get from sending the request, or in the request someone sent to you.
userID: Pass the user id of the user you are having the broadcast with.

Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After starting audio video broadcast successfully.
Response: Callback containing success message.
Eg:

{
    "Connected user" = 1;
}

(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while starting audio video broadcast request.
Response: NSError containing error code and message.
Usage:

Sender

[avbroadcast startAVBroadcastWithInitiator:YES callID:@"2be701b036ff9b6e3085d35049e59483" 
                 containerView:videoContainer connectedUser:^(NSDictionary *response) {
                } changeInAudioRoute:^(NSDictionary *audioRoute) {
                } failure:^(NSError *error) {
                }];

Receiver

[avbroadcast startAVBroadcastWithInitiator:NO callID:@"2be701b036ff9b6e3085d35049e59483" containerView:videoContainer                            connectedUser:^(NSDictionary *response) {
                } changeInAudioRoute:^(NSDictionary *audioRoute) {
                } failure:^(NSError *error) {
                }];

5. End call
End audio-video broadcast with the user corresponding to userID & callID specified. (Ensure that userID & callID specified should be same as given when starting the audio-video broadcast and also userID & callID cannot be nil or empty)

- (void)endAVBroadcastWithUser:(BOOL)initiator
                        userID:(NSString *)userID
                        callID:(NSString *)callID
                       success:(void (^)(NSDictionary *response))response
                       failure:(void (^)(NSError *error))failure;

The description of parameters is as follows:
initiator: If you are broadcaster then pass true, so the broadcast will end for all the users, if you are listener then pass false, so the broadcast will not end for all the users, you will just leave the broadcast.
callID: This is the call id you get from sending the request, or in the request someone sent to you.
userID: Pass the user id of the user you are having the broadcast with.

Return type: void
Callback Blocks:
(i). (void(^)(NSDictionary *response))response
Invocation: After ending audio video broadcast successfully.
Response: Callback containing success message.
Eg:

{  
 success = 1;
}

(ii). (void(^)(NSError *error))failure
Invocation: If an error occurs while ending audio video broadcast request
Response: NSError containing error code and message
Usage:

Sender


[avbroadcast endAVBroadcastWithUser:YES userID:@"5" callID:@"2be701b036ff9b6e3085d35049e59483" success:^(NSDictionary *response) {
        } failure:^(NSError *error) {
        }];

Receiver


[avbroadcast endAVBroadcastWithUser:NO userID:@"5" callID:@"2be701b036ff9b6e3085d35049e59483" success:^(NSDictionary *response) {
        } failure:^(NSError *error) {
        }];

6. Switch between front and rear camera in a Video call

- (void)switchCamera;

Return type: void
Usage:

[avbroadcast switchCamera];

Please refer ‎error codes for failure responses.

Not finding what you need?

The CometChat team is here to help!