@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/CHANGELOG.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yume-chan/scrcpy",
|
|
3
|
+
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.0.11",
|
|
6
|
+
"tag": "@yume-chan/scrcpy_v0.0.11",
|
|
7
|
+
"date": "Sun, 03 Apr 2022 10:54:15 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Add support for 1.22 new server options"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "Update to use Web Streams API"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"comment": "Improve compatibility with Node.js 12 ESM format"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"comment": "Workaround a issue with server crash on Samsung ROM (https://github.com/Genymobile/scrcpy/issues/2841)"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"comment": "Remove output parsing. It's output is for debugging only, not machine readable."
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"comment": "Update license year"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"dependency": [
|
|
30
|
+
{
|
|
31
|
+
"comment": "Updating dependency \"@yume-chan/adb\" from `^0.0.10` to `^0.0.11`"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"version": "0.0.10",
|
|
38
|
+
"tag": "@yume-chan/scrcpy_v0.0.10",
|
|
39
|
+
"date": "Sun, 09 Jan 2022 15:52:20 GMT",
|
|
40
|
+
"comments": {}
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Change Log - @yume-chan/scrcpy
|
|
2
|
+
|
|
3
|
+
This log was last generated on Sun, 03 Apr 2022 10:54:15 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.0.11
|
|
6
|
+
Sun, 03 Apr 2022 10:54:15 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Add support for 1.22 new server options
|
|
11
|
+
- Update to use Web Streams API
|
|
12
|
+
- Improve compatibility with Node.js 12 ESM format
|
|
13
|
+
- Workaround a issue with server crash on Samsung ROM (https://github.com/Genymobile/scrcpy/issues/2841)
|
|
14
|
+
- Remove output parsing. It's output is for debugging only, not machine readable.
|
|
15
|
+
- Update license year
|
|
16
|
+
|
|
17
|
+
## 0.0.10
|
|
18
|
+
Sun, 09 Jan 2022 15:52:20 GMT
|
|
19
|
+
|
|
20
|
+
_Initial release_
|
|
21
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2022 Simon Chan
|
|
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
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @yume-chan/scrcpy
|
|
2
|
+
|
|
3
|
+
TypeScript implementation of [Scrcpy](https://github.com/Genymobile/scrcpy) client.
|
|
4
|
+
|
|
5
|
+
It uses the official Scrcpy server releases.
|
|
6
|
+
|
|
7
|
+
**WARNING:** The public API is UNSTABLE. If you have any questions, please open an issue.
|
|
8
|
+
|
|
9
|
+
## Download Server Binary
|
|
10
|
+
|
|
11
|
+
This package has a script `fetch-scrcpy-server` to help you download the official server binary.
|
|
12
|
+
|
|
13
|
+
The server binary is subject to [Apache License 2.0](https://github.com/Genymobile/scrcpy/blob/master/LICENSE).
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ npx fetch-scrcpy-server <version>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For example:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
$ npx fetch-scrcpy-server 1.21
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
You can also add it to the `postinstall` script of your `package.json` so it will run automatically when you do `npm install`:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
"scripts": {
|
|
31
|
+
"postinstall": "fetch-scrcpy-server 1.21",
|
|
32
|
+
},
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
It will download the binary to `bin/scrcpy` and write the version string to `bin/version.js`. You can import the version string with
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import SCRCPY_SERVER_VERSION from '@yume-chan/scrcpy/bin/version';
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
And 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).
|
|
42
|
+
|
|
43
|
+
## Option versions
|
|
44
|
+
|
|
45
|
+
Scrcpy server has no backward compatibility on options input format. Currently the following versions are supported:
|
|
46
|
+
|
|
47
|
+
| versions | type |
|
|
48
|
+
| --------- | ------------------- |
|
|
49
|
+
| 1.16~1.17 | `ScrcpyOptions1_16` |
|
|
50
|
+
| 1.18~1.20 | `ScrcpyOptions1_18` |
|
|
51
|
+
| 1.21 | `ScrcpyOptions1_21` |
|
|
52
|
+
| 1.22 | `ScrcpyOptions1_22` |
|
|
53
|
+
|
|
54
|
+
You must use the correct type according to the server version.
|
|
55
|
+
|
|
56
|
+
## Video stream
|
|
57
|
+
|
|
58
|
+
The 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:
|
|
59
|
+
|
|
60
|
+
* 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.
|
|
61
|
+
* 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.
|
|
62
|
+
|
|
63
|
+
| Name | Chrome | Firefox | Safari | Performance | Supported H.264 profile/level |
|
|
64
|
+
| ----------------- | ------ | ------- | ------ | ------------------------------- | ----------------------------- |
|
|
65
|
+
| WebCodecs decoder | 94 | No | No | High with Hardware acceleration | High level 5 |
|
|
66
|
+
| TinyH264 decoder | 57 | 52 | 11 | Poor | Baseline level 4 |
|
|
67
|
+
|
|
68
|
+
TinyH264 decoder needs some extra setup:
|
|
69
|
+
|
|
70
|
+
1. `tinyh264`, `yuv-buffer` and `yuv-canvas` packages are peer dependencies. You must install them separately.
|
|
71
|
+
2. 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.
|
|
72
|
+
|
|
73
|
+
Example usage:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const client = new ScrcpyClient(adb);
|
|
77
|
+
const decoder = new WebCodecsDecoder(); // Or `new TinyH264Decoder()`
|
|
78
|
+
client.onSizeChanged(size => decoder.setSize(size));
|
|
79
|
+
client.onVideoData(data => decoder.feed(data));
|
|
80
|
+
client.start(serverPath, serverVersion, new ScrcpyOptionsX_XX({
|
|
81
|
+
...options,
|
|
82
|
+
codecOptions: new CodecOptions({
|
|
83
|
+
profile: decoder.maxProfile,
|
|
84
|
+
level: decoder.maxLevel,
|
|
85
|
+
}),
|
|
86
|
+
}));
|
|
87
|
+
document.body.appendChild(decoder.element);
|
|
88
|
+
```
|
|
Binary file
|
package/bin/version.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '1.22';
|
package/bin/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '1.22';
|
package/esm/client.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AdbBufferedStream, type Adb, type AdbSocket, type AdbSubprocessProtocol, type ReadableStream } from '@yume-chan/adb';
|
|
2
|
+
import { ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTouchControlMessage, type AndroidKeyEventAction } from './message.js';
|
|
3
|
+
import type { ScrcpyInjectScrollControlMessage1_22, ScrcpyOptions, VideoStreamPacket } from "./options/index.js";
|
|
4
|
+
export declare class ScrcpyClient {
|
|
5
|
+
static getEncoders(adb: Adb, path: string, version: string, options: ScrcpyOptions<any>): Promise<string[]>;
|
|
6
|
+
static start(adb: Adb, path: string, version: string, options: ScrcpyOptions<any>): Promise<ScrcpyClient>;
|
|
7
|
+
private _adb;
|
|
8
|
+
get adb(): Adb;
|
|
9
|
+
private options;
|
|
10
|
+
private process;
|
|
11
|
+
private _stdout;
|
|
12
|
+
get stdout(): ReadableStream<string>;
|
|
13
|
+
get exit(): Promise<number>;
|
|
14
|
+
private _screenWidth;
|
|
15
|
+
get screenWidth(): number | undefined;
|
|
16
|
+
private _screenHeight;
|
|
17
|
+
get screenHeight(): number | undefined;
|
|
18
|
+
private _videoStream;
|
|
19
|
+
get videoStream(): ReadableStream<VideoStreamPacket>;
|
|
20
|
+
private _controlStreamWriter;
|
|
21
|
+
private readonly clipboardChangeEvent;
|
|
22
|
+
get onClipboardChange(): {
|
|
23
|
+
(listener: import("@yume-chan/event").EventListener<string, unknown, [], unknown>): import("@yume-chan/event").RemoveEventListener;
|
|
24
|
+
<TThis, TArgs extends unknown[]>(listener: import("@yume-chan/event").EventListener<string, TThis, TArgs, unknown>, thisArg: TThis, ...args: TArgs): import("@yume-chan/event").RemoveEventListener;
|
|
25
|
+
};
|
|
26
|
+
private lastTouchMessage;
|
|
27
|
+
constructor(adb: Adb, options: ScrcpyOptions<any>, process: AdbSubprocessProtocol, videoStream: AdbBufferedStream, controlStream: AdbSocket | undefined);
|
|
28
|
+
private checkControlStream;
|
|
29
|
+
injectKeyCode(message: Omit<ScrcpyInjectKeyCodeControlMessage, 'type'>): Promise<void>;
|
|
30
|
+
injectText(text: string): Promise<void>;
|
|
31
|
+
injectTouch(message: Omit<ScrcpyInjectTouchControlMessage, 'type' | 'screenWidth' | 'screenHeight'>): Promise<void>;
|
|
32
|
+
injectScroll(message: Omit<ScrcpyInjectScrollControlMessage1_22, 'type' | 'screenWidth' | 'screenHeight'>): Promise<void>;
|
|
33
|
+
pressBackOrTurnOnScreen(action: AndroidKeyEventAction): Promise<void>;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA+F,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,KAAK,qBAAqB,EAAE,KAAK,cAAc,EAAoC,MAAM,gBAAgB,CAAC;AAG7P,OAAO,EAAsD,iCAAiC,EAAkC,+BAA+B,EAAE,KAAK,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAClN,OAAO,KAAK,EAAE,oCAAoC,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAuBjH,qBAAa,YAAY;WACD,WAAW,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,GAC5B,OAAO,CAAC,MAAM,EAAE,CAAC;WAyBA,KAAK,CACrB,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC;IA4C/B,OAAO,CAAC,IAAI,CAAM;IAClB,IAAW,GAAG,QAAwB;IAEtC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,OAAO,CAAwB;IAEvC,OAAO,CAAC,OAAO,CAAyB;IACxC,IAAW,MAAM,2BAA2B;IAE5C,IAAW,IAAI,oBAAgC;IAE/C,OAAO,CAAC,YAAY,CAAqB;IACzC,IAAW,WAAW,uBAAgC;IAEtD,OAAO,CAAC,aAAa,CAAqB;IAC1C,IAAW,YAAY,uBAAiC;IAExD,OAAO,CAAC,YAAY,CAAoC;IACxD,IAAW,WAAW,sCAAgC;IAEtD,OAAO,CAAC,oBAAoB,CAAsD;IAElF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA8B;IACnE,IAAW,iBAAiB;;;MAA8C;IAE1E,OAAO,CAAC,gBAAgB,CAAK;gBAGzB,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,EAC3B,OAAO,EAAE,qBAAqB,EAC9B,WAAW,EAAE,iBAAiB,EAC9B,aAAa,EAAE,SAAS,GAAG,SAAS;IAmDxC,OAAO,CAAC,kBAAkB;IAQb,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,iCAAiC,EAAE,MAAM,CAAC;IAStE,UAAU,CAAC,IAAI,EAAE,MAAM;IASvB,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,+BAA+B,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,CAAC;IA2BnG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,oCAAoC,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,CAAC;IAgBzG,uBAAuB,CAAC,MAAM,EAAE,qBAAqB;IAYrD,KAAK;CAIrB"}
|
package/esm/client.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { AdbBufferedStream, AdbNoneSubprocessProtocol, DecodeUtf8Stream, InspectStream, TransformStream, WritableStream } from '@yume-chan/adb';
|
|
3
|
+
import { EventEmitter } from '@yume-chan/event';
|
|
4
|
+
import Struct from '@yume-chan/struct';
|
|
5
|
+
import { AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage } from './message.js';
|
|
6
|
+
function* splitLines(text) {
|
|
7
|
+
let start = 0;
|
|
8
|
+
while (true) {
|
|
9
|
+
const index = text.indexOf('\n', start);
|
|
10
|
+
if (index === -1) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const line = text.substring(start, index);
|
|
14
|
+
yield line;
|
|
15
|
+
start = index + 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const ClipboardMessage = new Struct()
|
|
19
|
+
.uint32('length')
|
|
20
|
+
.string('content', { lengthField: 'length' });
|
|
21
|
+
export class ScrcpyClient {
|
|
22
|
+
constructor(adb, options, process, videoStream, controlStream) {
|
|
23
|
+
this.clipboardChangeEvent = new EventEmitter();
|
|
24
|
+
this.lastTouchMessage = 0;
|
|
25
|
+
this._adb = adb;
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.process = process;
|
|
28
|
+
this._stdout = process.stdout
|
|
29
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
30
|
+
.pipeThrough(new TransformStream({
|
|
31
|
+
transform(chunk, controller) {
|
|
32
|
+
for (const line of splitLines(chunk)) {
|
|
33
|
+
if (line === '') {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
controller.enqueue(line);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
}));
|
|
40
|
+
this._videoStream = options
|
|
41
|
+
.parseVideoStream(videoStream)
|
|
42
|
+
.pipeThrough(new InspectStream(packet => {
|
|
43
|
+
if (packet.type === 'configuration') {
|
|
44
|
+
this._screenWidth = packet.data.croppedWidth;
|
|
45
|
+
this._screenHeight = packet.data.croppedHeight;
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
if (controlStream) {
|
|
49
|
+
const buffered = new AdbBufferedStream(controlStream);
|
|
50
|
+
this._controlStreamWriter = controlStream.writable.getWriter();
|
|
51
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
try {
|
|
53
|
+
while (true) {
|
|
54
|
+
const type = yield buffered.read(1);
|
|
55
|
+
switch (type[0]) {
|
|
56
|
+
case 0:
|
|
57
|
+
const { content } = yield ClipboardMessage.deserialize(buffered);
|
|
58
|
+
this.clipboardChangeEvent.fire(content);
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
throw new Error('unknown control message type');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
// TODO: Scrcpy: handle error
|
|
67
|
+
}
|
|
68
|
+
}))();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
static getEncoders(adb, path, version, options) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
// Provide an invalid encoder name
|
|
74
|
+
// So the server will return all available encoders
|
|
75
|
+
options.value.encoderName = '_';
|
|
76
|
+
// Disable control for faster connection in 1.22+
|
|
77
|
+
options.value.control = false;
|
|
78
|
+
// Scrcpy server will open connections, before initializing encoder
|
|
79
|
+
// Thus although an invalid encoder name is given, the start process will success
|
|
80
|
+
const client = yield ScrcpyClient.start(adb, path, version, options);
|
|
81
|
+
const encoderNameRegex = options.getOutputEncoderNameRegex();
|
|
82
|
+
const encoders = [];
|
|
83
|
+
yield client.stdout.pipeTo(new WritableStream({
|
|
84
|
+
write(line) {
|
|
85
|
+
const match = line.match(encoderNameRegex);
|
|
86
|
+
if (match) {
|
|
87
|
+
encoders.push(match[1]);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
}));
|
|
91
|
+
return encoders;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
static start(adb, path, version, options) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const connection = options.createConnection(adb);
|
|
97
|
+
let process;
|
|
98
|
+
try {
|
|
99
|
+
yield connection.initialize();
|
|
100
|
+
process = yield adb.subprocess.spawn([
|
|
101
|
+
// cspell: disable-next-line
|
|
102
|
+
`CLASSPATH=${path}`,
|
|
103
|
+
'app_process',
|
|
104
|
+
/* unused */ '/',
|
|
105
|
+
'com.genymobile.scrcpy.Server',
|
|
106
|
+
version,
|
|
107
|
+
...options.formatServerArguments(),
|
|
108
|
+
], {
|
|
109
|
+
// Scrcpy server doesn't split stdout and stderr,
|
|
110
|
+
// so disable Shell Protocol to simplify processing
|
|
111
|
+
protocols: [AdbNoneSubprocessProtocol],
|
|
112
|
+
});
|
|
113
|
+
const result = yield Promise.race([
|
|
114
|
+
process.exit,
|
|
115
|
+
connection.getStreams(),
|
|
116
|
+
]);
|
|
117
|
+
if (typeof result === 'number') {
|
|
118
|
+
throw new Error('scrcpy server exited prematurely');
|
|
119
|
+
}
|
|
120
|
+
const [videoStream, controlStream] = result;
|
|
121
|
+
return new ScrcpyClient(adb, options, process, videoStream, controlStream);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
yield (process === null || process === void 0 ? void 0 : process.kill());
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
connection.dispose();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
get adb() { return this._adb; }
|
|
133
|
+
get stdout() { return this._stdout; }
|
|
134
|
+
get exit() { return this.process.exit; }
|
|
135
|
+
get screenWidth() { return this._screenWidth; }
|
|
136
|
+
get screenHeight() { return this._screenHeight; }
|
|
137
|
+
get videoStream() { return this._videoStream; }
|
|
138
|
+
get onClipboardChange() { return this.clipboardChangeEvent.event; }
|
|
139
|
+
checkControlStream(caller) {
|
|
140
|
+
if (!this._controlStreamWriter) {
|
|
141
|
+
throw new Error(`${caller} called with control disabled`);
|
|
142
|
+
}
|
|
143
|
+
return this._controlStreamWriter;
|
|
144
|
+
}
|
|
145
|
+
injectKeyCode(message) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const controlStream = this.checkControlStream('injectKeyCode');
|
|
148
|
+
yield controlStream.write(ScrcpyInjectKeyCodeControlMessage.serialize(Object.assign(Object.assign({}, message), { type: ScrcpyControlMessageType.InjectKeycode })));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
injectText(text) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const controlStream = this.checkControlStream('injectText');
|
|
154
|
+
yield controlStream.write(ScrcpyInjectTextControlMessage.serialize({
|
|
155
|
+
type: ScrcpyControlMessageType.InjectText,
|
|
156
|
+
text,
|
|
157
|
+
}));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
injectTouch(message) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
const controlStream = this.checkControlStream('injectTouch');
|
|
163
|
+
if (!this.screenWidth || !this.screenHeight) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// ADB streams are actually pretty low-bandwidth and laggy
|
|
167
|
+
// Re-sample move events to avoid flooding the connection
|
|
168
|
+
// TODO: Scrcpy: investigate how to throttle touch events
|
|
169
|
+
// because 60FPS may still be too high
|
|
170
|
+
const now = Date.now();
|
|
171
|
+
if (now - this.lastTouchMessage < 16 &&
|
|
172
|
+
[AndroidMotionEventAction.Move, AndroidMotionEventAction.HoverMove].includes(message.action)) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.lastTouchMessage = now;
|
|
176
|
+
yield controlStream.write(ScrcpyInjectTouchControlMessage.serialize(Object.assign(Object.assign({}, message), { type: ScrcpyControlMessageType.InjectTouch, screenWidth: this.screenWidth, screenHeight: this.screenHeight })));
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
injectScroll(message) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const controlStream = this.checkControlStream('injectScroll');
|
|
182
|
+
if (!this.screenWidth || !this.screenHeight) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const buffer = this.options.serializeInjectScrollControlMessage(Object.assign(Object.assign({}, message), { type: ScrcpyControlMessageType.InjectScroll, screenWidth: this.screenWidth, screenHeight: this.screenHeight }));
|
|
186
|
+
yield controlStream.write(buffer);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
pressBackOrTurnOnScreen(action) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const controlStream = this.checkControlStream('pressBackOrTurnOnScreen');
|
|
192
|
+
const buffer = this.options.serializeBackOrScreenOnControlMessage({
|
|
193
|
+
type: ScrcpyControlMessageType.BackOrScreenOn,
|
|
194
|
+
action,
|
|
195
|
+
});
|
|
196
|
+
if (buffer) {
|
|
197
|
+
yield controlStream.write(buffer);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
close() {
|
|
202
|
+
var _a;
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
// No need to close streams. Kill the process will destroy them from the other side.
|
|
205
|
+
yield ((_a = this.process) === null || _a === void 0 ? void 0 : _a.kill());
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAA+G,MAAM,gBAAgB,CAAC;AAC7P,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,iCAAiC,EAAE,8BAA8B,EAAE,+BAA+B,EAA8B,MAAM,cAAc,CAAC;AAGlN,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAY;IAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,OAAO,IAAI,EAAE;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACxC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACd,OAAO;SACV;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAA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EAC3C,WAAW,EAAE,IAAI,CAAC,WAAW,EAC7B,YAAY,EAAE,IAAI,CAAC,YAAY,IACjC,CAAC;YACH,MAAM,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;KAAA;IAEY,uBAAuB,CAAC,MAA6B;;YAC9D,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;YAEzE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAQ,CAAC,qCAAqC,CAAC;gBAC/D,IAAI,EAAE,wBAAwB,CAAC,cAAc;gBAC7C,MAAM;aACT,CAAC,CAAC;YACH,IAAI,MAAM,EAAE;gBACR,MAAM,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;aACrC;QACL,CAAC;KAAA;IAEY,KAAK;;;YACd,oFAAoF;YACpF,MAAM,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,IAAI,EAAE,CAAA,CAAC;;KAC9B;CACJ"}
|
package/esm/codec.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare enum AndroidCodecProfile {
|
|
2
|
+
Baseline = 1,
|
|
3
|
+
Main = 2,
|
|
4
|
+
Extended = 4,
|
|
5
|
+
High = 8,
|
|
6
|
+
High10 = 16,
|
|
7
|
+
High422 = 32,
|
|
8
|
+
High444 = 64,
|
|
9
|
+
ConstrainedBaseline = 65536,
|
|
10
|
+
ConstrainedHigh = 524288
|
|
11
|
+
}
|
|
12
|
+
export declare enum AndroidCodecLevel {
|
|
13
|
+
Level1 = 1,
|
|
14
|
+
Level1b = 2,
|
|
15
|
+
Level11 = 4,
|
|
16
|
+
Level12 = 8,
|
|
17
|
+
Level13 = 16,
|
|
18
|
+
Level2 = 32,
|
|
19
|
+
Level21 = 64,
|
|
20
|
+
Level22 = 128,
|
|
21
|
+
Level3 = 256,
|
|
22
|
+
Level31 = 512,
|
|
23
|
+
Level32 = 1024,
|
|
24
|
+
Level4 = 2048,
|
|
25
|
+
Level41 = 4096,
|
|
26
|
+
Level42 = 8192,
|
|
27
|
+
Level5 = 16384,
|
|
28
|
+
Level51 = 32768,
|
|
29
|
+
Level52 = 65536,
|
|
30
|
+
Level6 = 131072,
|
|
31
|
+
Level61 = 262144,
|
|
32
|
+
Level62 = 524288
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AACA,oBAAY,mBAAmB;IAC3B,QAAQ,IAAO;IACf,IAAI,IAAO;IACX,QAAQ,IAAO;IACf,IAAI,IAAO;IACX,MAAM,KAAO;IACb,OAAO,KAAO;IACd,OAAO,KAAO;IACd,mBAAmB,QAAU;IAC7B,eAAe,SAAU;CAC5B;AAED,oBAAY,iBAAiB;IACzB,MAAM,IAAO;IACb,OAAO,IAAO;IACd,OAAO,IAAO;IACd,OAAO,IAAO;IACd,OAAO,KAAO;IACd,MAAM,KAAO;IACb,OAAO,KAAO;IACd,OAAO,MAAO;IACd,MAAM,MAAQ;IACd,OAAO,MAAQ;IACf,OAAO,OAAQ;IACf,MAAM,OAAQ;IACd,OAAO,OAAS;IAChB,OAAO,OAAS;IAChB,MAAM,QAAS;IACf,OAAO,QAAS;IAChB,OAAO,QAAU;IACjB,MAAM,SAAU;IAChB,OAAO,SAAU;IACjB,OAAO,SAAU;CACpB"}
|
package/esm/codec.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// From https://developer.android.com/reference/android/media/MediaCodecInfo.CodecProfileLevel
|
|
2
|
+
export var AndroidCodecProfile;
|
|
3
|
+
(function (AndroidCodecProfile) {
|
|
4
|
+
AndroidCodecProfile[AndroidCodecProfile["Baseline"] = 1] = "Baseline";
|
|
5
|
+
AndroidCodecProfile[AndroidCodecProfile["Main"] = 2] = "Main";
|
|
6
|
+
AndroidCodecProfile[AndroidCodecProfile["Extended"] = 4] = "Extended";
|
|
7
|
+
AndroidCodecProfile[AndroidCodecProfile["High"] = 8] = "High";
|
|
8
|
+
AndroidCodecProfile[AndroidCodecProfile["High10"] = 16] = "High10";
|
|
9
|
+
AndroidCodecProfile[AndroidCodecProfile["High422"] = 32] = "High422";
|
|
10
|
+
AndroidCodecProfile[AndroidCodecProfile["High444"] = 64] = "High444";
|
|
11
|
+
AndroidCodecProfile[AndroidCodecProfile["ConstrainedBaseline"] = 65536] = "ConstrainedBaseline";
|
|
12
|
+
AndroidCodecProfile[AndroidCodecProfile["ConstrainedHigh"] = 524288] = "ConstrainedHigh";
|
|
13
|
+
})(AndroidCodecProfile || (AndroidCodecProfile = {}));
|
|
14
|
+
export var AndroidCodecLevel;
|
|
15
|
+
(function (AndroidCodecLevel) {
|
|
16
|
+
AndroidCodecLevel[AndroidCodecLevel["Level1"] = 1] = "Level1";
|
|
17
|
+
AndroidCodecLevel[AndroidCodecLevel["Level1b"] = 2] = "Level1b";
|
|
18
|
+
AndroidCodecLevel[AndroidCodecLevel["Level11"] = 4] = "Level11";
|
|
19
|
+
AndroidCodecLevel[AndroidCodecLevel["Level12"] = 8] = "Level12";
|
|
20
|
+
AndroidCodecLevel[AndroidCodecLevel["Level13"] = 16] = "Level13";
|
|
21
|
+
AndroidCodecLevel[AndroidCodecLevel["Level2"] = 32] = "Level2";
|
|
22
|
+
AndroidCodecLevel[AndroidCodecLevel["Level21"] = 64] = "Level21";
|
|
23
|
+
AndroidCodecLevel[AndroidCodecLevel["Level22"] = 128] = "Level22";
|
|
24
|
+
AndroidCodecLevel[AndroidCodecLevel["Level3"] = 256] = "Level3";
|
|
25
|
+
AndroidCodecLevel[AndroidCodecLevel["Level31"] = 512] = "Level31";
|
|
26
|
+
AndroidCodecLevel[AndroidCodecLevel["Level32"] = 1024] = "Level32";
|
|
27
|
+
AndroidCodecLevel[AndroidCodecLevel["Level4"] = 2048] = "Level4";
|
|
28
|
+
AndroidCodecLevel[AndroidCodecLevel["Level41"] = 4096] = "Level41";
|
|
29
|
+
AndroidCodecLevel[AndroidCodecLevel["Level42"] = 8192] = "Level42";
|
|
30
|
+
AndroidCodecLevel[AndroidCodecLevel["Level5"] = 16384] = "Level5";
|
|
31
|
+
AndroidCodecLevel[AndroidCodecLevel["Level51"] = 32768] = "Level51";
|
|
32
|
+
AndroidCodecLevel[AndroidCodecLevel["Level52"] = 65536] = "Level52";
|
|
33
|
+
AndroidCodecLevel[AndroidCodecLevel["Level6"] = 131072] = "Level6";
|
|
34
|
+
AndroidCodecLevel[AndroidCodecLevel["Level61"] = 262144] = "Level61";
|
|
35
|
+
AndroidCodecLevel[AndroidCodecLevel["Level62"] = 524288] = "Level62";
|
|
36
|
+
})(AndroidCodecLevel || (AndroidCodecLevel = {}));
|
|
37
|
+
//# sourceMappingURL=codec.js.map
|
package/esm/codec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,CAAN,IAAY,mBAUX;AAVD,WAAY,mBAAmB;IAC3B,qEAAe,CAAA;IACf,6DAAW,CAAA;IACX,qEAAe,CAAA;IACf,6DAAW,CAAA;IACX,kEAAa,CAAA;IACb,oEAAc,CAAA;IACd,oEAAc,CAAA;IACd,+FAA6B,CAAA;IAC7B,wFAAyB,CAAA;AAC7B,CAAC,EAVW,mBAAmB,KAAnB,mBAAmB,QAU9B;AAED,MAAM,CAAN,IAAY,iBAqBX;AArBD,WAAY,iBAAiB;IACzB,6DAAa,CAAA;IACb,+DAAc,CAAA;IACd,+DAAc,CAAA;IACd,+DAAc,CAAA;IACd,gEAAc,CAAA;IACd,8DAAa,CAAA;IACb,gEAAc,CAAA;IACd,iEAAc,CAAA;IACd,+DAAc,CAAA;IACd,iEAAe,CAAA;IACf,kEAAe,CAAA;IACf,gEAAc,CAAA;IACd,kEAAgB,CAAA;IAChB,kEAAgB,CAAA;IAChB,iEAAe,CAAA;IACf,mEAAgB,CAAA;IAChB,mEAAiB,CAAA;IACjB,kEAAgB,CAAA;IAChB,oEAAiB,CAAA;IACjB,oEAAiB,CAAA;AACrB,CAAC,EArBW,iBAAiB,KAAjB,iBAAiB,QAqB5B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Adb, AdbBufferedStream, AdbSocket } from "@yume-chan/adb";
|
|
2
|
+
import type { Disposable } from "@yume-chan/event";
|
|
3
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
4
|
+
export interface ScrcpyClientConnectionOptions {
|
|
5
|
+
control: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Write a byte on start to detect connection issues
|
|
8
|
+
*/
|
|
9
|
+
sendDummyByte: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Send device name and size
|
|
12
|
+
*/
|
|
13
|
+
sendDeviceMeta: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class ScrcpyClientConnection implements Disposable {
|
|
16
|
+
protected device: Adb;
|
|
17
|
+
protected options: ScrcpyClientConnectionOptions;
|
|
18
|
+
constructor(device: Adb, options: ScrcpyClientConnectionOptions);
|
|
19
|
+
initialize(): ValueOrPromise<void>;
|
|
20
|
+
abstract getStreams(): ValueOrPromise<[videoSteam: AdbBufferedStream, controlStream: AdbSocket | undefined]>;
|
|
21
|
+
dispose(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class ScrcpyClientForwardConnection extends ScrcpyClientConnection {
|
|
24
|
+
private connect;
|
|
25
|
+
private connectAndRetry;
|
|
26
|
+
private connectVideoStream;
|
|
27
|
+
getStreams(): Promise<[videoSteam: AdbBufferedStream, controlStream: AdbSocket | undefined]>;
|
|
28
|
+
}
|
|
29
|
+
export declare class ScrcpyClientReverseConnection extends ScrcpyClientConnection {
|
|
30
|
+
private streams;
|
|
31
|
+
private address;
|
|
32
|
+
initialize(): Promise<void>;
|
|
33
|
+
private accept;
|
|
34
|
+
getStreams(): Promise<[videoSteam: AdbBufferedStream, controlStream: AdbSocket | undefined]>;
|
|
35
|
+
dispose(): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,MAAM,WAAW,6BAA6B;IAC1C,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;CAC3B;AAED,8BAAsB,sBAAuB,YAAW,UAAU;IAC9D,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC;IAEtB,SAAS,CAAC,OAAO,EAAE,6BAA6B,CAAC;gBAE9B,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,6BAA6B;IAK/D,UAAU,IAAI,cAAc,CAAC,IAAI,CAAC;aAEzB,UAAU,IAAI,cAAc,CAAC,CAAC,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IAE5G,OAAO,IAAI,IAAI;CACzB;AAED,qBAAa,6BAA8B,SAAQ,sBAAsB;YACvD,OAAO;YAIP,eAAe;YAWf,kBAAkB;IAUnB,UAAU,IAAI,OAAO,CAAC,CAAC,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;CAY5G;AAED,qBAAa,6BAA8B,SAAQ,sBAAsB;IACrE,OAAO,CAAC,OAAO,CAA0C;IAEzD,OAAO,CAAC,OAAO,CAAU;IAEH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAkBnC,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