Listen for Callback Events

The ZMVideoSDKDelegate of the Video SDK allows you to subscribe to callback events that provide status updates on the operations performed in your app that are related to the SDK. For example, you might want to be notified when a user has successfully joined or left a session.

Implement a delegate

To subscribe to these events, you must create an instance of the ZMVideoSDKDelegate and have your class conform to the ZMVideoSDKDelegate protocol.

In this section, we will show you how to implement this delegate, assign it to the SDK instance, and provide you with examples of the event handlers associated with the SDK.

Conform to the ZMVideoSDKDelegate


@interface YourClass : NSObject <ZMVideoSDKDelegate>
// Add any of the following callback functions here as needed for your app.
[[ZMVideoSDK sharedZMVideoSDK] addListener:self];

class YourClass: ZMVideoSDKDelegate {
// Add any of the following callback functions here as needed for your app.
}
ZMVideoSDK.shared()?.addListener(self)

Callback functions

The following examples show the various callback functions that are provided by the Video SDK. You can use these functions and implement any additional operations as needed after receiving the result of each callback function.

Get notified of operation results and SDK errors


- (void)onError:(ZMVideoSDKErrors)ErrorType detail:(int)details {
    switch (ErrorType) {
        case ZMVideoSDKErrors_Success:
            // Your ZMVideoSDK operation was successful.
            NSLog(@"Success");
            break;
        default:
            // Your ZMVideoSDK operation raised an error.
            // Refer to error code documentation.
            NSLog(@"Error %lu %ld", (unsigned long)ErrorType, (long)details);
            break;
    }
}

func onError(_ ErrorType: ZMVideoSDKErrors, detail details: Int32) {
    switch ErrorType {
        case ZMVideoSDKErrors_Success:
        // Your ZMVideoSDK operation was successful.
        print("Success")
        default:
        // Your ZMVideoSDK operation raised an error.
        // Refer to error code documentation.
        print("Error (ErrorType) (details)")
        return
    }
}

Get notified when the local user successfully joins or leaves a session


- (void)onSessionJoin {
    // You have successfully joined the session.
}
- (void)onSessionLeave {
    // You have successfully left the session.
}

func onSessionJoin() {
    // You have successfully joined the session.
}
func onSessionLeave() {
    // You have successfully left the session.
}

Get notified when other users successfully join or leave a session


- (void)onUserJoin:(ZMVideoSDKUserHelper*)userHelper userList:(NSArray<ZMVideoSDKUser >)userArray {
    // UserArray contains the new users.
    // Use helper to perform actions on a user.
    for (int i = 0; i < userArray.count; i++) {
        NSLog(@"%@", userArray[i]);
    }
}
- (void)onUserLeave:(ZMVideoSDKUserHelper*)userHelper userList:(NSArray<ZMVideoSDKUser >)userArray {
    // UserArray contains the users that recently left.
    // Use helper to perform actions on a user.
    for (int i = 0; i < userArray.count; i++) {
        NSLog(@"%@", userArray[i]);
    }
}

func onUserJoin(_ userHelper: ZMVideoSDKUserHelper!, userList userArray: [ZMVideoSDKUser]!) {
    // UserArray contains the new users.
    // Use helper to perform actions on a user.
    if let userArray = userArray {
        for user in userArray {
            print(user)
        }
    }
}
func onUserLeave(_ userHelper: ZMVideoSDKUserHelper!, userList userArray: [ZMVideoSDKUser]!) {
    // UserArray contains the users that recently left.
    // Use helper to perform actions on a user.
    if let userArray = userArray {
        for user in userArray {
            print(user)
        }
    }
}

Get notified when a user's video status has changed


- (void)onUserVideoStatusChanged:(ZMVideoSDKVideoHelper*)videoHelper userList:(NSArray*)userArray {
    // UserArray contains the users that had a video status change.
    // Use helper to perform actions on a user.
    for (int i = 0; i < userArray.count; i++) {
        if (userArray[i]) {
            // Use to check if a user's video is on or off.
            if ([userArray[i] videoStatus].isOn) {
                // User's video is on.
            }
        }
    }
}

func onUserVideoStatusChanged(_ videoHelper: ZMVideoSDKVideoHelper!, userList userArray: [ZMVideoSDKUser]!) {
    // UserArray contains the users that had a video status change.
    // Use helper to perform actions on a user.
    if let userArray = userArray {
        for user in userArray {
            // Use to check if a user's video is on or off.
            if ((user.getVideoStatus()?.isOn) == true) {
                // User's video is on.
            }
        }
    }
}

Get notified when a user's audio status has changed


- (void)onUserAudioStatusChanged:(ZMVideoSDKAudioHelper*)audioHelper userList:(NSArray*)userArray {
    // UserArray contains the users that had an audio status change.
    // Use helper to perform actions on a user.
    for (int i = 0; i < userArray.count; i++) {
        if (userArray[i]) {
            // Use to check if a user's audio is muted.
            // If true, the user is muted. If false, the user is unmuted.
            if ([user getAudioStatus].isMuted) {
                // User's audio is not muted.
            }
            // Use to obtain a certain user's audio type.
            NSLog(@"User has audio type: %lu", [userArray[i] getAudioStatus].audioType);
        }
    }
}

func onUserAudioStatusChanged(_ audioHelper: ZMVideoSDKAudioHelper!, userList userArray: [ZMVideoSDKUser]!) {
    // UserArray contains the users that had an audio status change.
    // Use helper to perform actions on a user.
    if let userArray = userArray {
        for user in userArray {
            // Use to check if a user's audio is muted.
            // If true, the user is muted. If false, the user is unmuted.
            if ((user.getAudioStatus().isMuted) == true) {
                // User's audio is not muted.
            }
            // Use to obtain a certain user's audio type.
            if let audioType = getAudioStatus()?.audioType {
                print("User has audio type: (audioType)")
            }
        }
    }
}

Get notified when a user starts or stops screen sharing


- (void)onUserShareStatusChanged:(ZMVideoSDKShareHelper *)helper user:(ZMVideoSDKUser *)user status:(ZMVideoSDKShareStatus)status {
    // Use helper to perform sharing actions.
    // User is the user who's share status has changed.
    // Status is the new share status of that user.
    switch (status) {
        case ZMVideoSDKShareStatus_Start: {
            // User has begun sharing.
        }
        case ZMVideoSDKShareStatus_Stop: {
            // User has stopped sharing.
        }
        default:
            break;
    }
}

func onUserShareStatusChanged(_ helper: ZMVideoSDKShareHelper!, user: ZMVideoSDKUser!, status: ZMVideoSDKShareStatus) {
    // Use helper to perform sharing actions.
    // User is the user who's share status has changed.
    // Status is the new share status of that user.
    switch status {
        case ZMVideoSDKShareStatus_Start:
            // User has begun sharing.
        case ZMVideoSDKShareStatus_Stop:
            // User has stopped sharing.
        default:
            break
    }
}

Get notified when a user starts or stops live streaming


- (void)onLiveStreamStatusChanged:(ZMVideoSDKLiveStreamHelper*)liveStreamHelper liveStreamStatus:(ZMVideoSDKLiveStreamStatus)status {
    // Use helper to perform live stream actions.
    // Status is the new live stream status.
    switch (status) {
        case ZMVideoSDKLiveStreamStatus_InProgress:
            NSLog(@"Live stream now in progress.");
            break;
        case ZMVideoSDKLiveStreamStatus_Ended:
            NSLog(@"Live stream has ended.");
        default:
            NSLog(@"Live stream status unknown.");
            break;
    }
}

func onLiveStreamStatusChanged(_ liveStreamHelper: ZMVideoSDKLiveStreamHelper!, liveStreamStatus status: ZMVideoSDKLiveStreamStatus) {
    // Use helper to perform live stream actions.
    // Status is the new live stream status.
    switch status {
    case ZMVideoSDKLiveStreamStatus_InProgress:
        print("Live stream now in progress.")
    case ZMVideoSDKLiveStreamStatus_Ended:
        print("Live stream has ended.")
    default:
        print("Live stream status unknown.")
    }
}

Get notified when a message is delivered


- (void)onChatNewMessageNotify:(ZMVideoSDKChatHelper*)chatHelper chatMessage:(ZMVideoSDKChatMessage*)chatMessage {
    // Use helper to perform chat actions.
    // Message contains the info about a chat message.
    NSString *content = chatMessage.content;
    ZMVideoSDKUser *sender = [chatMessage getSendUser];
    NSLog(@"%@ sent a message: %@", sender.getUserName, content);
}

func onChatNewMessageNotify(_ chatHelper: ZMVideoSDKChatHelper!, chatMessage: ZMVideoSDKChatMessage!) {
    // Use helper to perform chat actions.
    // Message contains the info about a chat message.
    if let content = chatMessage.content, let senderName = chatMessage.sendUser.getName() {
        print("(senderName) sent a message: (content)")
    }
}

Get notified when the host of the session is changed


- (void)onUserHostChanged:(ZMVideoSDKUserHelper*)userHelper user:(ZMVideoSDKUser*)user {
    // User is the new host of the session.
    // Use helper to perform actions on a user.
    if ([user getUserName])
        NSLog(@"%@: is the new host.", user.getUserName);
}

func onUserHostChanged(_ userHelper: ZMVideoSDKUserHelper!, user: ZMVideoSDKUser!) {
    // User is the new host of the session.
    // Use helper to perform actions on a user.
    if let userName = user.getUserName() {
        print("(userName): is the new host.")
    }
}

Get notified when a user's active audio changes


// onUserActiveAudioChanged is different from onUserAudioStatusChanged. onUserActiveAudioChanged is called when a given user's audio changes, while onUserAudioStatusChanged is called when the user's audio status changes. For example, if the user is unmuted and is using their device's microphone, this callback will be triggered whenever their microphone detects a noise.
- (void)onUserActiveAudioChanged:(ZMVideoSDKAudioHelper*)audioHelper userList:(NSArray*)userArray {
    // UserArray contains the users that had an active audio change.
    // Use helper to perform audio actions.
    for (int i = 0; i < userArray.count; i++) {
        if (userArray[i]) {
            // Use to see if the user is currently talking.
            if ([userArray[i] getAudioStatus].isTalking) {
                NSLog(@"%@ began talking.", userArray[i].getUserName);
            }
        }
    }
}

// onUserActiveAudioChanged is different from onUserAudioStatusChanged. onUserActiveAudioChanged is called when a given user's audio changes, while onUserAudioStatusChanged is called when the user's audio status changes. For example, if the user is unmuted and is using their device's microphone, this callback will be triggered whenever their microphone detects a noise.
func onUserActiveAudioChanged(_ audioHelper: ZMVideoSDKAudioHelper!, userList userArray: [ZMVideoSDKUser]!) {
    // UserArray contains the users that had an active audio change.
    // Use helper to perform audio actions.
    if let userArray = userArray {
        for user in userArray {
            // Use to see if the user is currently talking.
            if let audioStatus = user.getAudioStatus(), audioStatus.isTalking, let userName = user.getUserName() {
                print("(userName) began talking.")
            }
        }
    }
}

Get notified when a password is required to join a session


- (void)onSessionNeedPassword:(ZMVideoSDKPasswordHandler *)handle {
    // Recommended action: prompt user to enter password again and pass user input into completion
    NSString *userInput = @"Password";
    if (handle) {
        [handle inputSessionPassword:userInput];
    }
    // Alternatively, you may abandon the attempt to join the session
    if (handle) {
        [handle leaveSessionIgnorePassword];
    }
}

func onSessionNeedPassword(_ handle: ZMVideoSDKPasswordHandler!) {
    // Recommended action: prompt user to enter password again and pass user input into completion
    if let handler = handle {
        let userInput = "Password"
        handler.inputSessionPassword(userInput)
    }
    // Alternatively, you may abandon the attempt to join the session
    if let handler = handle {
        handler.leaveSessionIgnorePassword()
    }
}

Get notified when an incorrect password is entered while joining a session


- (void)onSessionPasswordWrong:(ZMVideoSDKPasswordHandler *)handle {
    // Recommended action: prompt user to enter password again and pass user input into completion
    NSString *userInput = @"Password";
    if (handle) {
        [handle inputSessionPassword:userInput];
    }
    // Alternatively, you may abandon the attempt to join the session
    if (handle) {
        [handle leaveSessionIgnorePassword];
    }
}

func onSessionPasswordWrong(_ handle: ZMVideoSDKPasswordHandler!) {
    // Recommended action: prompt user to enter password again and pass user input into completion
    if let handler = handle {
        let userInput = "Password"
        handler.inputSessionPassword(userInput)
    }
    // Alternatively, you may abandon the attempt to join the session
    if let handler = handle {
        handler.leaveSessionIgnorePassword()
    }
}

Get notified when a user name has changed


- (void)onUserNameChanged:(ZMVideoSDKUser*)user {
}

func onUserNameChanged(_ user: ZMVideoSDKUser!) {
}

Get notified when a user manager has changed


- (void)onUserManagerChanged:(ZMVideoSDKUser*)user {
}

func onUserManagerChanged(_ user: ZMVideoSDKUser!) {
}

Get notified when shared raw audio data is received


- (void)onSharedAudioRawDataReceived:(ZMVideoSDKAudioRawData*)data {
}

func onSharedAudioRawDataReceived(_ data: ZMVideoSDKAudioRawData!) {
}

Get notified when mixed raw audio data is received


- (void)onMixedAudioRawDataReceived:(ZMVideoSDKAudioRawData*)data {
}

func onMixedAudioRawDataReceived(_ data: ZMVideoSDKAudioRawData!) {
}

Get notified when one-way raw audio data is received


- (void)onOneWayAudioRawDataReceived:(ZMVideoSDKAudioRawData*)data user:(ZMVideoSDKUser*)user {
}

func onOneWayAudioRawDataReceived(_ data: ZMVideoSDKAudioRawData!, user: ZMVideoSDKUser!) {
}

Need help?

If you're looking for help, try Developer Support or our Developer Forum. Priority support is also available with Premier Developer Support plans.