(
adb: Adb,
path: string,
options: AdbScrcpyOptions<Pick<ScrcpyOptions1_15.Init, "tunnelForward">>,
)
| 5 | import type { AdbScrcpyOptions } from "../../types.js"; |
| 6 | |
| 7 | export async function getDisplays( |
| 8 | adb: Adb, |
| 9 | path: string, |
| 10 | options: AdbScrcpyOptions<Pick<ScrcpyOptions1_15.Init, "tunnelForward">>, |
| 11 | ): Promise<ScrcpyDisplay[]> { |
| 12 | try { |
| 13 | // Server will exit before opening connections when an invalid display id was given |
| 14 | // so `start` will throw an `AdbScrcpyExitedError` |
| 15 | const client = await AdbScrcpyClient.start(adb, path, options); |
| 16 | |
| 17 | // If the server didn't exit, manually stop it and throw an error |
| 18 | await client.close(); |
| 19 | throw new Error("Unexpected server output"); |
| 20 | } catch (e) { |
| 21 | if (e instanceof AdbScrcpyExitedError) { |
| 22 | if (e.output[0]?.startsWith("[server] ERROR:")) { |
| 23 | throw e; |
| 24 | } |
| 25 | |
| 26 | const displays: ScrcpyDisplay[] = []; |
| 27 | for (const line of e.output) { |
| 28 | const display = options.parseDisplay(line); |
| 29 | if (display) { |
| 30 | displays.push(display); |
| 31 | } |
| 32 | } |
| 33 | return displays; |
| 34 | } |
| 35 | |
| 36 | throw e; |
| 37 | } |
| 38 | } |
no test coverage detected