From 9dbdda79c1bc82b0c1f45b3365165e2305f538f7 Mon Sep 17 00:00:00 2001 From: Zagicien Date: Wed, 9 Aug 2023 03:24:06 -0400 Subject: [PATCH] Update WsServer.php it won't works without it if json protocol is asked. --- src/Ratchet/WebSocket/WsServer.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 27795ca7..efe742de 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -114,8 +114,14 @@ public function onOpen(ConnectionInterface $conn, RequestInterface $request = nu $conn->WebSocket = new \StdClass; $conn->WebSocket->closing = false; - $response = $this->handshakeNegotiator->handshake($request)->withHeader('X-Powered-By', \Ratchet\VERSION); + $response = $this->handshakeNegotiator->handshake($request); + $Sec_WebSocket_Protocol = $request->getHeader('Sec-WebSocket-Protocol'); + if ($Sec_WebSocket_Protocol && $Sec_WebSocket_Protocol[0] == 'json'){ + $response = $response->withHeader('Sec-WebSocket-Protocol', 'json'); + } + + $response = $response->withHeader('X-Powered-By', \Ratchet\VERSION); $conn->send(Message::toString($response)); if (101 !== $response->getStatusCode()) {