Screen share in a 1-to-1 call
This page provides a code example for screen share in a 1-to-1 call.
Sender - Prepare screen capture and start screen capture
-
After joining a 1-to-1 call, you can get a list of screens (monitors) and windows (applications) that can be captured.
class YourApplication {
private:
PlanetKit::PlanetKitCall m_pCall;
}
void YourApplication::RefreshScreenShareList() {
PlanetKit::PlanetKitManagerPtr pManager = PlanetKit::PlanetKitManager::GetInstance();
PlanetKit::ScreenShareControllerPtr pController = pManager->GetScreenShareController();
PlanetKit::ScreenShareInfoArray arrScreenShare;
pController->GetScreenShareInfos(arrScreenShare);
} -
Start transmitting screen capture by calling
StartMyScreenShare()
. The target to capture can be selected from the Array obtained in Step 1. You can check the result with a callback function of theResultCallback
type. If successful, you can register a window for rendering.void YourApplication::StartScreenShare(PlanetKit::ScreenShareInfoPtr pTarget) {
// 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_pCall->AddMyScreenShareVideoView(pApp->m_hScreenShareRenderWnd);
}
};
// Start screen share.
bool bResult = m_pCall->StartMyScreenShare(
pTarget,
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_pCall->StopMyScreenShare(nullptr, [](void* pUserData, bool bSuccess) {
// You can check result of `StopMyScreenShare()` with the `bSuccess` parameter.
if(bSuccess == true) {
...
}
});
// Remove rendering window.
m_pCall->RemoveMyScreenShareVideoView(m_hScreenShareRenderWnd);
}
Receiver - Receive screen share update events
Check whether a peer's screen share has started or stopped through the OnPeerStartedScreenShare
and OnPeerStoppedScreenShare
events of ICallEvent
.
class CallEventListener : public PlanetKit::ICallEvent {
public:
void OnPeerStartedScreenShare(PlanetKit::PlanetKitCallPtr pPlanetKitCall) override {
std::wstring message = L"OnPeerStartedScreenShare";
OutputDebugStringW(message.c_str());
// Peer started screen share.
// You can start rendering peer's screen share.
StartRenderingPeerScreenShare();
}
void OnPeerStoppedScreenShare(PlanetKit::PlanetKitCallPtr pPlanetKitCall, bool bHasReason, int nUserReason) override {
std::wstring message = L"OnPeerStoppedScreenShare";
OutputDebugStringW(message.c_str());
// Peer stopped screen share.
// You can stop rendering peer's screen share.
StopRenderingPeerScreenShare();
}
};
Receiver - Start rendering the peer's screen share video
To start rendering the peer's screen share video, call AddPeerScreenShareVideoView()
of PlanetKitCall
.
class YourApplication {
public:
void StartRenderingPeerScreenShare() {
m_pCall->AddPeerScreenShareVideoView(m_hScreenShareRenderWnd);
}
}
Receiver - Stop rendering the peer's screen share video
To stop rendering the peer's screen share video, call RemovePeerScreenShareVideoView()
of PlanetKitCall
.
class YourApplication {
public:
void StopRenderingPeerScreenShare() {
m_pCall->RemovePeerScreenShareVideoView(m_hScreenShareRenderWnd);
}
}