onConnect = $handler; return $this; } /** * Setzt den Handler für eingehende Nachrichten * * @param callable $handler function(WebSocketConnection $connection, string $message): void */ public function onMessage(callable $handler): self { $this->onMessage = $handler; return $this; } /** * Setzt den Handler für geschlossene Verbindungen * * @param callable $handler function(WebSocketConnection $connection, int $code, string $reason): void */ public function onClose(callable $handler): self { $this->onClose = $handler; return $this; } /** * Setzt den Handler für Fehler * * @param callable $handler function(WebSocketConnection $connection, \Throwable $error): void */ public function onError(callable $handler): self { $this->onError = $handler; return $this; } /** * Setzt unterstützte Subprotokolle */ public function withSubprotocols(array $subprotocols): self { $this->subprotocols = $subprotocols; return $this; } /** * Setzt die maximale Nachrichtengröße */ public function withMaxMessageSize(int $bytes): self { $this->maxMessageSize = $bytes; return $this; } /** * Setzt das Ping-Intervall */ public function withPingInterval(int $seconds): self { $this->pingInterval = $seconds; return $this; } // Getter public function getOnConnect(): ?callable { return $this->onConnect; } public function getOnMessage(): ?callable { return $this->onMessage; } public function getOnClose(): ?callable { return $this->onClose; } public function getOnError(): ?callable { return $this->onError; } public function getSubprotocols(): array { return $this->subprotocols; } public function getMaxMessageSize(): int { return $this->maxMessageSize; } public function getPingInterval(): int { return $this->pingInterval; } }