| 177 | } |
| 178 | |
| 179 | private recordBlock(block: string): void { |
| 180 | let data = ""; |
| 181 | let id: string | null = null; |
| 182 | for (const line of block.replace(/\r/g, "").split("\n")) { |
| 183 | if (line.startsWith("data:")) data += `${line.slice("data:".length).trimStart()}\n`; |
| 184 | if (line.startsWith("id:")) id = line.slice("id:".length).trim(); |
| 185 | } |
| 186 | if (id) this.eventIds.push(id); |
| 187 | const trimmed = data.trim(); |
| 188 | if (!trimmed) return; |
| 189 | const parsed = JSON.parse(trimmed) as JsonRpcMessage; |
| 190 | this.messages.push(parsed); |
| 191 | if (typeof parsed.id !== "string" && typeof parsed.id !== "number") return; |
| 192 | const responseWaiters = this.responseWaiters; |
| 193 | this.responseWaiters = []; |
| 194 | for (const waiter of responseWaiters) waiter.resolve(parsed); |
| 195 | const waiters = this.waiters.get(parsed.id) ?? []; |
| 196 | this.waiters.delete(parsed.id); |
| 197 | for (const waiter of waiters) waiter.resolve(parsed); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | const openGet = async ( |