Screen Share (Beta)

iOS SDK provides support for sharing the entire screen of the device to the room.

Please note that for a peer to share their screen, their role must have screenshare enabled in the dashboard. Also select the appropriate resolution that you desire the screenshare track should be of.


How to start screenshare from the app

You create an iOS broadcast upload extension. It uses Apple's ReplayKit framework to record the device screen and delivers frame samples to your broadcast extension. You can share not ony your own app but also the entire device sceeen including other apps on the device.

HMSBroadcastExtensionSDK is made specifically to be used in the iOS broadcast upload extension target. After importing the SDK, you use HMSScreenRenderer class to process the sample buffer coming from RPBroadcastSampleHandler. These samples are then presented in your main meeting app as screen recording track.

How to import

Using Swift Package Manager

You can use Swift Package Manager (use as the package source)

Add HMSBroadcastExtensionSDK to your main app target from Swift Package Manager. Then add HMSBroadcastExtensionSDK to your iOS broadcast upload extension target.

Using Cocoapods

Get the HMSBroadcastExtensionSDK via Cocoapods. Add the pod 'HMSBroadcastExtensionSDK' to your broadcast upload extension target in Podfile as follows:

# Podfile platform :ios, '12.0' target 'MainApp' do pod 'HMSSDK' end target 'HMSScreenShare' do pod 'HMSBroadcastExtensionSDK' end

How to use HMSBroadcastExtensionSDK to share iOS screen with other participants in the room?

iOS broadcast extension provides you with CMSampleBuffers that you can process using HMSBroadcastExtensionSDK. This enabled you to share the screen with other participants in the room in your main app that uses HMSSDK.

How to create Replaykit Broadcast extension?

  1. Create a Broadcast Upload Extension target that is embeded in your app project target.
  2. You create a subclass of RPBroadcastSampleHandler and override processSampleBuffer funtion. This gives you access to the CMSampleBuffer provided by the Replaykit framework.

How to configure your main app and extension to enable screen sharing

  1. Configure an App Group for your main app. Choose the same App Group for your broadcast extension target.
  2. In your main app set the app group string to the hmssdk instance like below:
hmsSDK = { sdk in sdk.appGroup = "" ... }
  1. In your broadcast extension import HMSBroadcastExtensionSDK
import HMSBroadcastExtensionSDK
  1. Create an instance of HMSScreenRenderer passing the app group string like below:

    class SampleHandler: RPBroadcastSampleHandler { let screenRenderer = HMSScreenRenderer(appGroup: "") ...

    HMSScreenRenderer uses this app group string to talk to your main app.

How to share screen in meeting

In your broadcast extension you create a subclass of RPBroadcastSampleHandler class. This class handles screen frame samples produced by Replaykit. Replaykit delivers these frame as CMSampleBuffer to processSampleBuffer function.

In your processSampleBuffer function call process function on your screenRenderer instance passing the CMSampleBuffer like below:

override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) { switch sampleBufferType { case // Handle video sample buffer screenRenderer.process(sampleBuffer) ... }

How to invalidate the connection between main app and extension when user stops screen recording

When user stops screen sharing broadcastFinished function is called on your RPBroadcastSampleHandler class. At that point call invalidate on your screenRenderer instance to stop sceen sharing.

override func broadcastFinished() { // User has requested to finish the broadcast. self.screenRenderer.invalidate() }

Stop screen sharing when user leaves the room

When user leaves the meeting room from the main app, you will receive an error HMSScreenRendererErrorCode.noActiveMeeting when calling process on screenRenderer instance. You can handle this error to stop the broadcast extension like below:

override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) { switch sampleBufferType { case // Handle video sample buffer if let error = screenRenderer.process(sampleBuffer) { if error.code == .noActiveMeeting { finishBroadcastWithError(NSError(domain: "ScreenShare", code: error.code.rawValue, userInfo: [NSLocalizedFailureReasonErrorKey : "You are not in a meeting."])) } } ... }

👀 To see an Example iOS broadcast upload extension implementation for screen sharing using 100ms Broadcast extension SDK, checkout our Example project.

📲 Download the 100ms fully featured Sample iOS app here: