# Add video capabilities to the Contact Center SDK for iOS

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Initialize the video service

Create an instance of class `ZoomCCItem` to set the channel to use, chat or video. For video, set the `sdkType` property to `ZoomCCIInterfaceType_Video`.

Include the `entryId` from your Zoom Contact Center flow.

```objectivec
ZoomCCItem *item = [ZoomCCItem new];
item.sdkType = ZoomCCIInterfaceType_Video;
item.entryId = APP_VIDEO_ENTRY_ID;
```

```swift
let item = ZoomCCItem.init()
item.sdkType = .video
item.entryId = APP_VIDEO_ENTRY_ID
```

## Pass engagement variables (optional)

To pass custom application context variables to a video engagement, configure custom variables in Contact Center Management and set its value source to **Application**. Before calling `initializeWithItem`, use the variable name as the key and the application-provided value as the dictionary value in `ZoomCCItem.engagementVariables`.

> **Missing variables**
>
> Missing variables do not block the engagement flow, but nodes that depend on them may not work as expected.

```objectivec
ZoomCCItem *item = [ZoomCCItem new];
item.sdkType = ZoomCCIInterfaceType_Video;
item.entryId = APP_VIDEO_ENTRY_ID;
item.engagementVariables = @{@"test_key":@"test_value"};
```

```swift
let item = ZoomCCItem.init()
item.sdkType = .video
item.entryId = APP_VIDEO_ENTRY_ID
item.engagementVariables = ["test_key": "test_value"]
```

## Fetch the video service instance

Fetch the video service instance and set its delegate to receive callbacks from `ZoomCCSDK`. Initialize the service by calling `initializeWithItem:`. The service will connect to the Contact Center server to fetch the video information.

```objectivec
id<ZoomCCVideoService> videoService = [[ZoomCCInterface sharedInstance] videoService];
videoService.videoDelegate = self;
[videoService initializeWithItem:item];
```

```swift
let videoService = ZoomCCInterface.sharedInstance().videoService()
videoService.videoDelegate = self
if (videoService.status == .initial) {
videoService.initialize(with: item)
}
```

## Show the video view

To show the video view, call the function below. The call back gets the view's instance and displays it. The `videoService` requests to start a video session with the Contact Center server. Once it is ready, the user can join the video session automatically inside the `ZoomCCSDK` inner view.

```objectivec
__weak typeof(self) wself = self;
[videoService fetchUI:^(UIViewController * _Nonnull viewController) {
[wself directShow:viewController];
}];
```

```swift
videoService.fetchUI { vc in
self.navigationController?.pushViewController(vc, animated: true)
}
```

## Forcibly end an active video engagement

To forcibly end a video engagement, use the endVideo method. This action closes the video view and releases any associated service instances within the Contact Center SDK.

```objectivec
id<ZoomCCVideoService> videoService = [[ZoomCCInterface sharedInstance] videoService];
[videoService endVideo];
```

```swift
let videoService = ZoomCCInterface.sharedInstance().videoService()
videoService.endVideo()
```

## Callbacks

These callbacks are available for both chat and video.

-   [`onEngagementVariablesRequired`](#onengagementvariablesrequired)
-   [`error`](#error)
-   [`engagementStart`](#engagementstart)
-   [`engagementEnd`](#engagementend)
-   [`eventChange`](#eventchange)
-   [`loginStatusChanged`](#loginstatuschanged)
-   [`unreadMsgCountChanged` (chat only)](#unreadmsgcountchanged-chat-only)

### `onEngagementVariablesRequired`

Called after login when the engagement application variables are known. Each dictionary can contain `variableGroupName`, `variableName`, and `attributeName`. Use `attributeName` as the key in `ZoomCCItem.engagementVariables`.

This callback only reports the variable definitions; the SDK sends matching values when the engagement is created.

-   `service`: the current service.
-   `variables`: an array of dictionaries describing variables that the current engagement may require. Each dictionary can contain `variableGroupName`, `variableName`, or `attributeName`.

    ```objectivec
    - (void)onService:(id<ZoomCCService>)service
    engagementVariablesRequired:(NSArray<NSDictionary<NSString *, NSString *> *> *)variables;
    ```

    ```swift
    func onService(_ service: ZoomCCService, engagementVariablesRequired variables: [[String: String]]) {
    }
    ```

### `error`

Sent after a service error.

-   `service` &mdash; the current service.
-   `error` &mdash; the service error code. See [errors](contact-center/errors) for details.
-   `detail` &mdash; the error details.

    ```objectivec
    - (void)onService:(id<ZoomCCService>)service error:(NSUInteger)error  detail:(NSInteger)detail;
    ```

    ```swift
    func onService(_ service: ZoomCCService, error: UInt, detail: Int) {
    }
    ```

### `engagementStart`

Sent after the service creates an engagement.

-   `service` &mdash; the current service.
-   `engagementId` &mdash; the engagement identifier.

    ```objectivec
    - (void)onService:(id<ZoomCCService>)service engagementStart:(NSString*)engagementId;
    ```

    ```swift
    func onService(_ service: ZoomCCService, engagementStart engagementId: String) {
    }
    ```

### `engagementEnd`

Sent after the engagement ends.

-   `service` &mdash; the current service.
-   `engagementId` &mdash; the engagement identifier.

    ```objectivec
    - (void)onService:(id<ZoomCCService>)service engagementEnd:(NSString*)engagementId;
    ```

    ```swift
    func onService(_ service: ZoomCCService, engagementEnd engagementId: String) {
    }
    ```

### `eventChange`

Sent when a change has occurred, for example, due to a user action.

-   `service` &mdash; the current service.
-   `event` &mdash; the event that occurred.

    ```objectivec
    - (void)onService:(id<ZoomCCService>)service eventChange:(ZoomCCSDKEvent)event;
    ```

    ```swift
    func onService(_ service: ZoomCCService, eventChange event: ZoomCCSDKEvent) {
    }
    ```

### `loginStatusChanged`

Sent when the login status has changed.

-   `service` &mdash; the current service.
-   `status` &mdash; the service status. `ZoomCCSDKStatus_Login` means the logging succeeded.

    ```objectivec
    - (void)onService:(id<ZoomCCService>)service loginStatusChanged:(ZoomCCSDKStatus)status;
    ```

    ```swift
    func onService(_ service: ZoomCCService, loginStatusChanged status: ZoomCCSDKStatus) {
    }
    ```

### `unreadMsgCountChanged` (chat only)

Sent when the number of unread messages has changed. Only sent for chat.

-   `service` &mdash; the current service.
-   `status` &mdash; the service status. `ZoomCCSDKStatus_Login` means the logging succeeded.

    ```objectivec
    - (void)onChatService:(id<ZoomCCChatService>)service unreadMsgCountChanged:(NSUInteger)count;
    ```

    ```swift
    func onChatService(_ service: ZoomCCChatService, unreadMsgCountChanged count: UInt) {
    }
    ```
