( port: number, sessionId: string, cycle: number, sessionIndex: number, options: CliOptions, )
| 340 | } |
| 341 | |
| 342 | async function openRegisteredSocket( |
| 343 | port: number, |
| 344 | sessionId: string, |
| 345 | cycle: number, |
| 346 | sessionIndex: number, |
| 347 | options: CliOptions, |
| 348 | ) { |
| 349 | const socket = new WebSocket(`ws://127.0.0.1:${port}/session`); |
| 350 | await new Promise<void>((resolve, reject) => { |
| 351 | const timeout = setTimeout( |
| 352 | () => reject(new Error(`Timed out opening websocket for ${sessionId}.`)), |
| 353 | 2_000, |
| 354 | ); |
| 355 | socket.addEventListener( |
| 356 | "open", |
| 357 | () => { |
| 358 | clearTimeout(timeout); |
| 359 | resolve(); |
| 360 | }, |
| 361 | { once: true }, |
| 362 | ); |
| 363 | socket.addEventListener( |
| 364 | "error", |
| 365 | () => { |
| 366 | clearTimeout(timeout); |
| 367 | reject(new Error(`Websocket failed for ${sessionId}.`)); |
| 368 | }, |
| 369 | { once: true }, |
| 370 | ); |
| 371 | }); |
| 372 | |
| 373 | socket.send( |
| 374 | JSON.stringify({ |
| 375 | type: "register", |
| 376 | registration: makeRegistration(sessionId, cycle, sessionIndex, options), |
| 377 | snapshot: makeSnapshot(sessionId, 0, options), |
| 378 | }), |
| 379 | ); |
| 380 | return socket; |
| 381 | } |
| 382 | |
| 383 | async function sendSnapshotUpdates( |
| 384 | sockets: WebSocket[], |
no test coverage detected