@yume-chan/scrcpy 0.0.11
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.json +43 -0
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +88 -0
- package/bin/scrcpy-server +0 -0
- package/bin/version.d.ts +1 -0
- package/bin/version.js +1 -0
- package/esm/client.d.ts +36 -0
- package/esm/client.d.ts.map +1 -0
- package/esm/client.js +209 -0
- package/esm/client.js.map +1 -0
- package/esm/codec.d.ts +34 -0
- package/esm/codec.d.ts.map +1 -0
- package/esm/codec.js +37 -0
- package/esm/codec.js.map +1 -0
- package/esm/connection.d.ts +37 -0
- package/esm/connection.d.ts.map +1 -0
- package/esm/connection.js +103 -0
- package/esm/connection.js.map +1 -0
- package/esm/decoder/index.d.ts +4 -0
- package/esm/decoder/index.d.ts.map +1 -0
- package/esm/decoder/index.js +4 -0
- package/esm/decoder/index.js.map +1 -0
- package/esm/decoder/tinyh264/index.d.ts +20 -0
- package/esm/decoder/tinyh264/index.d.ts.map +1 -0
- package/esm/decoder/tinyh264/index.js +86 -0
- package/esm/decoder/tinyh264/index.js.map +1 -0
- package/esm/decoder/tinyh264/worker.d.ts +2 -0
- package/esm/decoder/tinyh264/worker.d.ts.map +1 -0
- package/esm/decoder/tinyh264/worker.js +3 -0
- package/esm/decoder/tinyh264/worker.js.map +1 -0
- package/esm/decoder/tinyh264/wrapper.d.ts +21 -0
- package/esm/decoder/tinyh264/wrapper.d.ts.map +1 -0
- package/esm/decoder/tinyh264/wrapper.js +67 -0
- package/esm/decoder/tinyh264/wrapper.js.map +1 -0
- package/esm/decoder/types.d.ts +28 -0
- package/esm/decoder/types.d.ts.map +1 -0
- package/esm/decoder/types.js +2 -0
- package/esm/decoder/types.js.map +1 -0
- package/esm/decoder/web-codecs/index.d.ts +22 -0
- package/esm/decoder/web-codecs/index.d.ts.map +1 -0
- package/esm/decoder/web-codecs/index.js +75 -0
- package/esm/decoder/web-codecs/index.js.map +1 -0
- package/esm/index.d.ts +9 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +9 -0
- package/esm/index.js.map +1 -0
- package/esm/message.d.ts +93 -0
- package/esm/message.d.ts.map +1 -0
- package/esm/message.js +92 -0
- package/esm/message.js.map +1 -0
- package/esm/options/1_16/index.d.ts +107 -0
- package/esm/options/1_16/index.d.ts.map +1 -0
- package/esm/options/1_16/index.js +211 -0
- package/esm/options/1_16/index.js.map +1 -0
- package/esm/options/1_16/sps.d.ts +22 -0
- package/esm/options/1_16/sps.d.ts.map +1 -0
- package/esm/options/1_16/sps.js +254 -0
- package/esm/options/1_16/sps.js.map +1 -0
- package/esm/options/1_18.d.ts +19 -0
- package/esm/options/1_18.d.ts.map +1 -0
- package/esm/options/1_18.js +23 -0
- package/esm/options/1_18.js.map +1 -0
- package/esm/options/1_21.d.ts +10 -0
- package/esm/options/1_21.d.ts.map +1 -0
- package/esm/options/1_21.js +23 -0
- package/esm/options/1_21.js.map +1 -0
- package/esm/options/1_22.d.ts +43 -0
- package/esm/options/1_22.d.ts.map +1 -0
- package/esm/options/1_22.js +40 -0
- package/esm/options/1_22.js.map +1 -0
- package/esm/options/common.d.ts +30 -0
- package/esm/options/common.d.ts.map +1 -0
- package/esm/options/common.js +16 -0
- package/esm/options/common.js.map +1 -0
- package/esm/options/index.d.ts +6 -0
- package/esm/options/index.d.ts.map +1 -0
- package/esm/options/index.js +6 -0
- package/esm/options/index.js.map +1 -0
- package/esm/push-server.d.ts +6 -0
- package/esm/push-server.d.ts.map +1 -0
- package/esm/push-server.js +23 -0
- package/esm/push-server.js.map +1 -0
- package/esm/utils.d.ts +4 -0
- package/esm/utils.d.ts.map +1 -0
- package/esm/utils.js +14 -0
- package/esm/utils.js.map +1 -0
- package/package.json +61 -0
- package/scrcpy.LICENSE +203 -0
- package/scripts/fetch-server.cjs +28 -0
- package/src/client.ts +275 -0
- package/src/codec.ts +35 -0
- package/src/connection.ts +123 -0
- package/src/decoder/index.ts +3 -0
- package/src/decoder/tinyh264/index.ts +112 -0
- package/src/decoder/tinyh264/types.d.ts +137 -0
- package/src/decoder/tinyh264/worker.ts +2 -0
- package/src/decoder/tinyh264/wrapper.ts +89 -0
- package/src/decoder/types.ts +35 -0
- package/src/decoder/web-codecs/index.ts +98 -0
- package/src/index.ts +8 -0
- package/src/message.ts +105 -0
- package/src/options/1_16/index.ts +322 -0
- package/src/options/1_16/sps.ts +300 -0
- package/src/options/1_18.ts +41 -0
- package/src/options/1_21.ts +34 -0
- package/src/options/1_22.ts +80 -0
- package/src/options/common.ts +61 -0
- package/src/options/index.ts +5 -0
- package/src/push-server.ts +26 -0
- package/src/utils.ts +16 -0
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yume-chan/scrcpy",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "TypeScript implementation of Scrcpy.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"adb",
|
|
7
|
+
"android-phone",
|
|
8
|
+
"scrcpy"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Simon Chan",
|
|
13
|
+
"email": "cnsimonchan@live.com",
|
|
14
|
+
"url": "https://chensi.moe/blog"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/yume-chan/ya-webadb/tree/master/packages/scrcpy#readme",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/yume-chan/ya-webadb.git",
|
|
20
|
+
"directory": "packages/scrcpy"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/yume-chan/ya-webadb/issues"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"fetch-scrcpy-server": "scripts/fetch-server.cjs"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "esm/index.js",
|
|
30
|
+
"types": "esm/index.d.ts",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@yume-chan/adb": "^0.0.11",
|
|
33
|
+
"@yume-chan/async": "^2.1.4",
|
|
34
|
+
"@yume-chan/event": "^0.0.10",
|
|
35
|
+
"@yume-chan/struct": "^0.0.10",
|
|
36
|
+
"tslib": "^2.3.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/dom-webcodecs": "^0.1.3",
|
|
40
|
+
"@types/jest": "^27.4.1",
|
|
41
|
+
"@yume-chan/ts-package-builder": "^1.0.0",
|
|
42
|
+
"gh-release-fetch": "^2.0.4",
|
|
43
|
+
"jest": "^27.5.1",
|
|
44
|
+
"tinyh264": "^0.0.7",
|
|
45
|
+
"typescript": "next",
|
|
46
|
+
"yuv-buffer": "^1.0.0",
|
|
47
|
+
"yuv-canvas": "^1.2.7"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@types/dom-webcodecs": "^0.1.3",
|
|
51
|
+
"tinyh264": "^0.0.6",
|
|
52
|
+
"yuv-buffer": "^1.0.0",
|
|
53
|
+
"yuv-canvas": "^1.2.7"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "build-ts-package",
|
|
57
|
+
"build:watch": "build-ts-package --incremental",
|
|
58
|
+
"test": "jest --coverage"
|
|
59
|
+
},
|
|
60
|
+
"readme": "# @yume-chan/scrcpy\r\n\r\nTypeScript implementation of [Scrcpy](https://github.com/Genymobile/scrcpy) client.\r\n\r\nIt uses the official Scrcpy server releases.\r\n\r\n**WARNING:** The public API is UNSTABLE. If you have any questions, please open an issue.\r\n\r\n## Download Server Binary\r\n\r\nThis package has a script `fetch-scrcpy-server` to help you download the official server binary.\r\n\r\nThe server binary is subject to [Apache License 2.0](https://github.com/Genymobile/scrcpy/blob/master/LICENSE).\r\n\r\nUsage:\r\n\r\n```\r\n$ npx fetch-scrcpy-server <version>\r\n```\r\n\r\nFor example:\r\n\r\n```\r\n$ npx fetch-scrcpy-server 1.21\r\n```\r\n\r\nYou can also add it to the `postinstall` script of your `package.json` so it will run automatically when you do `npm install`:\r\n\r\n```json\r\n\"scripts\": {\r\n \"postinstall\": \"fetch-scrcpy-server 1.21\",\r\n},\r\n```\r\n\r\nIt will download the binary to `bin/scrcpy` and write the version string to `bin/version.js`. You can import the version string with\r\n\r\n```js\r\nimport SCRCPY_SERVER_VERSION from '@yume-chan/scrcpy/bin/version';\r\n```\r\n\r\nAnd import the server binary with [file-loader](https://v4.webpack.js.org/loaders/file-loader/) (Webpack 4) or [Asset Modules](https://webpack.js.org/guides/asset-modules/) (Webpack 5).\r\n\r\n## Option versions\r\n\r\nScrcpy server has no backward compatibility on options input format. Currently the following versions are supported:\r\n\r\n| versions | type |\r\n| --------- | ------------------- |\r\n| 1.16~1.17 | `ScrcpyOptions1_16` |\r\n| 1.18~1.20 | `ScrcpyOptions1_18` |\r\n| 1.21 | `ScrcpyOptions1_21` |\r\n| 1.22 | `ScrcpyOptions1_22` |\r\n\r\nYou must use the correct type according to the server version.\r\n\r\n## Video stream\r\n\r\nThe data from `onVideoData` event is a raw H.264 stream. You can process it as you want, or use the following built-in decoders to render it in browsers:\r\n\r\n* WebCodecs decoder: Uses the [WebCodecs API](https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API). The video stream will be decoded into `VideoFrame`s and drawn on a 2D canvas.\r\n* TinyH264 decoder: TinyH264 compiles the old Android H.264 software decoder (now deprecated and removed) into WebAssembly, and wrap it in Web Worker to prevent blocking the main thread. The video stream will be decoded into YUV frames, then converted to RGB using a WebGL shader.\r\n\r\n| Name | Chrome | Firefox | Safari | Performance | Supported H.264 profile/level |\r\n| ----------------- | ------ | ------- | ------ | ------------------------------- | ----------------------------- |\r\n| WebCodecs decoder | 94 | No | No | High with Hardware acceleration | High level 5 |\r\n| TinyH264 decoder | 57 | 52 | 11 | Poor | Baseline level 4 |\r\n\r\nTinyH264 decoder needs some extra setup:\r\n\r\n1. `tinyh264`, `yuv-buffer` and `yuv-canvas` packages are peer dependencies. You must install them separately.\r\n2. The bundler you use must support the `new Worker(new URL('./worker.js', import.meta.url))` syntax. It's known to work with Webpack 5.\r\n\r\nExample usage:\r\n\r\n```ts\r\nconst client = new ScrcpyClient(adb);\r\nconst decoder = new WebCodecsDecoder(); // Or `new TinyH264Decoder()`\r\nclient.onSizeChanged(size => decoder.setSize(size));\r\nclient.onVideoData(data => decoder.feed(data));\r\nclient.start(serverPath, serverVersion, new ScrcpyOptionsX_XX({\r\n ...options,\r\n codecOptions: new CodecOptions({\r\n profile: decoder.maxProfile,\r\n level: decoder.maxLevel,\r\n }),\r\n}));\r\ndocument.body.appendChild(decoder.element);\r\n```\r\n"
|
|
61
|
+
}
|
package/scrcpy.LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright (C) 2018 Genymobile
|
|
191
|
+
Copyright (C) 2018-2021 Romain Vimont
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { fetchVersion } = require('gh-release-fetch');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs').promises;
|
|
6
|
+
|
|
7
|
+
(async () => {
|
|
8
|
+
const serverVersion = process.argv[2];
|
|
9
|
+
console.log(`Downloading Scrcpy server binary version ${serverVersion}...`);
|
|
10
|
+
|
|
11
|
+
const binFolder = path.resolve(__dirname, '..', 'bin');
|
|
12
|
+
|
|
13
|
+
await fetchVersion({
|
|
14
|
+
repository: 'Genymobile/scrcpy',
|
|
15
|
+
version: `v${serverVersion}`,
|
|
16
|
+
package: `scrcpy-server-v${serverVersion}`,
|
|
17
|
+
destination: binFolder,
|
|
18
|
+
extract: false,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
await fs.rename(
|
|
22
|
+
path.resolve(binFolder, `scrcpy-server-v${serverVersion}`),
|
|
23
|
+
path.resolve(binFolder, 'scrcpy-server')
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
fs.writeFile(path.resolve(binFolder, 'version.js'), `export default '${serverVersion}';`);
|
|
27
|
+
fs.writeFile(path.resolve(binFolder, 'version.d.ts'), `export default '${serverVersion}';`);
|
|
28
|
+
})();
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { AdbBufferedStream, AdbNoneSubprocessProtocol, DecodeUtf8Stream, InspectStream, TransformStream, WritableStream, type Adb, type AdbSocket, type AdbSubprocessProtocol, type ReadableStream, type WritableStreamDefaultWriter } from '@yume-chan/adb';
|
|
2
|
+
import { EventEmitter } from '@yume-chan/event';
|
|
3
|
+
import Struct from '@yume-chan/struct';
|
|
4
|
+
import { AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage, type AndroidKeyEventAction } from './message.js';
|
|
5
|
+
import type { ScrcpyInjectScrollControlMessage1_22, ScrcpyOptions, VideoStreamPacket } from "./options/index.js";
|
|
6
|
+
|
|
7
|
+
function* splitLines(text: string): Generator<string, void, void> {
|
|
8
|
+
let start = 0;
|
|
9
|
+
|
|
10
|
+
while (true) {
|
|
11
|
+
const index = text.indexOf('\n', start);
|
|
12
|
+
if (index === -1) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const line = text.substring(start, index);
|
|
17
|
+
yield line;
|
|
18
|
+
|
|
19
|
+
start = index + 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ClipboardMessage =
|
|
24
|
+
new Struct()
|
|
25
|
+
.uint32('length')
|
|
26
|
+
.string('content', { lengthField: 'length' });
|
|
27
|
+
|
|
28
|
+
export class ScrcpyClient {
|
|
29
|
+
public static async getEncoders(
|
|
30
|
+
adb: Adb,
|
|
31
|
+
path: string,
|
|
32
|
+
version: string,
|
|
33
|
+
options: ScrcpyOptions<any>
|
|
34
|
+
): Promise<string[]> {
|
|
35
|
+
// Provide an invalid encoder name
|
|
36
|
+
// So the server will return all available encoders
|
|
37
|
+
options.value.encoderName = '_';
|
|
38
|
+
// Disable control for faster connection in 1.22+
|
|
39
|
+
options.value.control = false;
|
|
40
|
+
|
|
41
|
+
// Scrcpy server will open connections, before initializing encoder
|
|
42
|
+
// Thus although an invalid encoder name is given, the start process will success
|
|
43
|
+
const client = await ScrcpyClient.start(adb, path, version, options);
|
|
44
|
+
|
|
45
|
+
const encoderNameRegex = options.getOutputEncoderNameRegex();
|
|
46
|
+
const encoders: string[] = [];
|
|
47
|
+
await client.stdout.pipeTo(new WritableStream({
|
|
48
|
+
write(line) {
|
|
49
|
+
const match = line.match(encoderNameRegex);
|
|
50
|
+
if (match) {
|
|
51
|
+
encoders.push(match[1]!);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
return encoders;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public static async start(
|
|
60
|
+
adb: Adb,
|
|
61
|
+
path: string,
|
|
62
|
+
version: string,
|
|
63
|
+
options: ScrcpyOptions<any>
|
|
64
|
+
) {
|
|
65
|
+
const connection = options.createConnection(adb);
|
|
66
|
+
let process: AdbSubprocessProtocol | undefined;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await connection.initialize();
|
|
70
|
+
|
|
71
|
+
process = await adb.subprocess.spawn(
|
|
72
|
+
[
|
|
73
|
+
// cspell: disable-next-line
|
|
74
|
+
`CLASSPATH=${path}`,
|
|
75
|
+
'app_process',
|
|
76
|
+
/* unused */ '/',
|
|
77
|
+
'com.genymobile.scrcpy.Server',
|
|
78
|
+
version,
|
|
79
|
+
...options.formatServerArguments(),
|
|
80
|
+
],
|
|
81
|
+
{
|
|
82
|
+
// Scrcpy server doesn't split stdout and stderr,
|
|
83
|
+
// so disable Shell Protocol to simplify processing
|
|
84
|
+
protocols: [AdbNoneSubprocessProtocol],
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const result = await Promise.race([
|
|
89
|
+
process.exit,
|
|
90
|
+
connection.getStreams(),
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
if (typeof result === 'number') {
|
|
94
|
+
throw new Error('scrcpy server exited prematurely');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const [videoStream, controlStream] = result;
|
|
98
|
+
return new ScrcpyClient(adb, options, process, videoStream, controlStream);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
await process?.kill();
|
|
101
|
+
throw e;
|
|
102
|
+
} finally {
|
|
103
|
+
connection.dispose();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private _adb: Adb;
|
|
108
|
+
public get adb() { return this._adb; }
|
|
109
|
+
|
|
110
|
+
private options: ScrcpyOptions<any>;
|
|
111
|
+
private process: AdbSubprocessProtocol;
|
|
112
|
+
|
|
113
|
+
private _stdout: ReadableStream<string>;
|
|
114
|
+
public get stdout() { return this._stdout; }
|
|
115
|
+
|
|
116
|
+
public get exit() { return this.process.exit; }
|
|
117
|
+
|
|
118
|
+
private _screenWidth: number | undefined;
|
|
119
|
+
public get screenWidth() { return this._screenWidth; }
|
|
120
|
+
|
|
121
|
+
private _screenHeight: number | undefined;
|
|
122
|
+
public get screenHeight() { return this._screenHeight; }
|
|
123
|
+
|
|
124
|
+
private _videoStream: ReadableStream<VideoStreamPacket>;
|
|
125
|
+
public get videoStream() { return this._videoStream; }
|
|
126
|
+
|
|
127
|
+
private _controlStreamWriter: WritableStreamDefaultWriter<Uint8Array> | undefined;
|
|
128
|
+
|
|
129
|
+
private readonly clipboardChangeEvent = new EventEmitter<string>();
|
|
130
|
+
public get onClipboardChange() { return this.clipboardChangeEvent.event; }
|
|
131
|
+
|
|
132
|
+
private lastTouchMessage = 0;
|
|
133
|
+
|
|
134
|
+
public constructor(
|
|
135
|
+
adb: Adb,
|
|
136
|
+
options: ScrcpyOptions<any>,
|
|
137
|
+
process: AdbSubprocessProtocol,
|
|
138
|
+
videoStream: AdbBufferedStream,
|
|
139
|
+
controlStream: AdbSocket | undefined,
|
|
140
|
+
) {
|
|
141
|
+
this._adb = adb;
|
|
142
|
+
this.options = options;
|
|
143
|
+
this.process = process;
|
|
144
|
+
|
|
145
|
+
this._stdout = process.stdout
|
|
146
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
147
|
+
.pipeThrough(new TransformStream({
|
|
148
|
+
transform(chunk, controller) {
|
|
149
|
+
for (const line of splitLines(chunk)) {
|
|
150
|
+
if (line === '') {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
controller.enqueue(line);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
this._videoStream = options
|
|
159
|
+
.parseVideoStream(videoStream)
|
|
160
|
+
.pipeThrough(new InspectStream(packet => {
|
|
161
|
+
if (packet.type === 'configuration') {
|
|
162
|
+
this._screenWidth = packet.data.croppedWidth;
|
|
163
|
+
this._screenHeight = packet.data.croppedHeight;
|
|
164
|
+
}
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
if (controlStream) {
|
|
168
|
+
const buffered = new AdbBufferedStream(controlStream);
|
|
169
|
+
this._controlStreamWriter = controlStream.writable.getWriter();
|
|
170
|
+
(async () => {
|
|
171
|
+
try {
|
|
172
|
+
while (true) {
|
|
173
|
+
const type = await buffered.read(1);
|
|
174
|
+
switch (type[0]) {
|
|
175
|
+
case 0:
|
|
176
|
+
const { content } = await ClipboardMessage.deserialize(buffered);
|
|
177
|
+
this.clipboardChangeEvent.fire(content!);
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
throw new Error('unknown control message type');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} catch {
|
|
184
|
+
// TODO: Scrcpy: handle error
|
|
185
|
+
}
|
|
186
|
+
})();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private checkControlStream(caller: string) {
|
|
191
|
+
if (!this._controlStreamWriter) {
|
|
192
|
+
throw new Error(`${caller} called with control disabled`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return this._controlStreamWriter;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public async injectKeyCode(message: Omit<ScrcpyInjectKeyCodeControlMessage, 'type'>) {
|
|
199
|
+
const controlStream = this.checkControlStream('injectKeyCode');
|
|
200
|
+
|
|
201
|
+
await controlStream.write(ScrcpyInjectKeyCodeControlMessage.serialize({
|
|
202
|
+
...message,
|
|
203
|
+
type: ScrcpyControlMessageType.InjectKeycode,
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public async injectText(text: string) {
|
|
208
|
+
const controlStream = this.checkControlStream('injectText');
|
|
209
|
+
|
|
210
|
+
await controlStream.write(ScrcpyInjectTextControlMessage.serialize({
|
|
211
|
+
type: ScrcpyControlMessageType.InjectText,
|
|
212
|
+
text,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public async injectTouch(message: Omit<ScrcpyInjectTouchControlMessage, 'type' | 'screenWidth' | 'screenHeight'>) {
|
|
217
|
+
const controlStream = this.checkControlStream('injectTouch');
|
|
218
|
+
|
|
219
|
+
if (!this.screenWidth || !this.screenHeight) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ADB streams are actually pretty low-bandwidth and laggy
|
|
224
|
+
// Re-sample move events to avoid flooding the connection
|
|
225
|
+
|
|
226
|
+
// TODO: Scrcpy: investigate how to throttle touch events
|
|
227
|
+
// because 60FPS may still be too high
|
|
228
|
+
const now = Date.now();
|
|
229
|
+
if (now - this.lastTouchMessage < 16 &&
|
|
230
|
+
[AndroidMotionEventAction.Move, AndroidMotionEventAction.HoverMove].includes(message.action)) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this.lastTouchMessage = now;
|
|
235
|
+
await controlStream.write(ScrcpyInjectTouchControlMessage.serialize({
|
|
236
|
+
...message,
|
|
237
|
+
type: ScrcpyControlMessageType.InjectTouch,
|
|
238
|
+
screenWidth: this.screenWidth,
|
|
239
|
+
screenHeight: this.screenHeight,
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public async injectScroll(message: Omit<ScrcpyInjectScrollControlMessage1_22, 'type' | 'screenWidth' | 'screenHeight'>) {
|
|
244
|
+
const controlStream = this.checkControlStream('injectScroll');
|
|
245
|
+
|
|
246
|
+
if (!this.screenWidth || !this.screenHeight) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const buffer = this.options!.serializeInjectScrollControlMessage({
|
|
251
|
+
...message,
|
|
252
|
+
type: ScrcpyControlMessageType.InjectScroll,
|
|
253
|
+
screenWidth: this.screenWidth,
|
|
254
|
+
screenHeight: this.screenHeight,
|
|
255
|
+
});
|
|
256
|
+
await controlStream.write(buffer);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
public async pressBackOrTurnOnScreen(action: AndroidKeyEventAction) {
|
|
260
|
+
const controlStream = this.checkControlStream('pressBackOrTurnOnScreen');
|
|
261
|
+
|
|
262
|
+
const buffer = this.options!.serializeBackOrScreenOnControlMessage({
|
|
263
|
+
type: ScrcpyControlMessageType.BackOrScreenOn,
|
|
264
|
+
action,
|
|
265
|
+
});
|
|
266
|
+
if (buffer) {
|
|
267
|
+
await controlStream.write(buffer);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
public async close() {
|
|
272
|
+
// No need to close streams. Kill the process will destroy them from the other side.
|
|
273
|
+
await this.process?.kill();
|
|
274
|
+
}
|
|
275
|
+
}
|
package/src/codec.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// From https://developer.android.com/reference/android/media/MediaCodecInfo.CodecProfileLevel
|
|
2
|
+
export enum AndroidCodecProfile {
|
|
3
|
+
Baseline = 0x01,
|
|
4
|
+
Main = 0x02,
|
|
5
|
+
Extended = 0x04,
|
|
6
|
+
High = 0x08,
|
|
7
|
+
High10 = 0x10,
|
|
8
|
+
High422 = 0x20,
|
|
9
|
+
High444 = 0x40,
|
|
10
|
+
ConstrainedBaseline = 0x10000,
|
|
11
|
+
ConstrainedHigh = 0x80000,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export enum AndroidCodecLevel {
|
|
15
|
+
Level1 = 0x01,
|
|
16
|
+
Level1b = 0x02,
|
|
17
|
+
Level11 = 0x04,
|
|
18
|
+
Level12 = 0x08,
|
|
19
|
+
Level13 = 0x10,
|
|
20
|
+
Level2 = 0x20,
|
|
21
|
+
Level21 = 0x40,
|
|
22
|
+
Level22 = 0x80,
|
|
23
|
+
Level3 = 0x100,
|
|
24
|
+
Level31 = 0x200,
|
|
25
|
+
Level32 = 0x400,
|
|
26
|
+
Level4 = 0x800,
|
|
27
|
+
Level41 = 0x1000,
|
|
28
|
+
Level42 = 0x2000,
|
|
29
|
+
Level5 = 0x4000,
|
|
30
|
+
Level51 = 0x8000,
|
|
31
|
+
Level52 = 0x10000,
|
|
32
|
+
Level6 = 0x20000,
|
|
33
|
+
Level61 = 0x40000,
|
|
34
|
+
Level62 = 0x80000,
|
|
35
|
+
}
|