Ohos
This topic describes how to use the screen sharing feature.
Note
1. For security reasons, screen sharing is disabled by default on mobile clients. To enable this feature, submit a ticket.
2. Your request must include your Alibaba Cloud UID and the AppId of the Real-Time Communication (RTC) application that requires screen sharing. The request must be submitted from your official company account.
Publisher
Start screen sharing.
// Configure screen sharing for stream ingest
// Get the DingRtcEngine instance
let dingRtc = DingRtcSDK.create(context);
let ret = dingRtc.startScreenShare(DingRtcConstants.RtcScreenShareMode.RtcScreenShareAll);
.....After you start the stream ingest, use a callback to check whether the screen share is published successfully.
onScreenSharePublishStateChanged(oldState: DingRtcConstants.RtcEnginePublishState, newState: DingRtcConstants.RtcEnginePublishState, elapseSinceLastState: number, channel: string): void {};Parameter
Type
Description
oldState
RtcEnginePublishState
The previous publishing state.
newState
RtcEnginePublishState
The current publishing state.
elapseSinceLastState
number
The time elapsed since the last state change, in milliseconds.
channel
String
The current channel ID.
Stop screen sharing.
let ret = dingRtc.stopScreenShare();;After you stop the screen share, use a callback to check whether it is successfully unpublished.
onScreenSharePublishStateChanged(oldState: DingRtcConstants.RtcEnginePublishState, newState: DingRtcConstants.RtcEnginePublishState, elapseSinceLastState: number, channel: string): void {};Parameter
Type
Description
oldState
RtcEnginePublishState
The previous publishing state.
newState
RtcEnginePublishState
The current publishing state.
elapseSinceLastState
int
The time elapsed since the last state change, in milliseconds.
channel
String
The current channel ID.
Listen for abnormal states. Implement the onOccurError callback to handle errors that occur during screen sharing.
onOccurError(error: number, msg: string): void { Prompt.showToast({ duration: 2000, message: 'onOccurError: ' + error + " ," + msg }); if (error == DingRtcConstants.ErrorCode.ScreenShareNoPermission) { Prompt.showToast({ duration: 2000, message: 'Screen recording permission is not enabled' }); this.local.isScreenOn = false; this.chat.pubScreen(this.local.isScreenOn, this.local.screenMode); } else if (error == DingRtcConstants.ErrorCode.ScreenShareStopByUser) { Prompt.showToast({ duration: 2000, message: 'Screen recording was manually stopped by the user' }); this.local.isScreenOn = false; this.chat.pubScreen(this.local.isScreenOn, this.local.screenMode); } else if (error == DingRtcConstants.ErrorCode.ScreenShareStopByOther) { Prompt.showToast({ duration: 2000, message: 'Screen recording was stopped by the system' }); this.local.isScreenOn = false; this.chat.pubScreen(this.local.isScreenOn, this.local.screenMode); }};
Subscriber
Subscribers can automatically or manually subscribe to the publisher's screen sharing video stream and set a view to display it. For more information, see the DingRtcEngine interface.