video-controller-next
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

VideoController

A nodejs package for controlling phone depend on scrcpy protocol.

Develop

npm install
npm run build
npm run dev

启动浏览器访问 localhost:9090

Getting Started

new VideoController({
  sendCtrl: this._sendCtrl.bind(this),
  videoElement: this.videoElement,
  textHelperElement: this.textHelperElement
});

协议内容

Key

{ "type": 0, "action": 0, "keyCode": $KEYCODE, "metaState": 0, "repeat": 0 }
{ "type": 0, "action": 1, "keyCode": $KEYCODE, "metaState": 0, "repeat": 0 }
export enum AndroidKeycode {
  Home = 3,
  Back = 4,
  Power = 26,
  Menu = 82,
  RencentApps = 187,
  Camera = 27,
  VoluneMute = 164,
  VoluneUp = 24,
  VolumeDown = 25,
}

Touch

{ "type": 2, "action": 0, "position": { "x": 0.812, "y": 0.284, "width": $realWidth, "height": $realHeight }, "buttons": 0, "pressure": 1 }
{ "type": 2, "action": 2, "position": { "x": 0.779, "y": 0.286, "width": $realWidth, "height": $realHeight }, "buttons": 0, "pressure": 1 }
{ "type": 2, "action": 2, "position": { "x": 0.762, "y": 0.286, "width": $realWidth, "height": $realHeight }, "buttons": 0, "pressure": 1 }
{ "type": 2, "action": 2, "position": { "x": 0.719, "y": 0.286, "width": $realWidth, "height": $realHeight }, "buttons": 0, "pressure": 1 }
{ "type": 2, "action": 1, "position": { "x": 0.719, "y": 0.286, "width": $realWidth, "height": $realHeight }, "buttons": 0, "pressure": 1 }

Scroll

{ "type": 3, "position": { "x": 0.433, "y": 0.191, "width": $realWidth, "height": $realHeight }, "hScroll": 0, "vScroll": 0.04 }
{ "type": 3, "position": { "x": 0.433, "y": 0.191, "width": $realWidth, "height": $realHeight }, "hScroll": 0, "vScroll": 0.04 }

TEXT

{ "type": 1, "text": "http://localhost:9090/", "paste": true }

Set_Clipboard

{ "type": 9, "text": "http://localhost:9090/", "paste": true }

Options

videoMode webrtc|image optional

使用的投流模式, 默认为 webrtc

videoElement HTMLVideoElement required

用来展示画面的video元素

textHelperElement HTMLInputElement required

用来辅助粘贴的text input元素

imageElement HTMLImageElement optional

使用图片流时用来展示画面的img元素

multiFingerCount number optional

发送触控事件使用的手指数量, 默认为1

multiFingerRotate number optional

发送触控事件使用的倾斜角度, 默认为0 (范围: 0 Deg - 180 Deg)

multiFingerOffset number optional

发送触控事件每个手指的间隔百分比, 默认为0.1 (范围: 0-1)

isPC boolean optional

指定投流终端是否为PC终端(Mouse Move事件的触发条件不同)

sendCtrl (msg: any) => void required

用于发送控制指令的函数(比如经过包装的websocket信息发送函数)

Methods

keyPress (code: AndroidKeycode) => void

模拟点击对端手机的某个功能按键键

rotate () => void

模拟发送转屏信号

backOrScreenOn () => void

模拟发送回到主页信号

resetFingerCount (number) => void

重置触控事件使用的手指数量

resetFingerRotate (number) => void

重置触控事件使用的倾斜角度

resetFingerOffset (number) => void

重置触控事件每个手指的间隔百分比

Readme

Keywords

Package Sidebar

Install

npm i video-controller-next

Weekly Downloads

12

Version

1.0.8

License

ISC

Unpacked Size

89.3 kB

Total Files

20

Last publish

Collaborators

  • yanfengqiu