Vmos Edge Web SDK
📖 Introduction
Vmos Edge Web SDK is a JavaScript/TypeScript SDK for remotely controlling Android devices in web browsers. It provides video stream rendering, touch event handling, key control, text input, and other features, allowing you to view and control Android devices in real-time on web pages.
⚠️ Note: The current version does not support audio stream transmission, only video stream and touch control are supported.
Key Features
- ✅ Real-time Video Stream: Supports WebGL/Canvas 2D rendering with automatic performance optimization
- ✅ Low-latency Control: Optimized touch event handling with multi-touch support
- ✅ Device Control: Supports keys, text input, and clipboard synchronization
- ✅ Group Control: Supports controlling multiple devices simultaneously
- ✅ Event System: Comprehensive lifecycle and error handling events
- ✅ TypeScript Support: Complete type definitions for excellent development experience
📦 Installation
npm install @vmosedge/web-sdkpnpm add @vmosedge/web-sdkyarn add @vmosedge/web-sdk⚠️ Important Limitations
The SDK currently only supports the following environments:
- Local file protocol
file:// localhostor127.0.0.1
⚠️ HTTP and HTTPS protocols are not supported (except localhost)
The SDK currently only supports running under local file protocol (file://) or localhost environment. It's recommended to open HTML files directly using file:// protocol, or access through localhost on a local web server.
💡 Usage:
- Method 1 (Recommended): Create an HTML file locally and open it directly in a browser (file:// protocol)
- Method 2: Access through a local web server using localhost or 127.0.0.1
- Ensure the device-side WebSocket service supports WS protocol connections
For better user experience and feature integration, we strongly recommend using the following desktop application frameworks in client applications:
- Electron - Build cross-platform desktop apps with web technologies
- Tauri - Build lightweight desktop apps with Rust and web frontend
- Other desktop application frameworks that support WebView
Advantages:
- ✅ Full control over the runtime environment, ensuring SDK works properly
- ✅ Can integrate more native features (file system, system notifications, etc.)
- ✅ Better performance and user experience
- ✅ Can be packaged as standalone desktop applications
- ✅ Avoid browser security policy restrictions
In these frameworks, the SDK can run normally as they provide a secure context environment similar to file:// or localhost.
🚀 Quick Start
Environment Detection (Recommended)
Before using the SDK, it's recommended to detect whether the current environment supports it:
import { VmosEdgeClient } from "@vmosedge/web-sdk";
if (!VmosEdgeClient.isWebCodecsSupported()) {
console.error("Current environment does not support SDK usage");
console.error("Please open the HTML file using file:// protocol, or access through localhost");
return;
}
// Environment supports SDK, can continue using itSimple Usage Example
import { VmosEdgeClient, VmosEdgeClientEvents } from "@vmosedge/web-sdk";
// 0. Environment detection (recommended)
if (!VmosEdgeClient.isWebCodecsSupported()) {
console.error("Current environment does not support SDK usage. Please open the HTML file using file:// protocol, or access through localhost");
return;
}
// 1. Prepare a DOM container (for displaying device screen)
const container = document.getElementById("device-container");
// 2. Create client instance (LAN mode: network_mode === 'macvlan')
const client = new VmosEdgeClient({
container: container!,
config: {
ip: "192.168.1.100", // Use device's ip field
deviceId: "EDGE418ASOC2LX9C", // Use device's dbid field
ports: {
video: 9999, // LAN mode fixed port
touch: 9997, // LAN mode fixed port
},
},
});
// 3. Listen for connection success event
client.on(VmosEdgeClientEvents.STARTED, () => {
console.log("Device connected successfully!");
});
// 4. Start connection
client.start();import { VmosEdgeClient, VmosEdgeClientEvents } from "@vmosedge/web-sdk";
// 0. Environment detection (recommended)
if (!VmosEdgeClient.isWebCodecsSupported()) {
console.error("Current environment does not support SDK usage. Please open the HTML file using file:// protocol, or access through localhost");
return;
}
// 1. Prepare a DOM container (for displaying device screen)
const container = document.getElementById("device-container");
// 2. Create client instance (Non-LAN mode)
const client = new VmosEdgeClient({
container: container!,
config: {
ip: "example.com", // Use device's hostip field
deviceId: "EDGE418ASOC2LX9C", // Use device's dbid field
ports: {
video: 22003, // Use device's tcp_port field
touch: 24003, // Use device's tcp_control_port field
},
},
});
// 3. Listen for connection success event
client.on(VmosEdgeClientEvents.STARTED, () => {
console.log("Device connected successfully!");
});
// 4. Start connection
client.start();Configuration Guide
deviceId: Corresponds to thedbidfield in device informationip:- LAN mode (
network_mode === 'macvlan'): Use device'sipfield - Non-LAN mode: Use device's
hostipfield
- LAN mode (
ports.video:- LAN mode: Fixed to
9999 - Non-LAN mode: Use device's
tcp_portfield
- LAN mode: Fixed to
ports.touch:- LAN mode: Fixed to
9997 - Non-LAN mode: Use device's
tcp_control_portfield
- LAN mode: Fixed to
📚 Import/Export Guide
Complete Import List
The SDK provides the following exports, which you can selectively import as needed:
1. Core Class
import { VmosEdgeClient } from "@vmosedge/web-sdk";
// Use static method for environment detection
VmosEdgeClient.isWebCodecsSupported();2. Configuration Types (TypeScript types for type checking)
import type {
VmosEdgeClientConfig, // Device connection configuration
VmosEdgeClientOptions, // Client initialization options
VmosEdgeSizeChangedEvent, // Size change event data
VmosEdgeErrorEvent, // Error event data
VmosEdgeChannelConnectedEvent, // Channel connection event data
VmosEdgeClientEventMap, // Event map (advanced usage)
VmosEdgeClientEventListener, // Event listener type (advanced usage)
VmosEdgeClientEventName, // Event name type (advanced usage)
ChannelStatus, // Channel status type
AllChannelsStatus, // All channels status type
} from "@vmosedge/web-sdk";Type Details:
VmosEdgeClientConfig- Device connection configurationVmosEdgeClientOptions- Client initialization optionsVmosEdgeSizeChangedEvent- Size change event dataVmosEdgeErrorEvent- Error event dataVmosEdgeChannelConnectedEvent- Channel connection event dataChannelStatus- Channel status typeAllChannelsStatus- All channels status type
3. Enums and Constants (runtime values)
import {
VmosEdgeClientEvents, // Event name enum
VmosEdgeErrorCode, // Error code enum
VmosEdgeErrorType, // Error type enum
} from "@vmosedge/web-sdk";Enum Details:
VmosEdgeClientEvents- Event name enumVmosEdgeErrorCode- Error code enumVmosEdgeErrorType- Error type enum
4. Android Control Related Enums
import {
AndroidKeyCode, // Android key code enum
AndroidKeyEventAction, // Key action enum (press/release)
AndroidMotionEventAction, // Touch action enum
AndroidMotionEventButton, // Touch button enum
AndroidMetaState, // Meta key state enum (Shift/Ctrl/Alt etc.)
} from "@vmosedge/web-sdk";Enum Details:
AndroidKeyCode- Android key code enumAndroidKeyEventAction- Key action enumAndroidMetaState- Meta key state enum
Common Import Combinations
Basic Usage (Recommended)
import {
VmosEdgeClient,
VmosEdgeClientEvents,
type VmosEdgeClientConfig,
type VmosEdgeErrorEvent,
} from "@vmosedge/web-sdk";Full Import (for all features)
import {
VmosEdgeClient,
VmosEdgeClientEvents,
VmosEdgeErrorCode,
VmosEdgeErrorType,
AndroidKeyCode,
AndroidKeyEventAction,
type VmosEdgeClientConfig,
type VmosEdgeClientOptions,
type VmosEdgeErrorEvent,
type VmosEdgeSizeChangedEvent,
} from "@vmosedge/web-sdk";📖 Documentation Navigation
- Examples - Vue, React, and vanilla JavaScript examples
- API Reference - Complete API method documentation
- Type Definitions - All TypeScript type definitions
- Events Guide - Event system usage guide
- Android Key Codes - Android key code reference
- Error Codes - Error codes and error handling
- FAQ - FAQ and troubleshooting
- Changelog - Version update history
