MCPcopy
hub / github.com/yume-chan/ya-webadb / AdbScrcpyClient

Class AdbScrcpyClient

libraries/adb-scrcpy/src/client.ts:91–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 | AdbScrcpyAudioStreamSuccessMetadata;
90
91export class AdbScrcpyClient<TOptions extends AdbScrcpyOptions<object>> {
92 static async pushServer(
93 adb: Adb,
94 file: ReadableStream<MaybeConsumable<Uint8Array>>,
95 filename = DefaultServerPath,
96 ) {
97 const sync = await adb.sync();
98 try {
99 await sync.write({
100 filename,
101 file,
102 });
103 } finally {
104 await sync.dispose();
105 }
106 }
107
108 static async start<
109 TOptions extends AdbScrcpyOptions<
110 Pick<ScrcpyOptions1_15.Init, "tunnelForward">
111 >,
112 >(
113 adb: Adb,
114 path: string,
115 options: TOptions,
116 ): Promise<AdbScrcpyClient<TOptions>> {
117 let connection: AdbScrcpyConnection | undefined;
118 let process: AdbNoneProtocolProcess | undefined;
119
120 try {
121 try {
122 connection = options.createConnection(adb);
123 await connection.initialize();
124 } catch (e) {
125 if (e instanceof AdbReverseNotSupportedError) {
126 // When reverse tunnel is not supported, try forward tunnel.
127 options.value.tunnelForward = true;
128 connection = options.createConnection(adb);
129 await connection.initialize();
130 } else {
131 connection = undefined;
132 throw e;
133 }
134 }
135
136 // Use environment variable CLASSPATH instead of -cp flag
137 // This is the approach used by the official scrcpy C implementation
138 // See: https://github.com/Genymobile/scrcpy/blob/master/app/src/server.c
139 const args = [
140 `CLASSPATH=${path}`, // Set environment variable
141 "app_process",
142 "/", // Parent dir (unused but required)
143 "com.genymobile.scrcpy.Server",
144 options.version,
145 ...options.serialize(),
146 ];
147
148 if (options.spawner) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected