@yume-chan/scrcpy 0.0.18 → 0.0.19
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 +18 -0
- package/CHANGELOG.md +10 -1
- package/README.md +111 -61
- package/bin/scrcpy-server +0 -0
- package/bin/version.d.ts +1 -1
- package/bin/version.js +1 -1
- package/esm/adb/client.d.ts +40 -40
- package/esm/adb/client.d.ts.map +1 -1
- package/esm/adb/client.js +223 -242
- package/esm/adb/client.js.map +1 -1
- package/esm/adb/connection.d.ts +48 -46
- package/esm/adb/connection.d.ts.map +1 -1
- package/esm/adb/connection.js +121 -109
- package/esm/adb/connection.js.map +1 -1
- package/esm/adb/index.d.ts +3 -3
- package/esm/adb/index.js +3 -3
- package/esm/adb/options/1_16.d.ts +7 -7
- package/esm/adb/options/1_16.d.ts.map +1 -1
- package/esm/adb/options/1_16.js +19 -19
- package/esm/adb/options/1_16.js.map +1 -1
- package/esm/adb/options/1_22.d.ts +7 -7
- package/esm/adb/options/1_22.d.ts.map +1 -1
- package/esm/adb/options/1_22.js +16 -16
- package/esm/adb/options/1_22.js.map +1 -1
- package/esm/adb/options/1_26.d.ts +9 -0
- package/esm/adb/options/1_26.d.ts.map +1 -0
- package/esm/adb/options/1_26.js +11 -0
- package/esm/adb/options/1_26.js.map +1 -0
- package/esm/adb/options/2_0.d.ts +8 -0
- package/esm/adb/options/2_0.d.ts.map +1 -0
- package/esm/adb/options/2_0.js +13 -0
- package/esm/adb/options/2_0.js.map +1 -0
- package/esm/adb/options/index.d.ts +3 -3
- package/esm/adb/options/index.js +3 -3
- package/esm/adb/options/types.d.ts +23 -23
- package/esm/adb/options/types.d.ts.map +1 -1
- package/esm/adb/options/types.js +36 -36
- package/esm/codec/av1.d.ts +33 -0
- package/esm/codec/av1.d.ts.map +1 -0
- package/esm/codec/av1.js +35 -0
- package/esm/codec/av1.js.map +1 -0
- package/esm/codec/h264.d.ts +98 -0
- package/esm/codec/h264.d.ts.map +1 -0
- package/esm/codec/h264.js +477 -0
- package/esm/codec/h264.js.map +1 -0
- package/esm/codec/h265.d.ts +36 -0
- package/esm/codec/h265.d.ts.map +1 -0
- package/esm/codec/h265.js +38 -0
- package/esm/codec/h265.js.map +1 -0
- package/esm/codec/index.d.ts +4 -0
- package/esm/codec/index.d.ts.map +1 -0
- package/esm/codec/index.js +4 -0
- package/esm/codec/index.js.map +1 -0
- package/esm/codec.d.ts +33 -33
- package/esm/codec.js +36 -36
- package/esm/control/back-or-screen-on.d.ts +2 -2
- package/esm/control/back-or-screen-on.d.ts.map +1 -1
- package/esm/control/back-or-screen-on.js +1 -1
- package/esm/control/basic.d.ts +5 -0
- package/esm/control/basic.d.ts.map +1 -0
- package/esm/control/basic.js +3 -0
- package/esm/control/basic.js.map +1 -0
- package/esm/control/hover-helper.d.ts +17 -17
- package/esm/control/hover-helper.d.ts.map +1 -1
- package/esm/control/hover-helper.js +43 -43
- package/esm/control/hover-helper.js.map +1 -1
- package/esm/control/index.d.ts +11 -11
- package/esm/control/index.js +11 -11
- package/esm/control/inject-keycode.d.ts +194 -60
- package/esm/control/inject-keycode.d.ts.map +1 -1
- package/esm/control/inject-keycode.js +199 -61
- package/esm/control/inject-keycode.js.map +1 -1
- package/esm/control/inject-scroll.d.ts +2 -2
- package/esm/control/inject-scroll.d.ts.map +1 -1
- package/esm/control/inject-scroll.js +1 -1
- package/esm/control/inject-text.d.ts +8 -8
- package/esm/control/inject-text.d.ts.map +1 -1
- package/esm/control/inject-text.js +6 -6
- package/esm/control/inject-text.js.map +1 -1
- package/esm/control/inject-touch.d.ts +37 -37
- package/esm/control/inject-touch.d.ts.map +1 -1
- package/esm/control/inject-touch.js +62 -62
- package/esm/control/rotate-device.d.ts +6 -6
- package/esm/control/rotate-device.d.ts.map +1 -1
- package/esm/control/rotate-device.js +3 -4
- package/esm/control/rotate-device.js.map +1 -1
- package/esm/control/serializer.d.ts +35 -33
- package/esm/control/serializer.d.ts.map +1 -1
- package/esm/control/serializer.js +82 -78
- package/esm/control/serializer.js.map +1 -1
- package/esm/control/set-clipboard.d.ts +2 -2
- package/esm/control/set-clipboard.d.ts.map +1 -1
- package/esm/control/set-clipboard.js +1 -1
- package/esm/control/set-screen-power-mode.d.ts +11 -11
- package/esm/control/set-screen-power-mode.d.ts.map +1 -1
- package/esm/control/set-screen-power-mode.js +11 -11
- package/esm/control/set-screen-power-mode.js.map +1 -1
- package/esm/control/simple.d.ts +5 -0
- package/esm/control/simple.d.ts.map +1 -0
- package/esm/control/simple.js +3 -0
- package/esm/control/simple.js.map +1 -0
- package/esm/control/type.d.ts +14 -14
- package/esm/control/type.js +18 -18
- package/esm/decoder.d.ts +2 -0
- package/esm/decoder.d.ts.map +1 -0
- package/esm/decoder.js +2 -0
- package/esm/decoder.js.map +1 -0
- package/esm/device-message/ack-clipboard.d.ts +8 -8
- package/esm/device-message/ack-clipboard.d.ts.map +1 -1
- package/esm/device-message/ack-clipboard.js +5 -5
- package/esm/device-message/clipboard.d.ts +9 -9
- package/esm/device-message/clipboard.d.ts.map +1 -1
- package/esm/device-message/clipboard.js +6 -6
- package/esm/device-message/index.d.ts +4 -4
- package/esm/device-message/index.js +4 -4
- package/esm/device-message/stream.d.ts +7 -7
- package/esm/device-message/stream.js +19 -19
- package/esm/device-message/type.d.ts +4 -4
- package/esm/device-message/type.js +6 -6
- package/esm/index.d.ts +5 -5
- package/esm/index.js +5 -5
- package/esm/options/1.17.d.ts +3 -0
- package/esm/options/1.17.d.ts.map +1 -0
- package/esm/options/1.17.js +2 -0
- package/esm/options/1.17.js.map +1 -0
- package/esm/options/1_16/codec-options.d.ts +20 -19
- package/esm/options/1_16/codec-options.d.ts.map +1 -1
- package/esm/options/1_16/codec-options.js +25 -25
- package/esm/options/1_16/codec-options.js.map +1 -1
- package/esm/options/1_16/float-to-uint16.d.ts +5 -0
- package/esm/options/1_16/float-to-uint16.d.ts.map +1 -0
- package/esm/options/1_16/float-to-uint16.js +27 -0
- package/esm/options/1_16/float-to-uint16.js.map +1 -0
- package/esm/options/1_16/h264-configuration.d.ts +48 -48
- package/esm/options/1_16/h264-configuration.js +413 -413
- package/esm/options/1_16/index.d.ts +4 -4
- package/esm/options/1_16/index.js +4 -4
- package/esm/options/1_16/init.d.ts +66 -0
- package/esm/options/1_16/init.d.ts.map +1 -0
- package/esm/options/1_16/init.js +16 -0
- package/esm/options/1_16/init.js.map +1 -0
- package/esm/options/1_16/message.d.ts +32 -0
- package/esm/options/1_16/message.d.ts.map +1 -0
- package/esm/options/1_16/message.js +37 -0
- package/esm/options/1_16/message.js.map +1 -0
- package/esm/options/1_16/options.d.ts +102 -93
- package/esm/options/1_16/options.d.ts.map +1 -1
- package/esm/options/1_16/options.js +189 -189
- package/esm/options/1_16/options.js.map +1 -1
- package/esm/options/1_16/scroll.d.ts +27 -26
- package/esm/options/1_16/scroll.d.ts.map +1 -1
- package/esm/options/1_16/scroll.js +55 -55
- package/esm/options/1_16/scroll.js.map +1 -1
- package/esm/options/1_17.d.ts +32 -0
- package/esm/options/1_17.d.ts.map +1 -0
- package/esm/options/1_17.js +36 -0
- package/esm/options/1_17.js.map +1 -0
- package/esm/options/1_18.d.ts +21 -19
- package/esm/options/1_18.d.ts.map +1 -1
- package/esm/options/1_18.js +45 -45
- package/esm/options/1_18.js.map +1 -1
- package/esm/options/1_21.d.ts +22 -20
- package/esm/options/1_21.d.ts.map +1 -1
- package/esm/options/1_21.js +36 -36
- package/esm/options/1_21.js.map +1 -1
- package/esm/options/1_22/index.d.ts +2 -2
- package/esm/options/1_22/index.js +2 -2
- package/esm/options/1_22/init.d.ts +17 -0
- package/esm/options/1_22/init.d.ts.map +1 -0
- package/esm/options/1_22/init.js +2 -0
- package/esm/options/1_22/init.js.map +1 -0
- package/esm/options/1_22/options.d.ts +29 -28
- package/esm/options/1_22/options.d.ts.map +1 -1
- package/esm/options/1_22/options.js +25 -25
- package/esm/options/1_22/options.js.map +1 -1
- package/esm/options/1_22/scroll.d.ts +16 -16
- package/esm/options/1_22/scroll.d.ts.map +1 -1
- package/esm/options/1_22/scroll.js +14 -14
- package/esm/options/1_23.d.ts +12 -11
- package/esm/options/1_23.d.ts.map +1 -1
- package/esm/options/1_23.js +34 -34
- package/esm/options/1_23.js.map +1 -1
- package/esm/options/1_24.d.ts +9 -8
- package/esm/options/1_24.d.ts.map +1 -1
- package/esm/options/1_24.js +12 -12
- package/esm/options/1_24.js.map +1 -1
- package/esm/options/1_25/index.d.ts +2 -2
- package/esm/options/1_25/index.js +2 -2
- package/esm/options/1_25/options.d.ts +6 -5
- package/esm/options/1_25/options.d.ts.map +1 -1
- package/esm/options/1_25/options.js +7 -7
- package/esm/options/1_25/options.js.map +1 -1
- package/esm/options/1_25/scroll.d.ts +19 -18
- package/esm/options/1_25/scroll.d.ts.map +1 -1
- package/esm/options/1_25/scroll.js +32 -32
- package/esm/options/1_25/scroll.js.map +1 -1
- package/esm/options/1_26.d.ts +57 -0
- package/esm/options/1_26.d.ts.map +1 -0
- package/esm/options/1_26.js +67 -0
- package/esm/options/1_26.js.map +1 -0
- package/esm/options/2.d.ts +57 -0
- package/esm/options/2.d.ts.map +1 -0
- package/esm/options/2.js +67 -0
- package/esm/options/2.js.map +1 -0
- package/esm/options/2_0.d.ts +87 -0
- package/esm/options/2_0.d.ts.map +1 -0
- package/esm/options/2_0.js +175 -0
- package/esm/options/2_0.js.map +1 -0
- package/esm/options/codec.d.ts +52 -0
- package/esm/options/codec.d.ts.map +1 -0
- package/esm/options/codec.js +26 -0
- package/esm/options/codec.js.map +1 -0
- package/esm/options/index.d.ts +8 -8
- package/esm/options/index.js +8 -8
- package/esm/options/latest.d.ts +12 -0
- package/esm/options/latest.d.ts.map +1 -0
- package/esm/options/latest.js +8 -0
- package/esm/options/latest.js.map +1 -0
- package/esm/options/types.d.ts +46 -46
- package/esm/options/types.d.ts.map +1 -1
- package/esm/options/types.js +17 -17
- package/package.json +11 -10
- package/src/adb/client.ts +72 -88
- package/src/adb/connection.ts +42 -25
- package/src/adb/index.ts +3 -3
- package/src/adb/options/1_16.ts +6 -4
- package/src/adb/options/1_22.ts +3 -3
- package/src/adb/options/index.ts +3 -3
- package/src/adb/options/types.ts +10 -10
- package/src/control/back-or-screen-on.ts +1 -1
- package/src/control/hover-helper.ts +2 -4
- package/src/control/inject-keycode.ts +193 -48
- package/src/control/inject-scroll.ts +1 -1
- package/src/control/inject-text.ts +7 -8
- package/src/control/inject-touch.ts +1 -1
- package/src/control/rotate-device.ts +7 -6
- package/src/control/serializer.ts +29 -26
- package/src/control/set-clipboard.ts +1 -1
- package/src/control/set-screen-power-mode.ts +7 -8
- package/src/device-message/ack-clipboard.ts +1 -1
- package/src/device-message/clipboard.ts +1 -1
- package/src/index.ts +5 -5
- package/src/options/1_16/codec-options.ts +4 -6
- package/src/options/1_16/options.ts +17 -12
- package/src/options/1_16/scroll.ts +2 -4
- package/src/options/1_18.ts +6 -6
- package/src/options/1_21.ts +5 -6
- package/src/options/1_22/options.ts +3 -2
- package/src/options/1_22/scroll.ts +1 -1
- package/src/options/1_23.ts +3 -5
- package/src/options/1_24.ts +5 -3
- package/src/options/1_25/options.ts +3 -2
- package/src/options/1_25/scroll.ts +4 -7
- package/src/options/index.ts +3 -3
- package/src/options/types.ts +8 -8
- package/tsconfig.build.tsbuildinfo +1 -1
package/src/adb/client.ts
CHANGED
|
@@ -1,88 +1,54 @@
|
|
|
1
|
+
import type { Adb, AdbSubprocessProtocol } from "@yume-chan/adb";
|
|
1
2
|
import {
|
|
3
|
+
AdbReverseNotSupportedError,
|
|
2
4
|
AdbSubprocessNoneProtocol,
|
|
3
|
-
type Adb,
|
|
4
|
-
type AdbSubprocessProtocol,
|
|
5
|
-
type AdbSync,
|
|
6
5
|
} from "@yume-chan/adb";
|
|
6
|
+
import type {
|
|
7
|
+
Consumable,
|
|
8
|
+
ReadableStream,
|
|
9
|
+
ReadableWritablePair,
|
|
10
|
+
} from "@yume-chan/stream-extra";
|
|
7
11
|
import {
|
|
8
12
|
AbortController,
|
|
9
13
|
DecodeUtf8Stream,
|
|
10
14
|
InspectStream,
|
|
11
|
-
|
|
15
|
+
PushReadableStream,
|
|
12
16
|
SplitStringStream,
|
|
13
|
-
WrapWritableStream,
|
|
14
17
|
WritableStream,
|
|
15
|
-
type ReadableStreamDefaultController,
|
|
16
|
-
type ReadableStreamDefaultReader,
|
|
17
|
-
type ReadableWritablePair,
|
|
18
18
|
} from "@yume-chan/stream-extra";
|
|
19
19
|
|
|
20
20
|
import { ScrcpyControlMessageSerializer } from "../control/index.js";
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
DEFAULT_SERVER_PATH,
|
|
27
|
-
type ScrcpyVideoStreamPacket,
|
|
21
|
+
import type { ScrcpyDeviceMessage } from "../device-message/index.js";
|
|
22
|
+
import { ScrcpyDeviceMessageDeserializeStream } from "../device-message/index.js";
|
|
23
|
+
import type {
|
|
24
|
+
ScrcpyOptionsInit1_16,
|
|
25
|
+
ScrcpyVideoStreamPacket,
|
|
28
26
|
} from "../options/index.js";
|
|
27
|
+
import { DEFAULT_SERVER_PATH } from "../options/index.js";
|
|
29
28
|
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
class ArrayToStream<T> extends ReadableStream<T> {
|
|
33
|
-
private array!: T[];
|
|
34
|
-
private index = 0;
|
|
35
|
-
|
|
36
|
-
constructor(array: T[]) {
|
|
37
|
-
super({
|
|
38
|
-
start: async () => {
|
|
39
|
-
await Promise.resolve();
|
|
40
|
-
this.array = array;
|
|
41
|
-
},
|
|
42
|
-
pull: (controller) => {
|
|
43
|
-
if (this.index < this.array.length) {
|
|
44
|
-
controller.enqueue(this.array[this.index]!);
|
|
45
|
-
this.index += 1;
|
|
46
|
-
} else {
|
|
47
|
-
controller.close();
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
29
|
+
import type { AdbScrcpyConnection } from "./connection.js";
|
|
30
|
+
import type { AdbScrcpyOptions } from "./options/index.js";
|
|
53
31
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
start: async (controller) => {
|
|
62
|
-
await Promise.resolve();
|
|
63
|
-
|
|
64
|
-
this.streams = streams;
|
|
65
|
-
this.advance(controller);
|
|
66
|
-
},
|
|
67
|
-
pull: async (controller) => {
|
|
68
|
-
const result = await this.reader.read();
|
|
69
|
-
if (!result.done) {
|
|
70
|
-
controller.enqueue(result.value);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this.advance(controller);
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
32
|
+
function arrayToStream<T>(array: T[]): ReadableStream<T> {
|
|
33
|
+
return new PushReadableStream(async (controller) => {
|
|
34
|
+
for (const item of array) {
|
|
35
|
+
await controller.enqueue(item);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
77
39
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
40
|
+
function concatStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T> {
|
|
41
|
+
return new PushReadableStream(async (controller) => {
|
|
42
|
+
for (const stream of streams) {
|
|
43
|
+
await stream.pipeTo(
|
|
44
|
+
new WritableStream({
|
|
45
|
+
async write(chunk) {
|
|
46
|
+
await controller.enqueue(chunk);
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
);
|
|
84
50
|
}
|
|
85
|
-
}
|
|
51
|
+
});
|
|
86
52
|
}
|
|
87
53
|
|
|
88
54
|
export class ScrcpyExitedError extends Error {
|
|
@@ -95,30 +61,46 @@ export class ScrcpyExitedError extends Error {
|
|
|
95
61
|
}
|
|
96
62
|
|
|
97
63
|
export class AdbScrcpyClient {
|
|
98
|
-
public static pushServer(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
64
|
+
public static async pushServer(
|
|
65
|
+
adb: Adb,
|
|
66
|
+
file: ReadableStream<Consumable<Uint8Array>>,
|
|
67
|
+
filename = DEFAULT_SERVER_PATH
|
|
68
|
+
) {
|
|
69
|
+
const sync = await adb.sync();
|
|
70
|
+
try {
|
|
71
|
+
await sync.write({
|
|
72
|
+
filename,
|
|
73
|
+
file,
|
|
74
|
+
});
|
|
75
|
+
} finally {
|
|
76
|
+
await sync.dispose();
|
|
77
|
+
}
|
|
109
78
|
}
|
|
110
79
|
|
|
111
80
|
public static async start(
|
|
112
81
|
adb: Adb,
|
|
113
82
|
path: string,
|
|
114
83
|
version: string,
|
|
115
|
-
options: AdbScrcpyOptions<
|
|
84
|
+
options: AdbScrcpyOptions<ScrcpyOptionsInit1_16>
|
|
116
85
|
) {
|
|
117
|
-
|
|
86
|
+
let connection: AdbScrcpyConnection | undefined;
|
|
118
87
|
let process: AdbSubprocessProtocol | undefined;
|
|
119
88
|
|
|
120
89
|
try {
|
|
121
|
-
|
|
90
|
+
try {
|
|
91
|
+
connection = options.createConnection(adb);
|
|
92
|
+
await connection.initialize();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
if (e instanceof AdbReverseNotSupportedError) {
|
|
95
|
+
// When reverse tunnel is not supported, try forward tunnel.
|
|
96
|
+
options.value.tunnelForward = true;
|
|
97
|
+
connection = options.createConnection(adb);
|
|
98
|
+
await connection.initialize();
|
|
99
|
+
} else {
|
|
100
|
+
connection = undefined;
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
122
104
|
|
|
123
105
|
process = await adb.subprocess.spawn(
|
|
124
106
|
[
|
|
@@ -176,7 +158,7 @@ export class AdbScrcpyClient {
|
|
|
176
158
|
return new AdbScrcpyClient(
|
|
177
159
|
options,
|
|
178
160
|
process,
|
|
179
|
-
|
|
161
|
+
concatStreams(arrayToStream(output), stdout),
|
|
180
162
|
videoStream,
|
|
181
163
|
controlStream
|
|
182
164
|
);
|
|
@@ -184,7 +166,7 @@ export class AdbScrcpyClient {
|
|
|
184
166
|
await process?.kill();
|
|
185
167
|
throw e;
|
|
186
168
|
} finally {
|
|
187
|
-
connection
|
|
169
|
+
connection?.dispose();
|
|
188
170
|
}
|
|
189
171
|
}
|
|
190
172
|
|
|
@@ -196,7 +178,7 @@ export class AdbScrcpyClient {
|
|
|
196
178
|
adb: Adb,
|
|
197
179
|
path: string,
|
|
198
180
|
version: string,
|
|
199
|
-
options: AdbScrcpyOptions<
|
|
181
|
+
options: AdbScrcpyOptions<ScrcpyOptionsInit1_16>
|
|
200
182
|
): Promise<string[]> {
|
|
201
183
|
Object.assign(options.value, {
|
|
202
184
|
// Provide an invalid encoder name
|
|
@@ -236,7 +218,7 @@ export class AdbScrcpyClient {
|
|
|
236
218
|
adb: Adb,
|
|
237
219
|
path: string,
|
|
238
220
|
version: string,
|
|
239
|
-
options: AdbScrcpyOptions<
|
|
221
|
+
options: AdbScrcpyOptions<ScrcpyOptionsInit1_16>
|
|
240
222
|
): Promise<number[]> {
|
|
241
223
|
Object.assign(options.value, {
|
|
242
224
|
// Similar to `getEncoders`, pass an invalid option and parse the output
|
|
@@ -308,11 +290,13 @@ export class AdbScrcpyClient {
|
|
|
308
290
|
}
|
|
309
291
|
|
|
310
292
|
public constructor(
|
|
311
|
-
options: AdbScrcpyOptions<
|
|
293
|
+
options: AdbScrcpyOptions<ScrcpyOptionsInit1_16>,
|
|
312
294
|
process: AdbSubprocessProtocol,
|
|
313
295
|
stdout: ReadableStream<string>,
|
|
314
296
|
videoStream: ReadableStream<Uint8Array>,
|
|
315
|
-
controlStream:
|
|
297
|
+
controlStream:
|
|
298
|
+
| ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
299
|
+
| undefined
|
|
316
300
|
) {
|
|
317
301
|
this.process = process;
|
|
318
302
|
this._stdout = stdout;
|
package/src/adb/connection.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Adb } from "@yume-chan/adb";
|
|
2
|
+
import { AdbReverseNotSupportedError } from "@yume-chan/adb";
|
|
2
3
|
import { delay } from "@yume-chan/async";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import type { Disposable } from "@yume-chan/event";
|
|
5
|
+
import type {
|
|
6
|
+
Consumable,
|
|
7
|
+
ReadableStream,
|
|
8
|
+
ReadableStreamDefaultReader,
|
|
9
|
+
ReadableWritablePair,
|
|
9
10
|
} from "@yume-chan/stream-extra";
|
|
10
|
-
import {
|
|
11
|
+
import { TransformStream } from "@yume-chan/stream-extra";
|
|
12
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
11
13
|
|
|
12
14
|
export interface AdbScrcpyConnectionOptions {
|
|
13
15
|
control: boolean;
|
|
@@ -41,7 +43,7 @@ export abstract class AdbScrcpyConnection implements Disposable {
|
|
|
41
43
|
[
|
|
42
44
|
videoSteam: ReadableStream<Uint8Array>,
|
|
43
45
|
controlStream:
|
|
44
|
-
| ReadableWritablePair<Uint8Array, Uint8Array
|
|
46
|
+
| ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
45
47
|
| undefined
|
|
46
48
|
]
|
|
47
49
|
>;
|
|
@@ -52,14 +54,18 @@ export abstract class AdbScrcpyConnection implements Disposable {
|
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
export class AdbScrcpyForwardConnection extends AdbScrcpyConnection {
|
|
55
|
-
private
|
|
57
|
+
private _disposed = false;
|
|
58
|
+
|
|
59
|
+
private connect(): Promise<
|
|
60
|
+
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
61
|
+
> {
|
|
56
62
|
return this.adb.createSocket("localabstract:scrcpy");
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
private async connectAndRetry(): Promise<
|
|
60
|
-
ReadableWritablePair<Uint8Array, Uint8Array
|
|
66
|
+
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
61
67
|
> {
|
|
62
|
-
for (let i = 0; i < 100; i += 1) {
|
|
68
|
+
for (let i = 0; !this._disposed && i < 100; i += 1) {
|
|
63
69
|
try {
|
|
64
70
|
return await this.connect();
|
|
65
71
|
} catch (e) {
|
|
@@ -83,18 +89,18 @@ export class AdbScrcpyForwardConnection extends AdbScrcpyConnection {
|
|
|
83
89
|
return videoStream;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
public async getStreams(): Promise<
|
|
92
|
+
public override async getStreams(): Promise<
|
|
87
93
|
[
|
|
88
94
|
videoSteam: ReadableStream<Uint8Array>,
|
|
89
95
|
controlStream:
|
|
90
|
-
| ReadableWritablePair<Uint8Array, Uint8Array
|
|
96
|
+
| ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
91
97
|
| undefined
|
|
92
98
|
]
|
|
93
99
|
> {
|
|
94
100
|
const videoStream = await this.connectVideoStream();
|
|
95
101
|
|
|
96
102
|
let controlStream:
|
|
97
|
-
| ReadableWritablePair<Uint8Array, Uint8Array
|
|
103
|
+
| ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
98
104
|
| undefined;
|
|
99
105
|
if (this.options.control) {
|
|
100
106
|
controlStream = await this.connectAndRetry();
|
|
@@ -113,24 +119,35 @@ export class AdbScrcpyForwardConnection extends AdbScrcpyConnection {
|
|
|
113
119
|
|
|
114
120
|
return [videoStream, controlStream];
|
|
115
121
|
}
|
|
122
|
+
|
|
123
|
+
public override dispose(): void {
|
|
124
|
+
super.dispose();
|
|
125
|
+
this._disposed = true;
|
|
126
|
+
}
|
|
116
127
|
}
|
|
117
128
|
|
|
118
129
|
export class AdbScrcpyReverseConnection extends AdbScrcpyConnection {
|
|
119
130
|
private streams!: ReadableStreamDefaultReader<
|
|
120
|
-
ReadableWritablePair<Uint8Array, Uint8Array
|
|
131
|
+
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
121
132
|
>;
|
|
122
133
|
|
|
123
134
|
private address!: string;
|
|
124
135
|
|
|
125
136
|
public override async initialize(): Promise<void> {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})
|
|
137
|
+
try {
|
|
138
|
+
// try to unbind first
|
|
139
|
+
await this.adb.reverse.remove("localabstract:scrcpy");
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (e instanceof AdbReverseNotSupportedError) {
|
|
142
|
+
throw e;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Ignore other errors when unbinding
|
|
146
|
+
}
|
|
130
147
|
|
|
131
148
|
const queue = new TransformStream<
|
|
132
|
-
ReadableWritablePair<Uint8Array, Uint8Array
|
|
133
|
-
ReadableWritablePair<Uint8Array, Uint8Array
|
|
149
|
+
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>,
|
|
150
|
+
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
134
151
|
>();
|
|
135
152
|
this.streams = queue.readable.getReader();
|
|
136
153
|
const writer = queue.writable.getWriter();
|
|
@@ -145,7 +162,7 @@ export class AdbScrcpyReverseConnection extends AdbScrcpyConnection {
|
|
|
145
162
|
}
|
|
146
163
|
|
|
147
164
|
private async accept(): Promise<
|
|
148
|
-
ReadableWritablePair<Uint8Array, Uint8Array
|
|
165
|
+
ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
149
166
|
> {
|
|
150
167
|
return (await this.streams.read()).value!;
|
|
151
168
|
}
|
|
@@ -154,14 +171,14 @@ export class AdbScrcpyReverseConnection extends AdbScrcpyConnection {
|
|
|
154
171
|
[
|
|
155
172
|
videoSteam: ReadableStream<Uint8Array>,
|
|
156
173
|
controlStream:
|
|
157
|
-
| ReadableWritablePair<Uint8Array, Uint8Array
|
|
174
|
+
| ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
158
175
|
| undefined
|
|
159
176
|
]
|
|
160
177
|
> {
|
|
161
178
|
const { readable: videoStream } = await this.accept();
|
|
162
179
|
|
|
163
180
|
let controlStream:
|
|
164
|
-
| ReadableWritablePair<Uint8Array, Uint8Array
|
|
181
|
+
| ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>
|
|
165
182
|
| undefined;
|
|
166
183
|
if (this.options.control) {
|
|
167
184
|
controlStream = await this.accept();
|
package/src/adb/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./options/index.js";
|
|
2
|
+
export * from "./client.js";
|
|
3
|
+
export * from "./connection.js";
|
package/src/adb/options/1_16.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Adb } from "@yume-chan/adb";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { ScrcpyOptionsInit1_16 } from "../../options/index.js";
|
|
4
|
+
import type {
|
|
5
|
+
AdbScrcpyConnection,
|
|
6
|
+
AdbScrcpyConnectionOptions,
|
|
7
|
+
} from "../connection.js";
|
|
4
8
|
import {
|
|
5
9
|
AdbScrcpyForwardConnection,
|
|
6
10
|
AdbScrcpyReverseConnection,
|
|
7
|
-
type AdbScrcpyConnection,
|
|
8
|
-
type AdbScrcpyConnectionOptions,
|
|
9
11
|
} from "../connection.js";
|
|
10
12
|
|
|
11
13
|
import { AdbScrcpyOptionsBase } from "./types.js";
|
package/src/adb/options/1_22.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Adb } from "@yume-chan/adb";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { ScrcpyOptionsInit1_22 } from "../../options/index.js";
|
|
4
|
+
import type { AdbScrcpyConnection } from "../connection.js";
|
|
4
5
|
import {
|
|
5
|
-
type AdbScrcpyConnection,
|
|
6
6
|
AdbScrcpyForwardConnection,
|
|
7
7
|
AdbScrcpyReverseConnection,
|
|
8
8
|
} from "../connection.js";
|
package/src/adb/options/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./1_16.js";
|
|
2
|
+
export * from "./1_22.js";
|
|
3
|
+
export * from "./types.js";
|
package/src/adb/options/types.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Adb } from "@yume-chan/adb";
|
|
2
|
+
import type { TransformStream } from "@yume-chan/stream-extra";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import type {
|
|
5
|
+
ScrcpyBackOrScreenOnControlMessage,
|
|
6
|
+
ScrcpyControlMessageType,
|
|
7
|
+
ScrcpySetClipboardControlMessage,
|
|
8
8
|
} from "../../control/index.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import type {
|
|
10
|
+
ScrcpyOptions,
|
|
11
|
+
ScrcpyVideoStreamPacket,
|
|
12
12
|
} from "../../options/index.js";
|
|
13
|
-
import {
|
|
13
|
+
import type { AdbScrcpyConnection } from "../connection.js";
|
|
14
14
|
|
|
15
15
|
export interface AdbScrcpyOptions<T extends object> extends ScrcpyOptions<T> {
|
|
16
16
|
createConnection(adb: Adb): AdbScrcpyConnection;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type ScrcpyInjectTouchControlMessage,
|
|
4
|
-
} from "./inject-touch.js";
|
|
1
|
+
import type { ScrcpyInjectTouchControlMessage } from "./inject-touch.js";
|
|
2
|
+
import { AndroidMotionEventAction } from "./inject-touch.js";
|
|
5
3
|
import { ScrcpyControlMessageType } from "./type.js";
|
|
6
4
|
|
|
7
5
|
/**
|