# Screen sharing (/en/realtime-media/interactive-live-streaming/build/manage-video-and-streaming/screen-sharing/unity)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

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 use-cases:

| Use-case                   | Description                                                                                                    |
| :------------------------- | :------------------------------------------------------------------------------------------------------------- |
| Online education           | Teachers share their slides, software, or other teaching materials with students for classroom demonstrations. |
| Game live broadcast        | Hosts share their game footage with the audience.                                                              |
| Interactive live broadcast | Anchors share their screens and interact with the audience.                                                    |
| Video conferencing         | Meeting participants share the screen to show a presentation or documents.                                     |
| Remote control             | A 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 game.

    ## Understand the tech [#understand-the-tech-8]

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

    **Screen sharing use-cases**

    ![Screen Sharing Functionality](https://assets-docs.agora.io/images/video-sdk/screen-sharing-functionality.png)

    * **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 [#prerequisites-8]

    * Ensure that you have implemented the [SDK quickstart](../../index.mdx) in your project.

    ## Set up your project [#set-up-your-project-8]

    <CodeBlockTabs defaultValue="ios">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="ios">
          iOS
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="macos-and-windows">
          macOS and Windows
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="ios">
        You use the iOS native `ReplayKit` framework in the extension to record the screen, and then add the screen sharing stream to the channel as a user. 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.

        ![Screen Sharing Unity Tech](https://assets-docs.agora.io/images/video-sdk/screen-sharing-flutter-unity-rn-blueprint.svg)
      </CodeBlockTab>

      <CodeBlockTab value="macos-and-windows">
        Windows or macOS systems assign a unique **Display ID** to each screen and a unique **Window ID** to each window. Agora currently supports the following two screen sharing options on the macOS, Windows platforms:

        * Share a specific screen or part of a specified screen: Call `GetScreenCaptureSources` to get the **Display ID** and then call `StartScreenCaptureByDisplayId` to start screen sharing.
        * Share a specific window or part of a specified window: Call `GetScreenCaptureSources` to get the **Window ID** and then call `StartScreenCaptureByWindowId` to start screen sharing.
      </CodeBlockTab>
    </CodeBlockTabs>

    ## Implement screen sharing [#implement-screen-sharing-8]

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

    <CodeBlockTabs defaultValue="android">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="android">
          Android
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="ios">
          iOS
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="macos-and-windows">
          macOS and Windows
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="android">
        When enabling screen sharing on Android, call the `StartScreenCapture` method. Depending on the actual business use-case, choose either of the following methods to implement screen sharing:

        * Call `StartScreenCapture` before joining the channel, then call `JoinChannel[2/2]` to join the channel and set `publishScreenCaptureVideo` to `true` to start screen sharing.

          ```csharp
          // Call StartScreenCapture to enable screen sharing before joining a channel.
          ScreenCaptureParameters2 screenCaptureParameters2 = new ScreenCaptureParameters2();
          screenCaptureParameters2.captureVideo = true;
          screenCaptureParameters2.captureAudio = true;
          RtcEngine.StartScreenCapture(screenCaptureParameters2);
          // Call JoinChannel to join a channel.
          ChannelMediaOptions channelMediaOptions = new ChannelMediaOptions();
          channelMediaOptions.publishScreenCaptureVideo.SetValue(true);
          channelMediaOptions.publishScreenCaptureAudio.SetValue(true);
          channelMediaOptions.publishCameraTrack.SetValue(false);
          channelMediaOptions.publishMicrophoneTrack.SetValue(false);
          RtcEngine.JoinChannel("token", "channelId", uid, channelMediaOptions);
          ```

        * Call `StartScreenCapture` after joining the channel, then call `UpdateChannelMediaOptions` to set `publishScreenCaptureVideo` to `true` to start screen sharing.

          ```csharp
          // Call JoinChannel to join the channel.
          RtcEngine.JoinChannel(_token, _channelName);
          ScreenCaptureParameters2 screenCaptureParameters2 = new ScreenCaptureParameters2();
          screenCaptureParameters2.captureVideo = true;
          screenCaptureParameters2.captureAudio = true;
          // Enable screen sharing.
          RtcEngine.StartScreenCapture(screenCaptureParameters2);
          ChannelMediaOptions channelMediaOptions = new ChannelMediaOptions();
          channelMediaOptions.publishScreenCaptureVideo.SetValue(true);
          channelMediaOptions.publishScreenCaptureAudio.SetValue(true);
          channelMediaOptions.publishCameraTrack.SetValue(false);
          channelMediaOptions.publishMicrophoneTrack.SetValue(false);
          // Update channel media options.
          RtcEngine.UpdateChannelMediaOptions(channelMediaOptions);
          ```
      </CodeBlockTab>

      <CodeBlockTab value="ios">
        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 add the screen sharing stream to the channel as a user.

        **Screen sharing Unity tech**

        ![Screen Sharing Unity Tech](https://assets-docs.agora.io/images/video-sdk/screen-sharing-flutter-unity-rn-blueprint.svg)

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

        1. Package the iOS project in **Unity Editor** and export the Xcode project.

        2. Go to your project folder and open the `unity-iphone/.xcodeproj` folder with Xcode.

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

        4. Navigate to &#x2A;*File > New > Target...**, select **Broadcast Upload Extension** in the popup window, and then click **Next**:

           ![Select Broadcast Upload Extension](https://assets-docs.agora.io/images/video-sdk/screen-sharing-ios-select-broadcast-upload-extension.png)

        5. 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.m` file.

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

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

           * If you only need 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*&#x2A; from **$(PRODUCT\_MODULE\_NAME}.SampleHandler** to **AgoraReplayKitHandler**:

             ![Use AgoraReplayKitHandler](https://assets-docs.agora.io/images/video-sdk/screen-sharing-ios-use-agorareplaykithandler.png)

           * If you need to implement some additional business logic, refer to the following code to modify the `SampleHandler.m` file:

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

             @interface SampleHandler ()<AgoraReplayKitExtDelegate>

             @end

             @implementation SampleHandler

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

             }

             - (void)broadcastPaused {
              NSLog(@"broadcastPaused");
              [[AgoraReplayKitExt shareInstance] pause];
             }

             - (void)broadcastResumed {
              NSLog(@"broadcastResumed");
              [[AgoraReplayKitExt shareInstance] resume];

             }

             - (void)broadcastFinished {
              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:
                 {

                 }
                 break;
                 case AgoraReplayKitExtReasonConnectFail:
                 {

                 }
                 break;

                 case AgoraReplayKitExtReasonDisconnect:
                 {

                 }
                 break;
                 default:
                 break;
               }
             }

             @end
             ```

        8. Select the extension you created in **TARGETS** and add all frameworks under the path &#x2A;*Frameworks/Agora-RTC-Plugin/Agora-Unity-RTC-SDK/Plugins/iOS/** in **General/Frameworks and Libraries**.

        9. To start screen sharing, call `StartScreenCapture` combined with the user's action. For example, prompt the user to press and hold the **Screen Recording** button in the Control Center on iOS, and select the extension you created to start recording.
           <CalloutContainer type="info">
             <CalloutDescription>
               <ul>
                 <li>Make sure your app and extension have the same **TARGETS/Deployment/iOS** version. The memory usage of **Broadcast Upload Extension** is limited to 50 MB. </li>

                 <li>Make sure that the memory usage of **Screen Sharing Extension** does not exceed 50 MB.</li>
               </ul>
             </CalloutDescription>
           </CalloutContainer>
      </CodeBlockTab>

      <CodeBlockTab value="macos-and-windows">
        Windows and macOS systems assign a unique **Display ID** to each screen and a unique **Window ID** to each window. Agora currently supports the following screen sharing options for macOS and Windows:

        * Share a specific screen or a portion of a specified screen: Call `GetScreenCaptureSources` to get the **Display ID** and then call `StartScreenCaptureByDisplayId` to start screen sharing.
        * Share a specific window or a portion of a specified window: Call `GetScreenCaptureSources` to get the **Window ID** and then call `StartScreenCaptureByWindowId` to start screen sharing.

        Take the following steps to implement screen sharing on macOS and Windows:

        3. Get a list of screens and windows that can be shared. Call `GetScreenCaptureSources` method to get the **Display ID** of the screen or the **Window ID** of the window to be shared:

           ```csharp
           SIZE thumbSize = new SIZE(360,240);
           SIZE iconSize = new SIZE(360,240);
           ScreenCaptureSourceInfo[] screenCaptureSourceInfos = RtcEngine.GetScreenCaptureSources(thumbSize, iconSize, true);
           ```

        4. Share the specified screen or window. Depending on the sharing object, call the `StartScreenCaptureByDisplayId` or `StartScreenCaptureByWindowId` method to start screen sharing:

           ```csharp
           ScreenCaptureSourceInfo info = screenCaptureSourceInfos[0];
           if (info.type == ScreenCaptureSourceType.ScreenCaptureSourceType_Screen)
           {
             ulong displayId = info.sourceId;
             RtcEngine.StartScreenCaptureByDisplayId((uint)displayId, default(Rectangle),default(ScreenCaptureParameters));
           }
            else if (info.type == ScreenCaptureSourceType.ScreenCaptureSourceType_Window)
           {
              ulong windowId = info.sourceId;
              RtcEngine.StartScreenCaptureByWindowId(windowId, default(Rectangle),default(ScreenCaptureParameters));
           }
           ```

        5. Join a channel and publish screen sharing stream.

           * To publish only the screen sharing stream, add the following code to your project:

             ```csharp
             ChannelMediaOptions options = new ChannelMediaOptions();
              options.publishCameraTrack.SetValue(false);
              options.publishScreenTrack.SetValue(true);

             #if UNITY_ANDROID || UNITY_IPHONE
              options.publishScreenCaptureAudio.SetValue(true);
              options.publishScreenCaptureVideo.SetValue(true);
             #endif
               RtcEngine.UpdateChannelMediaOptions(options);
             ```

           * To publish a screen sharing stream and the video stream captured by a local camera simultaneously, add the following code to your project:

             ```csharp
             // Join a channel and push the camera stream
             RtcEngine.EnableAudio();
             RtcEngine.EnableVideo();
             RtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);

             ChannelMediaOptions options = new ChannelMediaOptions();
             options.autoSubscribeAudio.SetValue(true);
             options.autoSubscribeVideo.SetValue(true);

             options.publishCameraTrack.SetValue(true);
             options.publishScreenTrack.SetValue(false);
             options.enableAudioRecordingOrPlayout.SetValue(true);
             options.clientRoleType.SetValue(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);
             RtcEngine.JoinChannel(_token, _channelName, this.Uid1, options);

             // Join a channel and push the screen sharing stream
             ChannelMediaOptions options = new ChannelMediaOptions();
             options.autoSubscribeAudio.SetValue(false);
             options.autoSubscribeVideo.SetValue(false);
             options.publishCameraTrack.SetValue(false);
             options.publishScreenTrack.SetValue(true);
             options.enableAudioRecordingOrPlayout.SetValue(false);
             #if UNITY_ANDROID || UNITY_IPHONE
             options.publishScreenCaptureAudio.SetValue(true);
             options.publishScreenCaptureVideo.SetValue(true);
             #endif
             options.clientRoleType.SetValue(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);
             var ret = RtcEngine.JoinChannelEx(_token, new RtcConnection(_channelName, this.Uid2), options);
             ```
      </CodeBlockTab>
    </CodeBlockTabs>

    ### Limitations [#limitations-8]

    Be aware of the following limitations:

    * 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](../../reference/pricing.md) for details.
    * 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.

    ## Reference [#reference-8]

    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 [#sample-project-8]

    Agora provides an open-source Unity [sample project](https://github.com/AgoraIO-Extensions/Agora-Unity-Quickstart/tree/main/API-Example-Unity/Assets/API-Example/Examples/Advanced/ScreenShare) on GitHub. Download and explore this project for a more detailed example.

    ### API reference [#api-reference-7]

    * Common
      * [`EnableAudio`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_enableaudio)
      * [`EnableVideo`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_enablevideo)
      * [`SetClientRole` \[1/2\]](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_setclientrole)
      * [`UpdateChannelMediaOptions`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_updatechannelmediaoptions)
      * [`ChannelMediaOptions`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_channelmediaoptions.html)
      * [`JoinChannel` \[2/2\]](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_joinchannel2)
      * [`JoinChannelEx`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengineex.html#api_irtcengineex_joinchannelex)

    * Android
      * [`StartScreenCapture` \[1/2\]](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_startscreencapture)
      * [`StopScreenCapture` \[1/2\]](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_stopscreencapture)
      * [`JoinChannel` \[2/2\]](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_joinchannel2)

    * iOS
      * [`StartScreenCapture` \[1/2\]](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_startscreencapture)
      * [`StopScreenCapture` \[1/2\]](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_stopscreencapture)
      * [`UpdateScreenCaptureParameters`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_updatescreencaptureparameters)

    * macOS, Windows
      * [`GetScreenCaptureSources`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_getscreencapturesources)
      * [`StartScreenCaptureByDisplayId`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_startscreencapturebydisplayid)
      * [`StartScreenCaptureByWindowId`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_startscreencapturebywindowid)

    
  
      
  
      
  
