* Subscribe to events for a session at a `{seq, epoch}` cursor. * If connected, sends immediately; otherwise queues until after server_hello.
(sessionId: string, cursor: SessionCursor = { seq: 0 })
| 154 | * If connected, sends immediately; otherwise queues until after server_hello. |
| 155 | */ |
| 156 | subscribe(sessionId: string, cursor: SessionCursor = { seq: 0 }): void { |
| 157 | this.subscriptions.set(sessionId, { ...cursor }); |
| 158 | |
| 159 | if (this.connected) { |
| 160 | this.sendSubscribe([sessionId], { [sessionId]: cursor }); |
| 161 | } else { |
| 162 | // Remove any earlier pending entry for this session, then enqueue |
| 163 | const idx = this.pendingSubscriptions.findIndex((p) => p.sessionId === sessionId); |
| 164 | if (idx !== -1) this.pendingSubscriptions.splice(idx, 1); |
| 165 | this.pendingSubscriptions.push({ sessionId, cursor: { ...cursor } }); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** Unsubscribe from a session's events. */ |
| 170 | unsubscribe(sessionId: string): void { |
nothing calls this directly
no test coverage detected