(
params: { simulatorUuid: string; fps?: number },
executor: CommandExecutor,
axeHelpers?: AxeHelpers,
)
| 156 | } |
| 157 | |
| 158 | export async function startSimulatorVideoCapture( |
| 159 | params: { simulatorUuid: string; fps?: number }, |
| 160 | executor: CommandExecutor, |
| 161 | axeHelpers?: AxeHelpers, |
| 162 | ): Promise<StartVideoCaptureResult> { |
| 163 | const simulatorUuid = params.simulatorUuid; |
| 164 | if (!simulatorUuid) { |
| 165 | return { started: false, error: 'simulatorUuid is required' }; |
| 166 | } |
| 167 | |
| 168 | if (sessions.has(simulatorUuid)) { |
| 169 | return { |
| 170 | started: false, |
| 171 | error: 'A video recording session is already active for this simulator. Stop it first.', |
| 172 | }; |
| 173 | } |
| 174 | |
| 175 | const helpers = axeHelpers ?? { |
| 176 | getAxePath, |
| 177 | getBundledAxeEnvironment, |
| 178 | }; |
| 179 | |
| 180 | const axeBinary = helpers.getAxePath(); |
| 181 | if (!axeBinary) { |
| 182 | return { started: false, error: 'Bundled AXe binary not found' }; |
| 183 | } |
| 184 | |
| 185 | const fps = Number.isFinite(params.fps as number) ? Number(params.fps) : 30; |
| 186 | const command = [axeBinary, 'record-video', '--udid', simulatorUuid, '--fps', String(fps)]; |
| 187 | const env = helpers.getBundledAxeEnvironment?.() ?? {}; |
| 188 | |
| 189 | log('info', `Starting AXe video recording for simulator ${simulatorUuid} at ${fps} fps`); |
| 190 | |
| 191 | const result = await executor(command, 'Start Simulator Video Capture', false, { env }, true); |
| 192 | |
| 193 | if (!result.success || !result.process) { |
| 194 | return { |
| 195 | started: false, |
| 196 | error: result.error ?? 'Failed to start video capture process', |
| 197 | }; |
| 198 | } |
| 199 | |
| 200 | const child = result.process as ChildProcess; |
| 201 | const session: Session = { |
| 202 | process: child, |
| 203 | sessionId: createSessionId(simulatorUuid), |
| 204 | startedAt: Date.now(), |
| 205 | buffer: '', |
| 206 | ended: false, |
| 207 | releaseActivity: acquireDaemonActivity('video.capture'), |
| 208 | }; |
| 209 | |
| 210 | try { |
| 211 | child.stdout?.on('data', (d: unknown) => { |
| 212 | session.buffer += String(d ?? ''); |
| 213 | }); |
| 214 | child.stderr?.on('data', (d: unknown) => { |
| 215 | session.buffer += String(d ?? ''); |
nothing calls this directly
no test coverage detected