>> roomId => (peerId => presence info), insertion-ordered */ private array $rooms = []; /** @var array peerId => roomId */ private array $peerRoom = []; public function members(string $roomId): array { return array_keys($this->rooms[$roomId] ?? []); } public function info(string $roomId, string $peerId): array { return $this->rooms[$roomId][$peerId] ?? []; } public function roomOf(string $peerId): ?string { return $this->peerRoom[$peerId] ?? null; } public function add(string $roomId, string $peerId, array $info): void { $this->rooms[$roomId][$peerId] = $info; $this->peerRoom[$peerId] = $roomId; } public function remove(string $roomId, string $peerId): void { unset($this->rooms[$roomId][$peerId], $this->peerRoom[$peerId]); if (($this->rooms[$roomId] ?? []) === []) { unset($this->rooms[$roomId]); } } public function roomIds(): array { return array_keys($this->rooms); } }