* Stream content with delta computation - only output new characters.
(ts: number, text: string, header: string)
| 385 | * Stream content with delta computation - only output new characters. |
| 386 | */ |
| 387 | streamContent(ts: number, text: string, header: string): void { |
| 388 | const previous = this.streamedContent.get(ts) |
| 389 | |
| 390 | if (!previous) { |
| 391 | // First time seeing this message - output header and initial text |
| 392 | this.writeRaw(`\n${header} `) |
| 393 | this.writeRaw(text) |
| 394 | this.streamedContent.set(ts, { ts, text, headerShown: true }) |
| 395 | this.currentlyStreamingTs = ts |
| 396 | this.streamingState.next({ ts, isStreaming: true }) |
| 397 | } else if (text.length > previous.text.length && text.startsWith(previous.text)) { |
| 398 | // Text has grown - output delta |
| 399 | const delta = text.slice(previous.text.length) |
| 400 | this.writeRaw(delta) |
| 401 | this.streamedContent.set(ts, { ts, text, headerShown: true }) |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * Finish streaming a message (add newline). |
no test coverage detected