API interface description

This document describes the interfaces provided by the Cloud Mobile Web H5 SDK.

API overview

initialize

const engine = new ArmcloudEngine(params)
params Field descriptions are as follows:
KeywordValue TypeRequiredDescription
deviceInfoobjectYesInformation required to connect to the cloud phone
viewIdstringYesThe ID of the div element where the page is mounted
callbacksobjectNoCollection of callback functions. See the detailed description of callback functions for details.
The deviceInfo field is described as follows:
KeywordValue TypeRequiredDescription
appIdstringYesReturned result from backend service when applying for an instance
roomCodestringYesReturned result from backend service when applying for an instance
roomTokenstringYesReturned result from backend service when applying for an instance
clientIdstringYesRoom number
userIdstringYesUser ID
autoRecoveryTimenumberNoInactivity recovery time, range 1s~7200s, default value: 300
isFullScreennumberNoFull screen mode 0: adaptive scaling (not full screen); 1: fill screen (full screen), default value: 1
mediaTypenumberNoMedia stream type 1: audio only 2: video only 3: both audio and video, default value: 3
rotateTypenumberNoScreen rotation 0: portrait, 1: landscape, default value: 0
keyboardstringNoKeyboard type 'local': local keyboard, 'pad': cloud keyboard, default value: 'pad'

Cloud Device Control Interface

Method NameMethod Description
isSupportedCheck if the browser supports RTC services
startJoin a room
stopLeave a room
setKeyboardStyleSwitch between local/cloud keyboard input types
setStreamConfigSet resolution, bitrate, and frame rate
resumeAllSubscribedStreamResume receiving media streams from the remote
pauseAllSubscribedStreamPause receiving media streams from the remote
saveScreenShotToLocalSave a screenshot locally
saveScreenShotToRemoteSave a screenshot to the cloud device
setPhoneRotationSet screen orientation for playback
setGPSCustomize GPS information
setAutoRecycleTimeSet the no-operation recovery time
getAutoRecycleTimeGet the no-operation recovery time
sendCommandSend key commands
increaseVolumeIncrease cloud device volume
decreaseVolumeDecrease cloud device volume
sendInputClipperSend a string to the cloud device clipboard
sendInputStringSend a string to the cloud device input field
saveCloudClipboardReceive cloud device clipboard content callback
sendShakeSend a "shake" command
setMicrophoneEnable or disable the microphone
setCameraEnable or disable the camera

Cloud Machine Control Interface

Browser Support Check

Method:
engine.isSupported()

Type:

() => Promise<boolean>
// true: Supported, false: Not supported
Code Example:
// Check if the browser supports RTC service listening
const isSupported = await armCloud.value.isSupported();
if (!isSupported) {
  showNotify({
    type: "warning",
    message: "This browser does not support RTC service"
  });
  return false;
}

Join Room

Parameters:
  • isGroupControl: Whether to enable group control
    • Type: boolean
    • Value: false
  • pads: Room numbers to be controlled in a group
    • Type: Array
    • Default Value: []
Method:
engine.start(isGroupControl, pads)

Leave Room

Method:
engine.stop()

Note: The stop() method destroys the engine and the DOM nodes created during the process. If there's a need to switch cloud machines, stop() must be called before each new ArmcloudEngine().

Switch Local/Cloud Machine Keyboard Input Type

Method:
engine.setKeyboardStyle(keyboard: string)
Parameters:
  • keyboard:
    • Type: string
    • Value: local for local input method, pad for cloud machine virtual input method.
Code Example (modify as needed):
engine.setKeyboardStyle('pad');

Set Resolution, Bitrate, and Frame Rate

Method:
engine.setStreamConfig(definitionConfig: CustomDefinition)
Parameters:
  • definitionConfig:
    • Type: object
    • Values:
Field NameDescription
definitionIdResolution
7: 144 * 256;
8: 216 * 384;
9: 288 * 512;
10: 360 * 640;
11: 480 * 848;
12: 540 * 960;
13: 600 * 1024;
14: 480 * 1280;
15: 720 * 1280;
16: 720 * 1920;
17: 1080 * 1920;
18: 1440 * 1920;
19: 1600 * 2560;
20: 2880 * 1080
framerateIdFrame rate
1: 20fps;
2: 25fps;
3: 30fps;
4: 60fps;
5: 1fps;
6: 5fps;
7: 10fps;
8: 15fps;
9: 2fps
bitrateIdBitrate
1: 1Mbps;
2: 1.5Mbps;
3: 2Mbps;
4: 2.5Mbps;
5: 3Mbps;
6: 3.5Mbps;
7: 4Mbps;
8: 5Mbps;
9: 6Mbps;
10: 8Mbps;
11: 10Mbps;
12: 12Mbps;
13: 200kbps;
14: 400kbps;
15: 600kbps
Code Example (modify as needed):
const definitionConfig = ref({
  definitionId: 12,
  framerateId: 2,
  bitrateId: 3
});
engine.setStreamConfig(definitionConfig.value);

Resume Receiving Remote Media Streams

Method:
engine.resumeAllSubscribedStream(mediaType: number)
Parameters:
  • mediaType:
    • Type: number
    • Values:
      • 1: Resume audio stream;
      • 2: Resume video stream;
      • 3: Resume both audio and video streams;
Code Example (modify as needed):
// Resume audio stream
engine.resumeAllSubscribedStream(1);

Pause Receiving Remote Media Streams

Method:
engine.pauseAllSubscribedStream(mediaType: number)
Parameters:
  • mediaType:
    • Type: number
    • Values:
      • 1: Pause audio stream;
      • 2: Pause video stream;
      • 3: Pause both audio and video streams;
Code Example (modify as needed):
// Pause audio stream
engine.pauseAllSubscribedStream(1);

Screenshot Save to Local

Method:
engine.saveScreenShotToLocal()
Return Value:

Type: Promise<ImageData>

Code Example (modify as needed):
engine.saveScreenShotToLocal().then(res => {
  const imageData = res;
  // Create canvas element
  const canvas: HTMLCanvasElement = document.createElement("canvas");
  canvas.width = imageData.width;
  canvas.height = imageData.height;
  const ctx = canvas.getContext("2d");

  // Draw image data on canvas
  ctx.putImageData(imageData, 0, 0);
  // Convert Canvas to image and save to local
  const link = document.createElement("a");
  // Use Canvas's toDataURL() method to convert Canvas to base64 encoded image URL
  link.href = canvas.toDataURL();
  // Set the filename for the download
  link.download = "image.png";
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
});

Screenshot Save to Cloud Machine

Method:
engine.saveScreenShotToRemote()
Code Example:
engine.saveScreenShotToRemote();

Set Portrait/Landscape Mode Playback

Method:
engine.setPhoneRotation(type: number)
Parameters:
  • type:
    • Type: number
    • Values:
      • 0: Portrait mode;
      • 1: Landscape mode;
Code Example (modify as needed):
// Set to landscape mode
engine.setPhoneRotation(1);

Custom GPS Information

Method:

engine.setGPS(longitude: number, latitude: number)

Parameters

  • longitude: Longitude

    • Type: number
  • latitude: Latitude

    • Type: number

Code Example (modify as necessary):

// Set longitude and latitude coordinates
engine.setGPS(113, 28);

Set Inactivity Recycle Time

Method:

engine.setAutoRecycleTime(second: number)

Parameters

  • second:
    • Type: number
    • Default: 300s, Range: 1s~7200s

Code Example (modify as necessary):

engine.setAutoRecycleTime(300);

Get Inactivity Recycle Time

Method:

engine.getAutoRecycleTime()

Return Value:

  • Type: Promise<number>

Code Example:

const time = await engine.getAutoRecycleTime();
console.log(time);

Send Key Command

Method:

engine.sendCommand(command: string)

Parameters

  • command:
    • Type: string
    • Values:
      • back: back command
      • home: home command
      • menu: menu command

Code Example (modify as necessary):

// Send home key command
engine.sendCommand("home");

Increase Cloud Machine Volume

Method:

engine.increaseVolume()

Code Example:

engine.increaseVolume();

Decrease Cloud Machine Volume

Method:

engine.decreaseVolume()

Code Example:

engine.decreaseVolume();

Send String to Cloud Phone's Clipboard

Method:

engine.sendInputClipper(text: string)

Code Example:

// This operation will only paste the copied content into the cloud machine's clipboard. 
// To use it, you need to long-press to paste in the cloud machine's input field.
const text = 'hello world';
engine.sendInputClipper(text);

Send String to Cloud Phone's Input Field

Method:

engine.sendInputString(text: string)

Code Example:

// This operation will automatically send the copied content to the input field when it is focused, 
// without needing to long-press to paste.
const text = 'hello world';
engine.sendInputString(text);

// Note: This operation will only send the text content to the input field 
// and will not paste the content into the cloud machine's clipboard. 
// If needed, call engine.sendInputClipper(text) manually.

Enable/Disable Cloud Machine Clipboard Content Callback

Method:

engine.saveCloudClipboard(flag: boolean)

Parameters

  • flag:
    • Type: boolean
    • Values:
      • true: receive cloud machine clipboard content callback
      • false: do not receive cloud machine clipboard content callback

Code Example:

// This operation will automatically send the copied content to the input field when it is focused, 
// without needing to long-press to paste.
const flag = true;
engine.saveCloudClipboard(flag);

Send Shake Command

Method:

engine.sendShake(time: number)

Parameters

  • time:
    • Type: number
    • Value: milliseconds
    • Default: 1500

Code Example:

// A long duration may cause multiple screenshots
engine.sendShake(1500);

Enable/Disable Microphone

Method:

engine.setMicrophone(enable: boolean)

Parameters

  • enable:
    • Type: boolean
    • Default: true

Code Example:

engine.setMicrophone(true);

Enable/Disable Camera

Method:

engine.setCamera(enable: boolean)

Parameters

  • enable:
    • Type: boolean
    • Default: true

Code Example:

engine.setCamera(true);