From ced79375833298b3178ecb6107e86f7058586668 Mon Sep 17 00:00:00 2001 From: GitProtogen Date: Sat, 7 Mar 2026 20:17:40 +0100 Subject: [PATCH] added responses to users in ws as json --- bin/WebSocketServer.php | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/bin/WebSocketServer.php b/bin/WebSocketServer.php index 7b61e96..5ef435b 100644 --- a/bin/WebSocketServer.php +++ b/bin/WebSocketServer.php @@ -20,7 +20,6 @@ use \ComCen\Security\TokenHandler; class WebSocketServer implements MessageComponentInterface { private $connectionsData = []; - private $chatGroups = []; private function isSameConnection(ConnectionInterface $connection1, ConnectionInterface $connection2): bool { @@ -62,27 +61,11 @@ class WebSocketServer implements MessageComponentInterface echo "New connection: {$conn->resourceId}\n"; } - public function createGroup(string $owner, string $name, string ...$whitelist): bool - { - foreach ($whitelist as $user) { - if (strlen($user) > 32) { - return false; - } - } - - $chatGroups[] = [ - "owner" => $owner, - "name" => $name, - "whitelist" => $whitelist - ]; - return true; - } - public function onMessage(ConnectionInterface $from, $msg): void { $decodedMsg = json_decode($msg, true); if (!$decodedMsg) { - $from->send("not or empty json"); + $from->send("{\"error\"}: \"not or empty json\""); return; } $index = $this->getConnectionIndex($from); @@ -92,14 +75,10 @@ class WebSocketServer implements MessageComponentInterface $msgContent = $decodedMsg["msg"] ?? null; if ($msgContent) { $this->sendToAllAuthenticated($this->connectionsData[$index]["username"], $msgContent); + $from->send("{\"success\"}: \"message send\""); return; } - - $groupCreationRequest = $decodedMsg["createGroupWithName"] ?? null; - if ($groupCreationRequest) { - - } - + $from->send("{\"error\"}: \"no message\""); return; } @@ -108,13 +87,13 @@ class WebSocketServer implements MessageComponentInterface $tokenUser = TokenHandler::getTokenOwnership($token); if ($tokenUser) { $this->connectionsData[$index]["username"] = $tokenUser; - $from->send("authenticated"); + $from->send("{\"success\"}: \"authenticated\""); return; } - $from->send("invalid token"); + $from->send("{\"error\"}: \"invalid token\""); return; } - $from->send("not authenticated"); + $from->send("{\"error\"}: \"you are not authenticated\""); } public function onClose(ConnectionInterface $conn): void