(frame: string)
| 127 | } |
| 128 | |
| 129 | private parse(frame: string): void { |
| 130 | let name = 'message'; |
| 131 | let data = ''; |
| 132 | for (const line of frame.split('\n')) { |
| 133 | if (line.startsWith(':')) { |
| 134 | this.comments += 1; |
| 135 | continue; |
| 136 | } |
| 137 | if (line.startsWith('event: ')) name = line.slice(7); |
| 138 | else if (line.startsWith('data: ')) data += line.slice(6); |
| 139 | } |
| 140 | if (data === '') return; |
| 141 | try { |
| 142 | this.events.push({ event: name, data: JSON.parse(data) }); |
| 143 | } catch { |
| 144 | this.events.push({ event: name, data }); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** Wait for an event of `type`, or give up. Never polls the server. */ |
| 149 | async waitFor(type: string, timeoutMs = 12_000): Promise<SseEvent> { |
no test coverage detected