Windows

Updated at:

The screen sharing feature on Windows lets you share an entire screen or a specific window. Your application can ingest the shared content as a stream. This topic describes how to share your screen on a Windows device.

Screen sharing

  1. After creating a software development kit (SDK) instance on the stream ingest client, call the GetScreenShareSourceInfo method to retrieve the available screen sharing sources. Set the sourceType parameter to RtcEngineScreenShareDesktop. The SDK then returns all display devices connected to the current device.

    ding::rtc::RtcEngine *engine_ =;
    
    // Get the screen sharing source
    ding::rtc::RtcEngineDeviceInfoList *list = engine_->GetScreenShareSourceInfo(ding::rtc::RtcEngineScreenShareDesktop);
    
    // Traverse all supported screens
    for (int i = 0; i < list.GetCount(); i++) {
    
    }
    
    // Release the list
    list->Release();
    
    Note

    Screen sharing returns multiple sources only when more than one display is connected to the current device.

  2. Call the StartScreenShareByDesktopId method to configure and start screen sharing. Set the desktopId parameter to the ID of the screen that you want to share, which you obtained in the previous step.

    // Set the screen sharing source to screen sharing and specify the source ID of the screen to share
    ding::rtc::RtcEngineScreenShareConfig config; // share whole screen by default
    
    // Set the content to share
    engine_->StartScreenShareByDesktopId(desktopId, config);
  3. After sharing starts, use a callback to check if the screen share was published successfully.

    void OnScreenSharePublishStateChanged(RtcEnginePublishState oldState, RtcEnginePublishState newState, int elapseSinceLastState, const char *channel);

    Name

    Type

    Description

    oldState

    RtcEnginePublishState

    The previous stream ingest state.

    newState

    RtcEnginePublishState

    The current stream ingest state.

    elapseSinceLastState

    int

    The time interval since the last state change.

    channel

    const char *

    The current channel ID.

  4. To stop sharing, stop the screen sharing stream.

    // Configure to stop screen sharing
    engine_->StopScreenShare();
  5. After stopping the screen sharing stream, use a callback to check if the stream was unpublished successfully.

    void OnScreenSharePublishStateChanged(RtcEnginePublishState oldState, RtcEnginePublishState newState, int elapseSinceLastState, const char *channel);

    Name

    Type

    Description

    oldState

    RtcEnginePublishState

    The previous stream ingest state.

    newState

    RtcEnginePublishState

    The current stream ingest state.

    elapseSinceLastState

    int

    The time interval since the last state change.

    channel

    const char *

    The current channel ID.

Window sharing

  1. After creating an SDK instance on the stream ingest client, call the GetScreenShareSourceInfo method to retrieve the available window sharing sources. Set the sourceType parameter to RtcEngineScreenShareWindow. The SDK then returns all visible application windows on the current device.

    ding::rtc::RtcEngine *engine_ =;
    
    // Get the screen sharing source
    ding::rtc::RtcEngineDeviceInfoList *list = engine_->GetScreenShareSourceInfo(ding::rtc::RtcEngineScreenShareWindow);
    
    // Traverse all supported windows
    for (int i = 0; i < list.GetCount(); i++) {
    
    }
    
    // Release the list
    list->Release();
    Note

    The SDK returns only currently visible windows (not minimized and with a size greater than 0) as sharing sources.

  2. Call the StartScreenShareByWindowId method to configure and start window sharing. Set the windowId parameter to the ID of the window that you want to share, which you obtained in the previous step.

    // Set the screen sharing source to window sharing and specify the source ID of the window to share
    ding::rtc::RtcEngineScreenShareConfig config; // share whole window by default
    
    // Set the content to share
    engine_->StartScreenShareByWindowId(windowId, config);
  3. After sharing starts, use a callback to check if the screen share was published successfully.

    void OnScreenSharePublishStateChanged(RtcEnginePublishState oldState, RtcEnginePublishState newState, int elapseSinceLastState, const char *channel);

    Name

    Type

    Description

    oldState

    RtcEnginePublishState

    The previous stream ingest state.

    newState

    RtcEnginePublishState

    The current stream ingest state.

    elapseSinceLastState

    int

    The time interval since the last state change.

    channel

    const char *

    The current channel ID.

  4. To stop sharing, stop the screen sharing stream.

    // Stop screen sharing.
    pEngine->StopScreenShare();
  5. After stopping the screen sharing stream, use a callback to check if the stream was unpublished successfully.

    void OnScreenSharePublishStateChanged(RtcEnginePublishState oldState, RtcEnginePublishState newState, int elapseSinceLastState, const char *channel);

    Name

    Type

    Description

    oldState

    RtcEnginePublishState

    The previous stream ingest state.

    newState

    RtcEnginePublishState

    The current stream ingest state.

    elapseSinceLastState

    int

    The time interval since the last state change.

    channel

    const char *

    The current channel ID.

Share audio while sharing the screen

To share system audio while sharing your screen, call GetAudioDeviceManager->EnableSystemAudio(true). For more information, see DingRtcEngineAudioDeviceManager.

Subscriber client

Users on the subscriber client can subscribe to the screen sharing video stream either automatically or manually and set a view for its display. For more information, see DingRtcEngine interface.