(controller)
| 91 | |
| 92 | const stream = new ReadableStream({ |
| 93 | start(controller) { |
| 94 | ctrl = controller; |
| 95 | |
| 96 | // Send current state as snapshot |
| 97 | const snapshot: ExternalAnnotationEvent<StorableAnnotation> = { |
| 98 | type: "snapshot", |
| 99 | annotations: store.getAll(), |
| 100 | }; |
| 101 | controller.enqueue(encoder.encode(serializeSSEEvent(snapshot))); |
| 102 | |
| 103 | subscribers.add(controller); |
| 104 | |
| 105 | // Heartbeat to keep connection alive |
| 106 | heartbeatTimer = setInterval(() => { |
| 107 | try { |
| 108 | controller.enqueue(encoder.encode(HEARTBEAT_COMMENT)); |
| 109 | } catch { |
| 110 | // Stream closed |
| 111 | if (heartbeatTimer) clearInterval(heartbeatTimer); |
| 112 | subscribers.delete(controller); |
| 113 | } |
| 114 | }, HEARTBEAT_INTERVAL_MS); |
| 115 | }, |
| 116 | cancel() { |
| 117 | if (heartbeatTimer) clearInterval(heartbeatTimer); |
| 118 | subscribers.delete(ctrl); |
nothing calls this directly
no test coverage detected