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.
You can use Swift Package Manager (use https://github.com/100mslive/100ms-ios-broadcast-sdk.git 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.
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'
endYou 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.
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.
- Create a Broadcast Upload Extension target that is embeded in your app project target.
- You create a subclass of RPBroadcastSampleHandler and override processSampleBuffer funtion. This gives you access to the CMSampleBuffer provided by the Replaykit framework.
- Configure an App Group for your main app. Choose the same App Group for your broadcast extension target.
- In your main app set the app group string to the hmssdk instance like below:
hmssdk.appGroup = "group.live.100ms.videoapp"- In your broadcast extension import HMSBroadcastExtensionSDK
import HMSBroadcastExtensionSDK- Create an instance of HMSScreenRenderer passing the app group string like below:
let screenRenderer = HMSScreenRenderer(appGroup: "group.live.100ms.videoapp")HMSScreenRenderer uses this app group string to talk to your main app.
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:
screenRenderer.process(sampleBuffer)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()
}👀 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: https://testflight.apple.com/join/dhUSE7N8