Files
VibeCoding/webrtc_controller_flutter/lib/utils/control_commands.dart

49 lines
1.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:convert';
/// 控制指令构造工具,对应 Android 端 RemoteTouchView 的指令格式。
///
/// 指令通过 DataChannel 以 JSON 字符串发送被控端WebRTCControlled
/// 的 InputCommandHandler 负责解析执行。
class ControlCommands {
ControlCommands._();
/// 单击指令。坐标 x/y 为相对于屏幕的百分比0.0 ~ 1.0)。
static String touch(double x, double y) => jsonEncode({
'action': 'TOUCH',
'x': x,
'y': y,
});
/// 滑动指令。坐标为相对百分比duration 为毫秒。
static String swipe(
double x1,
double y1,
double x2,
double y2,
int durationMs,
) =>
jsonEncode({
'action': 'SWIPE',
'x1': x1,
'y1': y1,
'x2': x2,
'y2': y2,
'duration': durationMs,
});
/// 按键指令。action: 0=按下, 1=抬起(对应 Android KeyEvent.ACTION_DOWN/UP
static String key(int keyCode, int action) => jsonEncode({
'action': 'KEY',
'keyCode': keyCode,
'keyAction': action,
});
/// 长按指令。坐标 x/y 为相对于屏幕的百分比0.0 ~ 1.0)。
/// 对应 Android 端 RemoteTouchView.createLongPressCommand。
static String longPress(double x, double y) => jsonEncode({
'action': 'LONG_PRESS',
'x': x,
'y': y,
});
}