Screen Sharing
This document primarily provides API descriptions for the screen sharing functionality under the Mic Connect module.
1. Usage
1.1 Get Screen Sharing Info
API Method: getScreenShareInfo(): ScreenShareInfo
Return Value Description: Screen sharing information, of type ScreenShareInfo. Detailed type description is as follows:
| Property Name | Description | Type |
|---|---|---|
supportScreenShare |
Whether the current environment supports screen sharing | boolean |
screenShareMode |
Screen sharing mode | ScreenShareMode |
audioMixEnabled |
Screen sharing audio mixing toggle | boolean |
isScreenSharing |
Whether currently screen sharing | boolean |
supportPip |
Whether the current environment supports Picture-in-Picture | boolean |
isPiping |
Whether currently in Picture-in-Picture mode | boolean |
Example:
const screenShareInfo = watchCore.connectMic.getScreenShareInfo();
console.log('是否支持屏幕共享', screenShareInfo.supportScreenShare);
console.log('正在屏幕共享中', screenShareInfo.isScreenSharing);
1.2 Set Screen Sharing Configuration
Set the screen sharing configuration via setScreenShareConfig. Note that this method cannot be called to configure screen sharing while screen sharing is active.
API Method: setScreenShareConfig(config?: ScreenShareConfig): ScreenShareResult
Parameter Description:
- config: Screen sharing configuration, of type
ScreenShareConfig, optional, defaults to{}. Detailed type description is as follows:
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
screenShareMode |
Sharing mode | ScreenShareMode |
No | - |
audioMixEnabled |
Audio mixing toggle | boolean |
No | - |
Return Value Description: Setting result, of type ScreenShareResult
Example:
import { ScreenShareMode } from '@polyv/live-watch-sdk';
const result = await watchCore.connectMic.setScreenShareConfig({
// 共享模式:动态画面为主
screenShareMode: ScreenShareMode.Motion,
// 开启混音
audioMixEnabled: true,
});
if (result.success) {
console.log('设置成功');
}
1.3 Start Screen Sharing
Start screen sharing via startScreenShare. Monitor the start of screen sharing through the ConnectMicEvents.ScreenShareStart event. Note that user authorization from the browser is required before starting; if the user denies authorization, a failure result will be returned.
API Method: startScreenShare(): Promise<ScreenShareResult>
Return Value Description: Type Promise<ScreenShareResult>
Example:
import { ScreenShareError } from '@polyv/live-watch-sdk';
async function startScreenShare() {
const result = await watchCore.connectMic.startScreenShare();
if (result.success) {
const info = watchCore.connectMic.getScreenShareInfo();
console.log('已进入屏幕共享', info.isScreenSharing); // true
return;
}
if (result.failReason === ScreenShareError.BrowserNotSupport) {
toast.error('屏幕共享失败,您拒绝了系统权限');
}
}
1.4 Stop Screen Sharing
Stop screen sharing via stopScreenShare. Monitor the end of screen sharing through the ConnectMicEvents.ScreenShareStop event.
API Method: stopScreenShare(): Promise<ScreenShareResult>
Return Value Description: Type Promise<ScreenShareResult>
Example:
// 结束屏幕共享
watchCore.connectMic.stopScreenShare();
1.5 Show User Camera (Picture-in-Picture)
After screen sharing is started, the user's camera can be displayed via enterPip, entering Picture-in-Picture mode.
API Method: enterPip(): Promise<void>
Example:
// 显示画中画
await watchCore.connectMic.enterPip();
const info = watchCore.connectMic.getScreenShareInfo();
console.log('是否正在画中画模式', info.isPiping); // true
1.6 Hide User Camera (Picture-in-Picture)
After screen sharing is started, the user's camera can be hidden via exitPip, exiting Picture-in-Picture mode.
API Method: exitPip(): Promise<void>
Example:
// 隐藏画中画
await watchCore.connectMic.exitPip();
const info = watchCore.connectMic.getScreenShareInfo();
console.log('是否正在画中画模式', info.isPiping); // false
2. Other
2.1 Screen Sharing Error Reasons
Enum: ScreenShareError
| Constant | Enum Member | Description |
|---|---|---|
'Unknown' |
ScreenShareError.Unknown |
Unknown |
'BrowserNotSupport' |
ScreenShareError.BrowserNotSupport |
Current environment does not support screen sharing |
'ChannelNotSupport' |
ScreenShareError.ChannelNotSupport |
Current channel does not support screen sharing |
'PermissionDenied' |
ScreenShareError.PermissionDenied |
User permission denied |
'SystemPermissionDenied' |
ScreenShareError.SystemPermissionDenied |
System permission denied |
'ScreenShareing' |
ScreenShareError.ScreenShareing |
Cannot set screen sharing configuration while screen sharing is active |
