Skip to content

Web SDK Integration Guide ​

Web SDK for cloud phone screen casting and real-time control.

1. Installation and Import ​

js
npm install @vmaos/web-cast-sdk

import { UniSDK } from '@vmaos/web-cast-sdk/uni-sdk';

2. Initialization Configuration ​

PropertyDescriptionRequired
mountedElementMount node; supports an HTMLElement instance or a selector/node ID.Required
connectConfigWebRTC connection configuration, obtained from the connection configuration API provided by the backend / SDK.Required
isGroupWhether to enable group control. Defaults to false.Optional
enabledDebugWhether to enable debug mode / log output. Defaults to false.Optional
disabledVerticalSwipeWhether to block vertical swiping. Defaults to false.Optional
disabledWhether to disable keyboard event handling. Defaults to false.Optional
enabledIMEKeyboardWhether to enable IME keyboard mapping. Defaults to false.Optional
enabledDecodeWhether to enable decoding (Canvas rendering). Defaults to false.Optional
cursorTypeCursor style, defaults to default. Available values and their enums:
• default: UniSDK.CURSOR_TYPE.DEFAULT_CURSOR
• circle: UniSDK.CURSOR_TYPE.CIRCLE_CURSOR
• triangle: UniSDK.CURSOR_TYPE.TRIANGLE_CURSOR
Optional
cloudDeviceSizeCloud phone screen size, in the format { width, height }.Optional
videoAngleVideo rotation angle.Optional
remoteViewBackgroundColorRemote view background color. Defaults to transparent.Optional

3. Instance Methods ​

MethodDescription
goHomeGo to the home screen (Android Home key)
goTaskRecents list (Android Recents key)
goBackGo back (Android Back key)
enableAudioEnable audio
disableAudioDisable audio
sendClipboardDataSend clipboard data
openIMEKeyboardOpen keyboard mapping
closeIMEKeyboardClose keyboard mapping
switchToGestureNavigationSwitch to gesture navigation
switchToThreeButtonNavigationSwitch to three-button navigation
changeLevelSet the clarity level; access the supported levels via UniSDK.CLARITY_LEVEL. Currently Smooth, Standard, and Ultra are supported
setVideoAngleSet the video rotation angle
getVideoAngleGet the video rotation angle
setStreamAngleSet the stream angle
setCloudDeviceSizeSet the cloud phone screen size
destroyDestroy the SDK instance

4. Event Listening ​

Listen with player.addListener(event, callback); event enums are accessible via UniSDK.EVENTS:

EventCallback ParameterDescription
CONNECTED-Connection established
LOADED_SUCCESS-Stream loaded successfully
LOADED_FAILUREerror: anyStream loading failed
STOP_CONNECT-Connection closed
STATISTIC_INFOinfo: StatisticInfoReal-time statistics update (includes framesPerSecond, bitrate, lostRate, currentRoundTripTime, averageDecodeTime)
CLARITY_LEVEL_CHANGElevel: numberClarity level change notification
DIRECTION_CHANGEangle: numberCloud phone screen orientation change (0 for portrait, -90 for landscape)
RESIZEscreen: { screenWidth, screenHeight }Cloud phone resolution change notification
GESTURE_MODE_CHANGEmode: numberCloud phone navigation mode change (0 three-button navigation, 2 gesture navigation)
RECEIVE_MEDIA_STREAM_TRACKtrack: MediaStreamTrackMedia stream track received
RECEIVE_ARRAY_BUFFERbuffer: ArrayBufferBinary data received
CLICK_DATAdata: ChannelDataTypeClick data
CHANNEL_EVENT-Channel event
GROUP_CONTROL_EVENT-Group control event
ERRORerror: ErrorStreaming-related error

5. Error Codes ​

CodeDescriptionSeverity
10001WebSocket connection failedHigh
10002WebSocket closedHigh
10003Failed to create offerHigh
10004Failed to process offerHigh
10005Failed to create answerHigh
10006Failed to process answerHigh
10007Failed to set local descriptionHigh
10008Failed to set remote descriptionHigh
10009Failed to handle ICE exchangeHigh
10010ICE state abnormalHigh
10011Camera errorHigh
10012The cloud phone is powered off or does not existHigh
10013Signaling channel errorLow
10014Failed to get WebRTC statisticsLow

6. Complete Example ​

ts
const config = {}; // Obtain the connectConfig from the connection configuration API

const player = new UniSDK({
    mountedElement: "#player-mounted",  // Mount node; can be an HTMLElement or a node ID
    isGroup: false, // Group control mode; defaults to false
    disabled: true, // Disabled
    enabledDebug: process.env.NODE_ENV !== 'production', // Enable logging in development; defaults to false
    disabledVerticalSwipe: false, // Whether to block vertical swiping; defaults to false
    enabledIMEKeyboard: false,     // Whether to enable keyboard mapping; defaults to false
    cursorType: UniSDK.CURSOR_TYPE.CIRCLE_CURSOR, // Cursor type; defaults to default
    connectConfig: {
      ...config
    }
});

player.addListener(UniSDK.EVENTS.CONNECTED, () => {
    console.log('Connected');
});

player.addListener(UniSDK.EVENTS.LOADED_SUCCESS, () => {
    console.log('Streaming started');
});

player.addListener(UniSDK.EVENTS.LOADED_FAILURE, (error: any) => {
    console.log('Streaming failed', error);
});

player.addListener(UniSDK.EVENTS.STATISTIC_INFO, (info: any) => {
    console.log('Statistics', info); // See the statistics fields in the Event Listening section
});

player.addListener(UniSDK.EVENTS.CLARITY_LEVEL_CHANGE, (level: number) => {
    console.log('Clarity level updated', level);
});

player.init();

OpenAPI Docs