Skip to main content
Version: 5.5

Screen share in a group call

This page provides a code example for screen share in a group call (conference).

Sender - Prepare screen capture and start screen capture

  1. After joining a group call, you can get a list of screens (monitors) and windows (applications) that can be captured.

    class YourApplication {
    private:
    PlanetKit::PlanetKitConference m_pConference;
    }

    void YourApplication::RefreshScreenShareList() {
    PlanetKit::PlanetKitManagerPtr pManager = PlanetKit::PlanetKitManager::GetInstance();
    PlanetKit::ScreenShareControllerPtr pController = pManager->GetScreenShareController();
    PlanetKit::ScreenShareInfoArray arrScreenShare;
    pController->GetScreenShareInfos(arrScreenShare);
    }
  2. Start transmitting screen capture by calling StartMyScreenShare(). The target to capture can be selected from the Array obtained in Step 1.

    • The strSubgroupName parameter determines the destination subgroup of the screen share, and if it is NullOptional, the screen share will be sent to the main room.
    • You can check the result with a callback function of the ResultCallback type. If successful, you can register a window for rendering.
    void YourApplication::StartScreenShare(PlanetKit::ScreenShareInfoPtr pTarget, const WStringOptional& strSubgroupName) {
    // This is result callback function.
    auto callback = [](void* pUserData, bool bSuccess) {
    // You can check result of `StartScreenShare` with parameter `bSuccess`.
    if(bSuccess == true) {
    // You can set rendering window.
    YourApplication* pApp = (YourApplication*)pUserData;
    pApp->m_pConference->AddMyScreenShareVideoView(pApp->m_hScreenShareRenderWnd);
    }
    };

    // Start screen share.
    bool bResult = m_pConference->StartMyScreenShare(
    pTarget,
    strSubgroupName,
    this,
    callback
    );
    }

Sender - Stop sending screen share

Call StopMyScreenShare() to stop screen share and get the result with a callback function of the ResultCallback type as in Step 2 of Prepare screen capture and start screen capture.

void YourApplication::StopScreenShare() {
...
// You can use callback parameter by using lambda function.
bool bResult = false = m_pConference->StopMyScreenShare(nullptr, [](void* pUserData, bool bSuccess) {
// You can check result of `StopMyScreenShare()` with the `bSuccess` parameter.
if(bSuccess == true) {
...
}
});

// Remove rendering window.
m_pConference->RemoveMyScreenShareVideoView(m_hScreenShareRenderWnd);
}

Receiver - Receive screen share update events

Check whether a peer's screen share has started or stopped through the OnScreenShareUpdated event of IPeerControlEvent.

class PeerControlEventListener : public PlanetKit::IPeerControlEvent {
public:
void OnScreenShareUpdated(PlanetKit::PeerControlPtr pPeerControl, PlanetKit::SubgroupPtr pSubgroup, PlanetKit::EScreenShareState eState) override {
std::wstring message = L"OnScreenShareUpdated, User=" + pPeerControl->GetPeer()->GetUserID()->GetID().c_str() + L" ScreenShareState=" + std::to_wstring(eState) + L"\n";
OutputDebugStringW(message.c_str());

if(eState == PlanetKit::EScreenShareState::PLNK_SCREEN_SHARE_STATE_ENABLED) {
m_pYourApp->RequestPeerScreenShare(pPeerControl, pSubgroup);
}
else {
m_pYourApp->StopPeerScreenShare();
}
}
private:
YourApplication* m_pYourApp; // Prepare instance of YourApplication
};

Receiver - Request a peer's screen share video and render the video

To request a screen share video from the peer, call StartScreenShare() of PeerControl.

To render the received screen share video, call SetScreenShareView() of PeerControl.

class YourApplication {
public:
void RequestPeerScreenShare(PlanetKit::PeerControlPtr pPeerControl, PlanetKit::SubgroupPtr pSubgroup) {
auto callback = [](void* pUserData, bool bSuccess) {
YourApplication* pApp = (YourApplication*)pUserData;
if(bSuccess == true) {
// Render peer's screen share.
pApp->m_pScreenSharePeerControl->SetScreenShareView(m_hScreenShareRenderWnd);
}
}

// You can keep instance of PeerControl for the peer who is performing screen share.
m_pScreenSharePeerControl = pPeerControl;

// Start peer's screen share.
pPeerControl->StartScreenShare(pSubgroup->GetSubgroupName(), this, callback);
}
private:
PlanetKit::PeerControlPtr m_pScreenSharePeerControl;
}

Receiver - Stop receiving a peer's screen share video

To stop receiving the peer's screen share video, call ClearScreenShareView() of PeerControl to stop rendering, and then call StopScreenShare() of PeerControl.

class YourApplication {
public :
void StopPeerScreenShare() {
// Remove render.
m_pScreenSharePeerControl->ClearScreenShareView();

// Request to stop screen share.
m_pScreenSharePeerControl->StopScreenShare();
}
}