*/ public array $sent = []; public bool $closed = false; /** @param array $inbound scripted JSON frames handed back by receive() */ public function __construct(private array $inbound) {} public function send(string $text): void { $this->sent[] = $text; } public function receive(): ?string { return array_shift($this->inbound); // null once exhausted } public function close(): void { $this->closed = true; } /** @return array the `type` of each sent frame, in order */ public function sentTypes(): array { return array_map(static fn ($s) => (string) (json_decode($s, true)['type'] ?? '?'), $this->sent); } }