Skip to main content
Android
iOS
macOS
Web
Windows
Electron
Flutter
React Native
React JS
Unity
Unreal Engine
Unreal (Blueprint)

Screen sharing

During Interactive Live Streaming sessions, hosts use the screen sharing feature in the Agora Video SDK to share their screen content with other users or viewers in the form of a video stream. Screen sharing is typically used in the following scenarios:

ScenarioDescription
Online educationTeachers share their slides, software, or other teaching materials with students for classroom demonstrations.
Game live broadcastHosts share their game footage with the audience.
Interactive live broadcastAnchors share their screens and interact with the audience.
Video conferencingMeeting participants share the screen to show a presentation or documents.
Remote controlA controlled terminal displays its desktop on the master terminal.

Agora screen sharing offers the following advantages:

  • Ultra HD quality experience: Supports Ultra HD video (4K resolution, 60 FPS frame rate), giving users a smoother, high-definition, ultimate picture experience.
  • Multi-app support: Compatible with many mainstream apps such as WPS Office, Microsoft Office Power Point, Visual Studio Code, Adobe Photoshop, Windows Media Player, and Scratch. This makes it convenient for users to directly share specific apps.
  • Multi-device support: Supports multiple devices sharing at the same time. Screen sharing is compatible with Windows 8 systems, devices without independent graphics cards, dual graphics card devices, and external screen devices.
  • Multi-platform adaptation: Supports iOS, Android, macOS, Windows, Web, Unity, Flutter, React Native, Unreal Engine, and other platforms.
  • High security: Supports sharing only a single app or part of the screen. Also supports blocking specified app windows, effectively ensuring user information security.

This page shows you how to implement screen sharing in your app.

Understand the tech

The screen sharing feature provides the following screen sharing modes for use in various scenarios:

Screen Sharing Functionality

  • Share the entire screen: Share your entire screen, including all the information on the screen. This feature supports collecting and sharing information from two screens at the same time.
  • Share an app window: If you don't want to share the entire screen with other users, you can share only the area within an app window.
  • Share a designated screen area: If you only want to share a portion of the screen or app window, you can set a sharing area when starting screen sharing.

Screen sharing modes are available on different platforms as follows:

  • Desktop (Windows and macOS): Supports all screen sharing features listed above.
  • Mobile (Android and iOS): Only supports sharing the entire screen.

Prerequisites

  • Ensure that you have implemented the SDK quickstart in your project.

Implement screen sharing

This section introduces how to implement screen sharing in your project.

Android implementation

When enabling screen sharing on Android, you only need to call the startScreenCapture method. Refer to the screen sharing sample project to implement screen sharing.

iOS implementation

Since Apple does not support capturing the screen in the main process of the app, you create a separate extension for the screen sharing stream. You use the iOS native ReplayKit framework in the extension to record the screen, and then send the screen sharing stream to the main process.

Screen Sharing React Native Tech

Take the following steps to set up your screen sharing project:

  1. Go to your project folder and open the ios/.xcodeproj file with Xcode.

  2. Create a Broadcast Upload Extension to enable the process of screen sharing:

    1. Navigate to File > New > Target..., select Broadcast Upload Extension in the popup window, and then click Next:

      Select Broadcast Upload Extension

    2. Fill in the Product Name and other information in the popup window, uncheck Include UI Extension, and click Finish. Xcode automatically creates a folder for the extension that contains the SampleHandler.h files.

    3. Under Target, select the newly created extension. Click General and set the iOS version to 12.0 or later under Deployment Info.

    4. Modify project settings to implement the screen sharing code logic, and choose one of the following methods according to your business needs:

      • To use the functionality in the AgoraReplayKitExtension.xcframework dynamic library provided by Agora, select Target as the extension you just created, and change the Value in Info corresponding to NSExtension > NSExtensionPrincipalClass from $(PRODUCT_MODULE_NAME}.SampleHandler to AgoraReplayKitHandler:

        Use AgoraReplayKitHandler

      • To implement additional business logic, refer to the following code to modify the SampleHandler.h file:

        #import "SampleHandler.h"
        #import "AgoraReplayKitExt.h"
        #import <sys/time.h>

        @interface SampleHandler ()<AgoraReplayKitExtDelegate>

        @end

        @implementation SampleHandler

        - (void)broadcastStartedWithSetupInfo:(NSDictionary<NSString *,NSObject *> *)setupInfo {
        // User request to start broadcasting
        [[AgoraReplayKitExt shareInstance] start:self];

        }

        - (void)broadcastPaused {
        // User requests to pause the broadcast, screen sharing is paused
        NSLog(@"broadcastPaused");
        [[AgoraReplayKitExt shareInstance] pause];
        }

        - (void)broadcastResumed {
        // User requests to resume broadcasting, screen sharing is resumed
        NSLog(@"broadcastResumed");
        [[AgoraReplayKitExt shareInstance] resume];

        }

        - (void)broadcastFinished {
        // User requests to stop broadcasting
        NSLog(@"broadcastFinished");
        [[AgoraReplayKitExt shareInstance] stop];

        }

        - (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer withType:(RPSampleBufferType)sampleBufferType {
        [[AgoraReplayKitExt shareInstance] pushSampleBuffer:sampleBuffer withType:sampleBufferType];
        }

        #pragma mark - AgoraReplayKitExtDelegate

        - (void)broadcastFinished:(AgoraReplayKitExt *_Nonnull)broadcast reason:(AgoraReplayKitExtReason)reason {
        switch (reason) {
        case AgoraReplayKitExtReasonInitiativeStop:
        {
        NSLog(@"AgoraReplayKitExtReasonInitiativeStop");
        }
        break;
        case AgoraReplayKitExtReasonConnectFail:
        {
        NSLog(@"AgoraReplayKitExReasonConnectFail");
        }
        break;

        case AgoraReplayKitExtReasonDisconnect:
        {
        NSLog(@"AgoraReplayKitExReasonDisconnect");
        }
        break;
        default:
        break;
        }
        }

        @end
        Copy
  3. Combine the call to startScreenCapture with the user's action to enable screen sharing in your app. To do this, use one of the following methods:

    • Use Apple's new RPSystemBroadcastPickerView in iOS 12.0 to make the Enable Screen Sharing button pop up on the app interface, prompting the user to click the button to start recording.

      information
      This is the default method for React Native SDK, but RPSystemBroadcastPickerView has some usage restrictions and may not work in later versions of iOS. If it fails, use the following method instead.
    • Prompt the user to long click the screen recording button in the Control Center on iOS and choose to use the extension you created to start recording.

Development notes

  • If you use Cocoapods, add the following content to the Podfile file to add a dependency for your screen sharing extension. Replace ScreenSharing with the target name of your screen sharing extension:

    target 'ScreenSharing' do
    # Change the version to match the SDK dependency in the node_modules/react-native-agora/react-native-agora.podspec file
    pod 'AgoraRtcEngine_iOS', 'version'
    end
    Copy
  • The memory usage of Broadcast Upload Extension is limited to 50 MB. Make sure that the memory usage of Screen Sharing Extension does not exceed 50 MB.

Limitations

Be aware of the following limitations:

iOS platform

  • Due to system limitations, screen sharing is only supported on iOS 12.0 and above.
  • This feature requires a high level of device performance. Agora recommends that you use an iPhone X or above.
  • The video unit price for a screen-sharing stream is based on the video resolution you set in ScreenCaptureParameters. If you do not pass dimensions in ScreenCaptureParameters, Agora bills you at the default resolution of 1920 x 1080 (2,073,600). See Pricing for details.

Reference

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

Sample project

Agora provides open source sample projects on GitHub for your reference:

API reference

Interactive Live Streaming