(data: Buffer | string)
| 445 | } |
| 446 | |
| 447 | private onPtyData(data: Buffer | string): void { |
| 448 | if (this.disposed) return; |
| 449 | const buf = Buffer.isBuffer(data) ? data : Buffer.from(data, 'utf8'); |
| 450 | this.buffer.append(buf); |
| 451 | |
| 452 | const ws = this.ws; |
| 453 | if (ws !== null) { |
| 454 | ws.send(buf, { binary: true }, (err) => { |
| 455 | if (err) { |
| 456 | this.log.warn('session.send_error', { err }); |
| 457 | return; |
| 458 | } |
| 459 | if (this.paused && ws.bufferedAmount <= this.opts.lowWatermarkBytes) { |
| 460 | this.paused = false; |
| 461 | try { |
| 462 | this.term.resume(); |
| 463 | } catch { |
| 464 | // ignore |
| 465 | } |
| 466 | } |
| 467 | }); |
| 468 | |
| 469 | if (!this.paused && ws.bufferedAmount >= this.opts.highWatermarkBytes) { |
| 470 | this.paused = true; |
| 471 | try { |
| 472 | this.term.pause(); |
| 473 | } catch { |
| 474 | // ignore |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | if (this.buffer.tailSeq - this.lastCursorSeq >= CURSOR_BYTES_INTERVAL) { |
| 480 | this.maybeSendCursor(); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /** Un-pause the PTY read stream if backpressure paused it. Safe to call when |
| 485 | * already running. Keeping the `paused` flag and the term stream in lockstep |
no test coverage detected