(
simulatorUuid: string,
options: { timeoutMs?: number } = {},
)
| 85 | type StopSessionResult = StopSessionSuccess | StopSessionError; |
| 86 | |
| 87 | async function stopSession( |
| 88 | simulatorUuid: string, |
| 89 | options: { timeoutMs?: number } = {}, |
| 90 | ): Promise<StopSessionResult> { |
| 91 | const session = sessions.get(simulatorUuid); |
| 92 | if (!session) { |
| 93 | return { error: 'No active video recording session for this simulator' }; |
| 94 | } |
| 95 | |
| 96 | sessions.delete(simulatorUuid); |
| 97 | const child = session.process as ChildProcess | undefined; |
| 98 | |
| 99 | try { |
| 100 | child?.kill?.('SIGINT'); |
| 101 | } catch { |
| 102 | try { |
| 103 | child?.kill?.(); |
| 104 | } catch { |
| 105 | // ignore |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | await waitForChildToStop(session, options.timeoutMs ?? 5000); |
| 110 | |
| 111 | const combinedOutput = session.buffer; |
| 112 | const parsedPath = parseLastAbsoluteMp4Path(combinedOutput) ?? undefined; |
| 113 | |
| 114 | session.releaseActivity?.(); |
| 115 | |
| 116 | return { |
| 117 | sessionId: session.sessionId, |
| 118 | stdout: combinedOutput, |
| 119 | parsedPath, |
| 120 | }; |
| 121 | } |
| 122 | |
| 123 | function ensureSignalHandlersAttached(): void { |
| 124 | if (signalHandlersAttached) return; |
no test coverage detected