| 275 | } |
| 276 | |
| 277 | private send(client: Client, event: WireEvent): void { |
| 278 | if (client.res.writableEnded) return; |
| 279 | try { |
| 280 | // `retry` on every frame is cheap and means a client that reconnects with |
| 281 | // the browser's own EventSource still backs off the way we asked. |
| 282 | client.res.write(`retry: 3000\nevent: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`); |
| 283 | } catch { |
| 284 | this.drop(client); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | private broadcast(event: WireEvent): void { |
| 289 | for (const client of [...this.clients]) this.send(client, event); |