Core features

Enhance the collaborative experience of a session by using the screen sharing feature provided by the Video SDK for macOS. This feature gives users the ability to share their screen's content on a macOS device.

Screen sharing options

There are two different approaches for screen sharing with the Video SDK:

  1. Share the entire display
  2. Share a specific window

To use either method, retrieve a ZMVideoSDKShareHelper instance through the SDK.

let helper = ZMVideoSDK.shared()?.getShareHelper()
ZMVideoSDKShareHelper *helper = [[ZMVideoSDK sharedVideoSDK] getShareHelper];

After determining the type of share you are going to use, obtain the ID of the display or window you would like to share.

Start sharing

After obtaining the ID of the window or display you intend to share with your session, pass it into the corresponding startShare method.

Share a display

To share an entire display, pass its CGDirectDisplayID to startShareScreen.

helper?.startShareScreen(displayId, shareOption: ZMVideoSDKShareOption())
[helper startShareScreen:displayId shareOption:shareOptions];

Share a window

To share a single window, pass its CGWindowID to startShareView.

helper?.startShareView(windowId, shareOption: ZMVideoSDKShareOption())
[helper startShareView:windowId shareOption:shareOptions];

Verify screen share

After completing the above steps to share your screen, verify that your screen share has started by responding to the following callback to get notified when a user starts or stops screen sharing within your ZMVideoSDKDelegate.

func onUserShareStatusChanged(shareHelper: ZMVideoSDKShareHelper, user: ZMVideoSDKUser, shareAction: ZMVideoSDKShareAction) {
    switch shareAction.shareStatus {
    case .none:
        break
    // User has begun sharing.
    case .start:
        shareAction.getShareCanvas().subscribe(with: yourView, aspectMode: .original, resolution: .auto)
    case .pause:
        break
    case .resume:
        break
    // User has stopped sharing.
    case .stop:
        // Retrieve the share canvas and unsubscribe it from your view.
        shareAction.getShareCanvas().unSubscribe(with: yourView)
    default:
        break
    }
}
- (void)onUserShareStatusChanged:(ZMVideoSDKShareHelper*)shareHelper user:(ZMVideoSDKUser*)user shareAction:(ZMVideoSDKShareAction*)shareAction {
    switch (shareAction.shareStatus) {
        case ZMVideoSDKShareStatus_None:
            break;
        // User has begun sharing.
        case ZMVideoSDKShareStatus_Start:
            [[shareAction getShareCanvas] subscribeWithView:yourView aspectMode:ZMVideoSDKVideoAspect_Original resolution:ZMVideoSDKResolution_Auto];
        case ZMVideoSDKShareStatus_Pause:
            break;
        case ZMVideoSDKShareStatus_Resume:
            break;
        // User has stopped sharing.
        case ZMVideoSDKShareStatus_Stop:
            // Retrieve the share canvas and unsubscribe it from your view.
            [[shareAction getShareCanvas] unSubscribeWithView:yourView];
        default:
            break;
    }
}

To verify that the screen share data of a user is accessible on another device, subscribe to the user's share pipe.

let sharePipe = user.getSharePipe()
sharePipe?.subscribe(ZMVideoSDKResolution_720P, listener: self)
ZMVideoSDKRawDataPipe *sharePipe = [user getSharePipe];
[sharePipe subscribe:ZMVideoSDKResolution_720P listener:self];

Share device audio

There are two aspects to this:

  • Starting a share with audio enabled.
  • Starting audio share.

Start share with audio enabled

To include device audio when you begin sharing, create a ZMVideoSDKShareOption with isWithDeviceAudio enabled (and isOptimizeForSharedVideo for smoother video), then pass it to startShareScreen or startShareView.

let shareOptions = ZMVideoSDKShareOption()
shareOptions.isOptimizeForSharedVideo = true
shareOptions.isWithDeviceAudio = true
ZMVideoSDKShareOption *shareOption = [[ZMVideoSDKShareOption alloc] init];
shareOption.isOptimizeForSharedVideo = true;
shareOption.isWithDeviceAudio = true;

Start sharing audio

To toggle device audio on a share that is already in progress, call enableShareDeviceAudio on the share helper.

helper?.enableShareDeviceAudio(true)
helper?.enableOptimize(forSharedVideo: true)
[helper enableShareDeviceAudio:true];
[helper enableOptimizeForSharedVideo:true];

To draw over shared content, see Annotation. To subscribe to a specific share when a user has more than one, see Handle multiple screen shares.