dsh-mobile-mirror 0.0.0-stage → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +249 -0
- package/CONTRIBUTING.md +74 -0
- package/LICENSE +21 -0
- package/README.md +124 -2
- package/THIRD-PARTY-NOTICES.md +50 -0
- package/assets/icon-180.png +0 -0
- package/client.js +1395 -0
- package/cordis.patch.yml +12 -0
- package/docs/DETAIL.md +170 -0
- package/docs/media/frame.png +0 -0
- package/icon.svg +7 -0
- package/index.js +673 -0
- package/lib/adb.js +314 -0
- package/lib/control.js +113 -0
- package/lib/mirror.html +824 -0
- package/lib/server.js +444 -0
- package/lib/video.js +635 -0
- package/lib/window.js +160 -0
- package/lib/window.jxa +158 -0
- package/licenses/Apache-2.0.txt +204 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +65 -4
- package/scripts/selftest.mjs +104 -0
- package/vendor/scrcpy-server-1.25.jar +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
|
|
4
|
+
versioning is [SemVer](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [0.5.1] — 2026-12-01
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- 把 `scripts/` 纳入发布文件,`npm run selftest` 在安装后的包内也能运行;
|
|
10
|
+
0.5.0 的 tarball 里只有 `package.json` 的 scripts 字段,没有脚本本体。
|
|
11
|
+
|
|
12
|
+
## [0.5.0] — 2026-12-01
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- 项目改名为 **dsh-mobile-mirror**(原 `dsh-phone-mirror` 与 npm 上已有的 Windows 同名插件冲突,
|
|
16
|
+
无法发布)。包名、bundle 名、GitHub 仓库、文档与安装示例同步更新;旧仓库地址由 GitHub 重定向。
|
|
17
|
+
- README 状态更新到 0.5.0,并说明原生窗口当前仅 macOS,`/mirror` 页面本身跨平台。
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- `files` 漏掉 `vendor`,导致 npm / release tarball 里没有
|
|
21
|
+
`vendor/scrcpy-server-1.25.jar`,装上后无法拉流。现在打包会带上 jar。
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- 新增 `assets/icon-180.png`,供插件市场卡片使用(SVG 仍是 DSH 内的图标)。
|
|
25
|
+
- `npm run selftest`:离线校验 bundle 清单、vendor jar 大小与 MD5、JS 语法、
|
|
26
|
+
locale 详情路径、图标尺寸和版本一致性。
|
|
27
|
+
|
|
28
|
+
## [0.4.4] — 2026-12-01
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
- 输入权限探测:宿主用 `input keyevent 0`(无副作用的 KEYCODE_UNKNOWN)探测设备是否允许
|
|
32
|
+
shell 注入。MIUI/HyperOS 等 ROM 默认关闭「USB 调试(安全设置)」时,`input tap` 会抛
|
|
33
|
+
`SecurityException: ... requires INJECT_EVENTS`,scrcpy control 也会被系统丢掉,表现就是
|
|
34
|
+
“画面能看,但点击/滑动没反应”。
|
|
35
|
+
- 新增 `GET /input/status`:返回 `{available, blocked, message}`。`/tap`、`/swipe`、`/key`
|
|
36
|
+
带 `space:"video"` 且探测到拒绝时返回 HTTP 412 `INPUT_FORBIDDEN`,页面顶部显示
|
|
37
|
+
“请到开发者选项打开 USB 调试(安全设置)”,不再是静默成功。
|
|
38
|
+
- 被拒绝的结果只缓存 2 秒,用户改完设置后下一次点击会重新探测并立即恢复;允许的结果缓存
|
|
39
|
+
5 分钟,不拖慢正常输入。
|
|
40
|
+
|
|
41
|
+
## [0.4.3] — 2026-12-01
|
|
42
|
+
|
|
43
|
+
### Fixed
|
|
44
|
+
- 画面里的点击坐标错了:`/mirror` 的 canvas 是视频尺寸(328×720),页面却把视频像素
|
|
45
|
+
直接发给 `/tap`,`adb input tap` 按设备像素(1080×2400)解释,于是点击落在左上角附近,
|
|
46
|
+
经常“点了没反应”。现在页面发归一化坐标,宿主按视频尺寸走 scrcpy,回退 adb 时再按
|
|
47
|
+
`wm size` 换算成设备像素。
|
|
48
|
+
- 画面只绑了 `click`,没有拖拽手势,滑动手机没有任何反应。现在改成 Pointer Events:
|
|
49
|
+
按下/移动/抬起,短按算点击,拖动算滑动(时长按实际手势夹到 120–900ms)。
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
- 原生窗口和 `/mirror` 的输入改走 scrcpy control 通道:`control=true` 后在同一
|
|
53
|
+
`localabstract:scrcpy` 上开第二条 socket,直接发触摸/按键消息,不再为每次点击启动
|
|
54
|
+
一个 `adb shell input` 进程。点击请求从 ~600ms 降到 ~10ms,滑动可以在手指抬起前
|
|
55
|
+
就开始注入。scrcpy 不可用时自动回退到 adb `input`,坐标仍按设备尺寸换算。
|
|
56
|
+
|
|
57
|
+
## [0.4.2] — 2026-12-01
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
- `/stream` 退订时机错误:GET 请求的 `request` 在读完请求头时就触发 `close`,订阅被立刻
|
|
61
|
+
取消,3 秒后视频源被停掉;HTTP 响应还挂着,客户端 reader 永远等不到新数据,画面就停在
|
|
62
|
+
最后一帧。现在只监听 `response` 的 `close`,连接真断时才退订。
|
|
63
|
+
- 原生窗口失焦后 WKWebView 会暂停读取 `/stream` 的 body,页面仍能收到点击。现在任意
|
|
64
|
+
`pointerdown` / `keydown` 都会检查最后一次读取时间,超过 1.5s 就换一条新流,点击和
|
|
65
|
+
画面恢复在同一次交互里完成。
|
|
66
|
+
- `screenrecord` 兜底进程退出后没有回收 `source.session`,订阅者会一直挂在死流上;现在
|
|
67
|
+
child `exit` 会触发重拉。
|
|
68
|
+
|
|
69
|
+
### Added
|
|
70
|
+
- 视频源每秒发一个空心跳(记录类型 `0x68`),客户端据此区分“手机画面静止”和“连接已死”;
|
|
71
|
+
只在窗口可见且聚焦时按 4 秒无心跳重连,避免静止画面被误判。
|
|
72
|
+
|
|
73
|
+
## [0.4.1] — 2026-12-01
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
- **独立窗口内的「置顶」和「贴右」。** 窗口页新增两个只在原生窗口里出现的按钮:
|
|
77
|
+
「置顶」在普通层级(0)和浮动层级(3)之间切换,默认关;「贴右」把窗口移到屏幕
|
|
78
|
+
可见区域右侧并夹紧纵向位置。对应宿主接口 `POST /window/pin {serial, pinned}` 和
|
|
79
|
+
`POST /window/snap-right {serial}`,窗口进程每秒轮询状态文件生效。
|
|
80
|
+
- 窗口被 DSH 挡住时,WebKit 会把 `body` 读取限流到约 1 帧/1.4s;页面现在在窗口重新
|
|
81
|
+
可见或重新获得焦点、且超过 1.5s 没新字节时自动换一条流。不按「多久没新字节」做定时
|
|
82
|
+
看门狗:手机画面静止时本来就没有新帧,定时断开会把正常静止误判成卡死。
|
|
83
|
+
|
|
84
|
+
### Fixed
|
|
85
|
+
- 解码队列超过 8 帧时最多等 2 秒,不再可能无限等待;解码器状态异常会断开重连,
|
|
86
|
+
而不是让整条管道静默卡住。
|
|
87
|
+
- 明确记录:画面看起来"不动"多半是窗口被 DSH 盖住(普通层级 + 重叠 191pt 时只露出
|
|
88
|
+
右侧 111pt),不是解码停住;置顶或并排后即可完整看到。
|
|
89
|
+
|
|
90
|
+
## [0.4.0] — 2026-12-01
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
- **原生独立窗口。** `⤢` 和「独立窗口」按钮不再打开浏览器,而是由宿主 spawn 一个
|
|
94
|
+
AppKit 窗口(`lib/window.jxa`,`osascript -l JavaScript` 执行):标准标题栏可拖动、
|
|
95
|
+
可缩放,能放到 DSH 窗口之外或第二块屏;记住上次位置,DSH 退出时窗口一起关闭。
|
|
96
|
+
窗口内仍是 `/mirror` 页面(`?embed=1` 会隐藏重复标题和无效的全屏按钮),
|
|
97
|
+
因此设备切换、点击点按、输入归属、H.264/PNG 兜底全部复用。
|
|
98
|
+
- 新增 `POST /window/open {serial}`:宿主侧窗口管理器(`lib/window.js`)负责进程生命周期、
|
|
99
|
+
同设备复用窗口、心跳与孤儿进程回收。
|
|
100
|
+
|
|
101
|
+
### Changed
|
|
102
|
+
- 独立窗口是**普通层级**,不置顶;点 DSH 会把它盖住(0.4.1 起窗口内可手动「置顶」)。
|
|
103
|
+
- 仅 macOS:依赖系统自带的 `osascript`,不需要编译,也不需要另装 App。
|
|
104
|
+
- `/mirror` 页面保留,作为窗口内容和直接打开调试的入口。
|
|
105
|
+
|
|
106
|
+
## [0.3.5] — 2026-12-01
|
|
107
|
+
|
|
108
|
+
### Added
|
|
109
|
+
- **独立窗口 `/mirror`。** 桥接服务新增一个自包含页面(`lib/mirror.html`),不依赖 DSH 的
|
|
110
|
+
React 壳,直接在系统浏览器里打开:可任意拉伸、全屏、拖到第二块屏,画面不再受 DSH 窗口
|
|
111
|
+
边界限制。支持 H.264 / WebCodecs,缺解码器时退回 PNG 兜底;带设备切换、返回/主页/任务、
|
|
112
|
+
点击点按、输入归属提示和「接管」。
|
|
113
|
+
- 浮窗标题栏新增「⤢ 在独立窗口打开」,设备管理页每台在线设备也多了「独立窗口」按钮。
|
|
114
|
+
两者都走 `window.open`,DSH 桌面会把 http 链接交给系统浏览器(主窗口拒绝内嵌新窗口)。
|
|
115
|
+
|
|
116
|
+
### Changed
|
|
117
|
+
- 独立窗口是浏览器标签/窗口,**不会总在最前**;真正置顶浮窗需要 Electron 主进程能力,
|
|
118
|
+
插件侧做不到。
|
|
119
|
+
|
|
120
|
+
## [0.3.4] — 2026-12-01
|
|
121
|
+
|
|
122
|
+
### Fixed
|
|
123
|
+
- **浮窗拖到右侧会被窗口裁掉。** 旧拖拽夹紧按 `innerWidth - 120` / `innerHeight - 80` 算,
|
|
124
|
+
允许把大半个浮窗拖出应用窗口,超出部分自然看不见。现在按浮窗自身的四条边夹紧:无论怎么
|
|
125
|
+
拖,整窗都留在视口内;窗口尺寸变化或重新打开时也会自动拉回可视区。
|
|
126
|
+
- **小窗口里画面放不下。** 画面高度改为随视口收缩(`max-height: calc(100vh - 190px)`,
|
|
127
|
+
`object-fit: contain`),窗口再矮也能看到完整手机,代价是画面按比例缩小。
|
|
128
|
+
- 缩放后用 `object-fit: contain` 会留黑边,点击坐标改按实际画面区域反算,避免点偏。
|
|
129
|
+
- 标题栏双击可回到右下角默认位置。
|
|
130
|
+
|
|
131
|
+
## [0.3.3] — 2026-12-01
|
|
132
|
+
|
|
133
|
+
### Fixed
|
|
134
|
+
- **点击「打开镜像」后浮窗不出现。** `PhoneMirrorPanel` 先以 `open=false` 挂载,早退
|
|
135
|
+
`if (!open) return null` 之后还留着 `toggleLock` 这个 `useCallback`;点开镜像时多跑一个
|
|
136
|
+
hook,React 直接抛 `Rendered more hooks than during the previous render`,整个浮窗渲染
|
|
137
|
+
失败,于是看不到画面。所有 hook 已移到早退之前。
|
|
138
|
+
- **文档纠正。** `shell.overlay` 在当前 app frame 里排在主区域之后且 `z-index:20`,本身就在
|
|
139
|
+
面板页之上;0.3.1 里"浮层在 DOM 里排在主区域之前、会被盖住"的说法已过时。打开镜像仍会
|
|
140
|
+
`selectPanel(null)`,但理由改成"回到会话、边看边聊"。
|
|
141
|
+
|
|
142
|
+
## [0.3.2] — 2026-12-01
|
|
143
|
+
|
|
144
|
+
### Fixed
|
|
145
|
+
- **Sidebar row could vanish on a bad startup.** The client half now beacons to the Host
|
|
146
|
+
bridge the moment `apply` starts (`report.stage` = `start` → `locale` → `mounted`), so a
|
|
147
|
+
missing entry can be told apart from "never loaded" without opening devtools. The
|
|
148
|
+
`layout` service is read through `ctx.get('layout')` instead of `ctx.layout`, the sidebar
|
|
149
|
+
label is resolved to a plain string up front, and the sidebar row is registered before the
|
|
150
|
+
main view.
|
|
151
|
+
- **`/client-graph` (host side).** New diagnostic endpoint that reports whether this package
|
|
152
|
+
is in the client-module graph, the chunk URL the renderer should request, and the status
|
|
153
|
+
that URL answers with — enough to separate "not composed" from "composed but not served".
|
|
154
|
+
|
|
155
|
+
## [0.3.1] — 2026-12-01
|
|
156
|
+
|
|
157
|
+
### Fixed
|
|
158
|
+
- **`打开镜像` now returns to the conversation.** The floating window lives in
|
|
159
|
+
`shell.overlay`, which the app frame renders *before* the main region in DOM order, so a
|
|
160
|
+
full-bleed panel page painted over it. Opening the mirror now closes the panel
|
|
161
|
+
(`layout.selectPanel(null)`) and the picture shows up over the chat, which is the whole
|
|
162
|
+
point of streaming it.
|
|
163
|
+
- **Theme-aware surfaces.** The manager page and the floating window used made-up token
|
|
164
|
+
names (`--dsw-alias-border`, `--dsw-alias-fg-muted`, `--dsw-alias-warning`) with dark
|
|
165
|
+
literal fallbacks, so on a light theme the card rendered as a black block and the
|
|
166
|
+
window chrome looked out of place. Everything now uses the real aliases
|
|
167
|
+
(`label-primary/secondary/tertiary`, `border-l2/l3`, `bg-layer-1/2`, `brand-primary`,
|
|
168
|
+
`state-warn-label`) with neutral fallbacks.
|
|
169
|
+
|
|
170
|
+
## [0.3.0] — 2026-12-01
|
|
171
|
+
|
|
172
|
+
### Added
|
|
173
|
+
- **Sidebar panel = device manager.** `手机镜像` now sits in the left sidebar (after
|
|
174
|
+
`记忆系统`, before `更多`) and opens a management page: one row per phone with model,
|
|
175
|
+
serial, connection state, input-ownership chip, and `打开镜像` / `关闭镜像` /
|
|
176
|
+
`接管` / `禁止 agent` actions. Registered through `main` + `sidebar.panellist`, the
|
|
177
|
+
same pattern the built-in schedule panel uses (`order: 40`).
|
|
178
|
+
|
|
179
|
+
### Changed
|
|
180
|
+
- **The picture stays floating.** Embedding the live surface in the main area made the
|
|
181
|
+
conversation unusable while watching the phone, so the H.264 view remains the
|
|
182
|
+
`shell.overlay` window; the page only opens/closes it. Both share `mirrorStore`, so
|
|
183
|
+
switching device in either place switches both.
|
|
184
|
+
|
|
185
|
+
### Removed
|
|
186
|
+
- The self-positioned 📱 overlay entry (`MirrorEntryHost` / `PhoneMirrorEntry`) — the
|
|
187
|
+
sidebar navigation list was the target all along.
|
|
188
|
+
|
|
189
|
+
## [0.2.3] — 2026-12-01
|
|
190
|
+
|
|
191
|
+
### Fixed
|
|
192
|
+
- **The top-left entry did not show up.** It was registered into
|
|
193
|
+
`conversation.header.leading`, which this build renders only in some views; the entry
|
|
194
|
+
vanished with it. The button now renders from `shell.overlay` and positions itself over
|
|
195
|
+
the header's leading seat (`[data-conversation-header-leading]`), falling back to the
|
|
196
|
+
window's top-left corner when that seat is absent.
|
|
197
|
+
|
|
198
|
+
### Added
|
|
199
|
+
- `POST /client-log` / `GET /client-log` on the bridge: the client half reports its
|
|
200
|
+
version and slot-registration outcome once on load, so "is the plugin loaded at all?"
|
|
201
|
+
can be answered with `curl 127.0.0.1:7799/client-log` instead of opening devtools.
|
|
202
|
+
|
|
203
|
+
## [0.2.2] — 2026-12-01
|
|
204
|
+
|
|
205
|
+
### Added
|
|
206
|
+
- **Top-left entry point.** A 📱 button in `conversation.header.leading` (before the
|
|
207
|
+
session title) opens a device manager: per-device connection state and input-ownership
|
|
208
|
+
chip, one-click open/close of the mirror, refresh, and a hint when no device is
|
|
209
|
+
attached. This is also where multiple devices will be managed.
|
|
210
|
+
- **Real close button.** The panel header now has `×` (close, hides the panel) next to
|
|
211
|
+
`–` (collapse to just the title bar), so the mirror can be dismissed without leaving
|
|
212
|
+
the app.
|
|
213
|
+
|
|
214
|
+
### Fixed
|
|
215
|
+
- **Header buttons were dead.** `onHeaderPointerDown` captured the pointer for dragging
|
|
216
|
+
even when the pointerdown landed on a button, select or input, so `–`/`×`/the device
|
|
217
|
+
picker swallowed their clicks. Dragging now bails out for interactive targets.
|
|
218
|
+
|
|
219
|
+
## [0.2.1] — 2026-12-01
|
|
220
|
+
|
|
221
|
+
### Fixed
|
|
222
|
+
- **New subscribers got no key frame.** scrcpy only sends SPS/PPS + an IDR once when the
|
|
223
|
+
stream opens, so anyone joining a running session received deltas only and the canvas
|
|
224
|
+
stayed black for up to ~12s. The hub now tracks `lastKeyAt`: if the newest key frame is
|
|
225
|
+
older than `KEY_FRESH_MS` (1500ms) the session is restarted to get a clean IDR, otherwise
|
|
226
|
+
the cached key frame is replayed immediately.
|
|
227
|
+
|
|
228
|
+
### Added
|
|
229
|
+
- `phone_lock` tool plus the panel switch that blocks the agent from borrowing control
|
|
230
|
+
(`CONTROL_LOCKED`); locking forces an agent lease back to the human.
|
|
231
|
+
|
|
232
|
+
## [0.2.0] — 2026-12-01
|
|
233
|
+
|
|
234
|
+
### Added
|
|
235
|
+
- H.264 video channel: scrcpy server 1.25 over `adb forward`, custom framing on `/stream`
|
|
236
|
+
(`k`/`d` + length + pts + Annex-B), decoded with WebCodecs in the panel canvas.
|
|
237
|
+
- Assertion tools: `phone_find`, `phone_tap_text`, `phone_wait_for`,
|
|
238
|
+
`phone_assert_visible`, `phone_wait_stable`.
|
|
239
|
+
- Input ownership lease: `phone_arm` / `phone_disarm` / `phone_control`, TTL release,
|
|
240
|
+
panel takeover, HTTP 409 for human input while the agent holds the lease.
|
|
241
|
+
|
|
242
|
+
### Changed
|
|
243
|
+
- `/frame.png` PNG polling is now only a fallback for browsers without WebCodecs.
|
|
244
|
+
|
|
245
|
+
## [0.1.0] — 2026-11-30
|
|
246
|
+
|
|
247
|
+
### Added
|
|
248
|
+
- First skeleton: local bridge on `127.0.0.1:7799`, 8 tools, PNG screen mirroring in a
|
|
249
|
+
`shell.overlay` picture-in-picture window.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for taking a look. This is a small plugin; keep changes small and verifiable.
|
|
4
|
+
|
|
5
|
+
## Before you open a PR
|
|
6
|
+
|
|
7
|
+
1. `node --check index.js client.js lib/*.js` must pass — the project has no build step and
|
|
8
|
+
no runtime dependencies, and it should stay that way (only `node:` built-ins).
|
|
9
|
+
2. Test against a real device. Statements like "should work" are not enough for the parts
|
|
10
|
+
that talk to `adb`; paste the command output that proves the behaviour.
|
|
11
|
+
3. If you touch the wire format (`DSPM1` framing, scrcpy packet parsing, `/control`
|
|
12
|
+
payloads), update `docs/DETAIL.md` in the same PR — it is the reference for those bytes.
|
|
13
|
+
|
|
14
|
+
## Manual test recipe
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# host half, on its own port, with debug logging
|
|
18
|
+
node -e "import('./index.js').then(({ apply }) => apply(
|
|
19
|
+
{ effect: (fn) => fn(), tools: { register: () => () => {} }, logger: console },
|
|
20
|
+
{ port: 7808, defaultSerial: process.env.SERIAL }))"
|
|
21
|
+
|
|
22
|
+
curl -s localhost:7808/health
|
|
23
|
+
curl -s "localhost:7808/frame.png?serial=$SERIAL" -o /tmp/f.png && file /tmp/f.png
|
|
24
|
+
curl -s "localhost:7808/uitree?serial=$SERIAL" | head -c 300
|
|
25
|
+
curl -s -X POST localhost:7808/control -H 'content-type: application/json' \
|
|
26
|
+
-d "{\"serial\":\"$SERIAL\",\"action\":\"arm\",\"ttlMs\":30000}"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Upgrading the bundled scrcpy server
|
|
30
|
+
|
|
31
|
+
`vendor/scrcpy-server-x.y.jar` is a **pinned** dependency: the wire format we parse is
|
|
32
|
+
version-specific, and a bump that is not verified end-to-end silently turns the video
|
|
33
|
+
panel black. Treat it like a protocol change, not like a file copy.
|
|
34
|
+
|
|
35
|
+
Known data point: **1.25 works; 2.4 does not** — 2.4 sends the 1-byte dummy then stalls
|
|
36
|
+
before the device-name header, and its option names differ (`raw_video_stream` is unknown
|
|
37
|
+
to 1.25). Do not "just bump it".
|
|
38
|
+
|
|
39
|
+
Checklist:
|
|
40
|
+
|
|
41
|
+
- [ ] Download the release asset from upstream, not a mirror you cannot verify:
|
|
42
|
+
`https://github.com/Genymobile/scrcpy/releases/download/vx.y/scrcpy-server-vx.y`
|
|
43
|
+
- [ ] Record size and `md5` of the downloaded file, name it
|
|
44
|
+
`vendor/scrcpy-server-x.y.jar`, and delete the old jar (do not keep two).
|
|
45
|
+
- [ ] Update every place that names the version: `SCRCPY_VERSION = 'x.y'` in
|
|
46
|
+
`lib/video.js` (it is passed as the first argument to `com.genymobile.scrcpy.Server`,
|
|
47
|
+
a mismatch aborts `app_process`), and the `scrcpyJar` filename in `index.js`.
|
|
48
|
+
- [ ] Re-verify the stream header by hand, with `DSPM_DEBUG=1`:
|
|
49
|
+
the first bytes must still be `1 dummy + 64 device name + 2×u16 width/height`, then
|
|
50
|
+
12-byte packet headers (`u64 pts/flags` with bit63 = config, bit62 = key, then `u32`
|
|
51
|
+
length) — see `parse()` in `lib/video.js`. If any of that moved, update the parser and
|
|
52
|
+
`docs/DETAIL.md` in the same PR.
|
|
53
|
+
- [ ] Decode on a real device: canvas must paint, and after a subscribe-while-running the
|
|
54
|
+
first key frame must still arrive within `KEY_FRESH_MS` semantics (restart path).
|
|
55
|
+
- [ ] Update the provenance table in `THIRD-PARTY-NOTICES.md` — version, source URL, size,
|
|
56
|
+
**md5**, and the upstream copyright years if they changed.
|
|
57
|
+
- [ ] Grep for the old version string: `grep -rn "<old version>" --include='*.js' --include='*.md' .`
|
|
58
|
+
- [ ] Add a `CHANGELOG.md` entry saying what changed and why.
|
|
59
|
+
|
|
60
|
+
If the new jar adds or changes a licence obligation, update `licenses/` as well.
|
|
61
|
+
|
|
62
|
+
## What is welcome
|
|
63
|
+
|
|
64
|
+
- Bug reports with `DSPM_DEBUG=1` logs and the device's Android version.
|
|
65
|
+
- Performance work on the video path (latency, bandwidth, H.264 fallbacks).
|
|
66
|
+
- New *assertion-style* tools. Prefer `wait_*` / `assert_*` shapes over "sleep then look".
|
|
67
|
+
- Panel UX fixes (the current picture-in-picture is deliberately minimal).
|
|
68
|
+
|
|
69
|
+
## What needs discussion first
|
|
70
|
+
|
|
71
|
+
- Replacing the localhost HTTP bridge with a `ctx.connection` route (see the migration note
|
|
72
|
+
in `docs/DETAIL.md`) — it changes the transport for every panel.
|
|
73
|
+
- Bundling another binary: keep the licence story clean, see `THIRD-PARTY-NOTICES.md`.
|
|
74
|
+
- Anything that would let the agent bypass the ownership lease.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 susirsusir (https://github.com/susirsusir)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-mobile-mirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [DeepSeek Harness](https://github.com/deepseek-ai) plugin that puts an **Android phone inside the agent loop** — and on your screen.
|
|
4
|
+
|
|
5
|
+
- **Human**: an in-DSH floating panel, or a native macOS window you can drag anywhere on the desktop. Click or drag the picture to drive the phone.
|
|
6
|
+
- **Agent**: 17 tools to read the UI tree, tap by visible text, wait for conditions, type and swipe — guarded by an ownership lease so the agent never fights you for the phone.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
> Status: `0.5.1`, Android only, verified on Android 11 (SDK 30). Host side needs `adb` (Android platform-tools). Nothing here needs root. The current native window is macOS-only; the `/mirror` page itself is platform-neutral, with Windows support on the roadmap.
|
|
11
|
+
|
|
12
|
+
## 它解决什么
|
|
13
|
+
|
|
14
|
+
手机上跑着一个 App,agent 要"用"它——点按钮、填表单、看结果;同时人也想看见 agent 到底在手机上点了什么。两个需求指向同一条通路,只是消费者不同:
|
|
15
|
+
|
|
16
|
+
- **人**:连续画面(H.264 硬编码 + WebCodecs 解码,滑动时 18–30fps,静止时自动降到 3–9fps 省电)。
|
|
17
|
+
- **agent**:某一刻的**确定性快照**——控件树 + 必要时一张图。视频塞给模型既慢又贵,控件树通常只有几十行。
|
|
18
|
+
|
|
19
|
+
`screencap` PNG 只在没有 WebCodecs 的浏览器里兜底。
|
|
20
|
+
|
|
21
|
+
## 前置要求
|
|
22
|
+
|
|
23
|
+
- DSH desktop profile(本插件不 import `@deepseek-ai/*`,用原生 JSON Schema 注册工具)。
|
|
24
|
+
- `adb` 在 `PATH` 或 `ANDROID_HOME/platform-tools/adb`;`adb devices` 能看到设备(USB 调试或无线调试都行)。
|
|
25
|
+
- Android 设备开启「USB 调试」;scrcpy server 以 `shell` 身份运行,**不需要 root**。
|
|
26
|
+
- 小米/红米(MIUI、HyperOS)等部分 ROM 还需要在开发者选项里打开
|
|
27
|
+
**「USB 调试(安全设置)」**,否则 `adb shell input` 和 scrcpy control 都会被系统拒绝
|
|
28
|
+
(`INJECT_EVENTS`),表现是画面能看但点击、滑动没反应。
|
|
29
|
+
|
|
30
|
+
## 安装
|
|
31
|
+
|
|
32
|
+
1. 确认 `adb` 可用:`adb devices` 能看到设备(USB 调试或 `adb connect` 无线均可)。
|
|
33
|
+
2. 安装:先 `git clone https://github.com/susirsusir/dsh-mobile-mirror.git`,然后在 DSH 里 `plugin_manager install_bundle` 指向该目录;或在 Plugins 里选 Add plugin 选这个目录。
|
|
34
|
+
3. 插件配置(可选):
|
|
35
|
+
|
|
36
|
+
| 键 | 默认 | 说明 |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `adbPath` | `''` | 留空则依次找 `ANDROID_HOME`、`~/Library/Android/sdk/platform-tools/adb`、`PATH` |
|
|
39
|
+
| `port` | `7799` | 面板取帧用的本地端口,改这里要同步改 `client.js` 的 `DEFAULT_PORT` |
|
|
40
|
+
| `frameIntervalMs` | `200` | 相邻两帧的最小间隔 |
|
|
41
|
+
| `defaultSerial` | `''` | 工具不传 `serial` 时用的设备 |
|
|
42
|
+
|
|
43
|
+
## 界面
|
|
44
|
+
|
|
45
|
+
分两块:**管理页**在侧栏,**画面**在浮窗。
|
|
46
|
+
|
|
47
|
+
左侧栏「记忆系统」下面多一行 **手机镜像**,点开是设备管理页:
|
|
48
|
+
|
|
49
|
+
- 每台手机一行:型号、serial、`在线 / 未授权 / 离线`,以及输入归属(`agent 操作中` / `已禁止 agent`)
|
|
50
|
+
- 行内 `打开镜像` / `关闭镜像`:画面出现在右下角浮窗里,**不占用对话区**,可以边看手机边聊
|
|
51
|
+
(点「打开镜像」会自动收起管理页、切回对话——否则浮窗会被整页面板盖住)
|
|
52
|
+
- 行内 `接管`(agent 正在操作时)、`禁止 agent` / `解除`(锁住这台手机)
|
|
53
|
+
- 顶部 `刷新` 立即重拉 `adb devices`;没有设备时给连接提示
|
|
54
|
+
|
|
55
|
+
浮窗标题栏有四个控件:设备下拉(多设备时切换)、`⤢` 在独立窗口打开、`–` 收起(只留标题条)、
|
|
56
|
+
`×` 关闭(整个窗口收起,从管理页再打开即可)。
|
|
57
|
+
|
|
58
|
+
需要更大的画面、放到第二块屏,或拖到 DSH 窗口之外时,用 `⤢`(管理页每台在线设备也有
|
|
59
|
+
`独立窗口` 按钮):宿主会开一个**原生 macOS 窗口**,不是浏览器标签页,也没有地址栏。
|
|
60
|
+
窗口默认是普通层级(**不置顶**),可以拖到屏幕任意位置、缩放,位置会记住;关闭窗口即停止拉流,
|
|
61
|
+
DSH 退出时窗口一起关闭。窗口内仍是 `/mirror` 页面,设备切换、返回/主页/任务、点击/拖拽和
|
|
62
|
+
输入归属都复用;输入走 scrcpy control 通道,点击和滑动是毫秒级响应。
|
|
63
|
+
|
|
64
|
+
窗口页还有两个控件:**「置顶」** 把窗口浮到普通窗口之上(再点一次取消,默认关),
|
|
65
|
+
**「贴右」** 把窗口移到屏幕可见区域右侧。DSH 和手机窗并排时如果互相遮挡,用「置顶」
|
|
66
|
+
或把 DSH 缩窄即可完整看到手机。
|
|
67
|
+
|
|
68
|
+
> 独立窗口仅支持 macOS:用系统自带的 `osascript` 跑 `lib/window.jxa`,不需要编译或另装 App。
|
|
69
|
+
> 也可以直接在浏览器打开 `http://127.0.0.1:7799/mirror?serial=<设备>` 调试。
|
|
70
|
+
|
|
71
|
+
> 管理页走 DSH 的 `main` + `sidebar.panellist` 两个槽位,和「自动化任务」是同一套注册方式;
|
|
72
|
+
> 如果你的 DSH 版本没有这两个槽,插件会退化成只有浮窗 + 工具,不会报错。
|
|
73
|
+
|
|
74
|
+
## 工具
|
|
75
|
+
|
|
76
|
+
| 工具 | 用途 |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `phone_devices` | 列出设备 |
|
|
79
|
+
| `phone_ui_tree` | 控件树(文本 / desc / resource-id / bounds),定位元素的主力 |
|
|
80
|
+
| `phone_screenshot` | 存一张 PNG 到临时目录并返回路径(贵,谨慎用) |
|
|
81
|
+
| `phone_current_window` | 当前前台窗口 |
|
|
82
|
+
| `phone_tap` / `phone_swipe` | 点击 / 滑动(需持有租约) |
|
|
83
|
+
| `phone_type` | 输入 ASCII 文本(需持有租约) |
|
|
84
|
+
| `phone_key` | home / back / enter / recent …(需持有租约) |
|
|
85
|
+
| `phone_find` | 按文本/desc/id 找控件,直接给点击坐标 |
|
|
86
|
+
| `phone_tap_text` | 按文本找到并点它,不用自己算坐标(需持有租约) |
|
|
87
|
+
| `phone_wait_for` | **等**控件出现/消失,命中即返回;agent 的主要断言手段 |
|
|
88
|
+
| `phone_assert_visible` | 一次采样断言「它在不在」 |
|
|
89
|
+
| `phone_wait_stable` | 等界面稳定(转场、加载),比 sleep 靠谱 |
|
|
90
|
+
| `phone_arm` / `phone_disarm` / `phone_control` | 借用/归还/查询手机操作权 |
|
|
91
|
+
| `phone_lock` | 真人硬开关:锁上后 agent 连 `phone_arm` 都借不到 |
|
|
92
|
+
|
|
93
|
+
### 输入归属:agent 和真人怎么不打架
|
|
94
|
+
|
|
95
|
+
手机只有一块屏,两个人同时点就会互相踩。所以默认 **owner = human**:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
agent: phone_arm({ttlMs: 120000, note: "帮你回一条微信"}) → 拿到租约
|
|
99
|
+
agent: phone_tap_text({text: "发送"}) → 需要租约,否则 CONTROL_NOT_ARMED
|
|
100
|
+
agent: phone_disarm() → 主动交还
|
|
101
|
+
真人: 面板底部显示「🤖 agent 正在操作 · 剩余 87s」,点一下即可「接管」
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
租约到点自动还给真人(`ttlMs` 默认 120s,上限 30min),agent 崩了也不会把手机锁死。agent 持租约期间真人在面板上的点击会被拒(HTTP 409),而不是悄悄抢走。
|
|
105
|
+
|
|
106
|
+
## 安全模型
|
|
107
|
+
|
|
108
|
+
这个插件把「本机的一个 HTTP 端口」和「adb 的 shell 权限」直接暴露给了 agent,请按这个前提使用:
|
|
109
|
+
|
|
110
|
+
- 本地桥只监听 `127.0.0.1:7799`,**没有鉴权**——同一台机器上的任何进程都能驱动手机,这和 `adb` 本身的信任边界一致。不要把它转发到局域网。
|
|
111
|
+
- scrcpy server 与 `uiautomator`、`input` 都以 `shell` 身份运行:能读屏幕、读控件树、模拟输入。别在不受信任的机器上对着不受信任的设备用。
|
|
112
|
+
- 真人优先:agent 必须先 `phone_arm` 借租约,真人随时可「接管」或 `phone_lock` 硬锁;面板上的真人点击永远不需要许可。
|
|
113
|
+
- 插件不联网、不上传画面;视频只在 `127.0.0.1` 上从 Host 进程流到 DSH 面板。
|
|
114
|
+
|
|
115
|
+
## 已知边界
|
|
116
|
+
|
|
117
|
+
- `FLAG_SECURE` 页面(银行、部分 IM)截图是全黑,无 root 无法绕过;`phone_screenshot` 会明确报 `SCREENSHOT_INVALID`。
|
|
118
|
+
- `input text` 不支持中文,`phone_type` 遇到非 ASCII 直接报错而不是静默丢字。
|
|
119
|
+
- 页面若是 https,浏览器会拦本地 http 帧流;此时面板提示改用 `ctx.connection` 通道(`docs/DETAIL.md` 有迁移路径)。
|
|
120
|
+
- 只支持 Android。iOS 需要 WebDriverAgent 或 pymobiledevice3,完全是另一条路。
|
|
121
|
+
- scrcpy server(`vendor/scrcpy-server-1.25.jar`)以 shell 身份 `app_process` 启动,**启动后会自删 jar**,所以每次开流前都会比对 md5 重新 push;`max_size=720` 是对长边等比缩放(1080×2400 → 328×720)。
|
|
122
|
+
## 许可
|
|
123
|
+
|
|
124
|
+
- 本项目:MIT,见 [LICENSE](LICENSE)。
|
|
125
|
+
- 捆绑的 `vendor/scrcpy-server-1.25.jar`:scrcpy 的 server(Apache-2.0,未修改,来自 v1.25 release)。来源、校验和与合规说明见 [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md),许可证全文见 [licenses/Apache-2.0.txt](licenses/Apache-2.0.txt)。
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
This project bundles one third-party binary. Everything else in the repository
|
|
4
|
+
is original code written for this plugin.
|
|
5
|
+
|
|
6
|
+
## scrcpy server (`vendor/scrcpy-server-1.25.jar`)
|
|
7
|
+
|
|
8
|
+
| | |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| Upstream project | scrcpy — https://github.com/Genymobile/scrcpy |
|
|
11
|
+
| Version | 1.25 |
|
|
12
|
+
| Upstream file | `scrcpy-server-v1.25` release asset for tag `v1.25` |
|
|
13
|
+
| Source URL | https://github.com/Genymobile/scrcpy/releases/download/v1.25/scrcpy-server-v1.25 |
|
|
14
|
+
| License | Apache License 2.0 (see [`licenses/Apache-2.0.txt`](licenses/Apache-2.0.txt)) |
|
|
15
|
+
| Copyright | Copyright (C) 2018 Genymobile, Copyright (C) 2018-2021 Romain Vimont |
|
|
16
|
+
| Size / checksum | 42,151 bytes, MD5 `f636d4bacae28c10943e44266bebc967` |
|
|
17
|
+
| Modifications | none — byte-identical to the upstream release asset |
|
|
18
|
+
|
|
19
|
+
### Why it is bundled
|
|
20
|
+
|
|
21
|
+
The plugin streams the phone screen as H.264. Android's own `screenrecord` is
|
|
22
|
+
blocked by SELinux on some OEM builds (verified on Android 11), so the
|
|
23
|
+
plugin runs the scrcpy server instead: it is pushed to
|
|
24
|
+
`/data/local/tmp/scrcpy-server.jar` and executed with
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.25 ...
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Because scrcpy's server deletes its own jar after starting, the plugin re-pushes
|
|
31
|
+
it whenever the checksum on the device no longer matches (see
|
|
32
|
+
`ensureDeviceJar` in `lib/video.js`). Shipping the jar inside the package keeps
|
|
33
|
+
the plugin usable offline and pins the exact server build the wire format was
|
|
34
|
+
verified against.
|
|
35
|
+
|
|
36
|
+
### License compliance
|
|
37
|
+
|
|
38
|
+
The scrcpy server is distributed under the Apache License, Version 2.0. A copy
|
|
39
|
+
of the license text is included at `licenses/Apache-2.0.txt`. The jar is
|
|
40
|
+
unmodified; if you patch or rebuild it, you must also comply with the Apache
|
|
41
|
+
License 2.0 requirements for modified files (retain notices, state changes).
|
|
42
|
+
|
|
43
|
+
## Development-time references (not bundled)
|
|
44
|
+
|
|
45
|
+
- `scrcpy` documentation for the video stream framing used by
|
|
46
|
+
`lib/video.js` (1-byte dummy, 64-byte device name, 2×u16 dimensions, then
|
|
47
|
+
12-byte packet headers with config/key flags).
|
|
48
|
+
- Android `uiautomator dump`, `input`, `screencap`, `dumpsys` are part of the
|
|
49
|
+
Android platform (Apache License 2.0) and are invoked as external commands;
|
|
50
|
+
no Android code is copied into this repository.
|
|
Binary file
|