diff --git a/HauptManager/module.php b/HauptManager/module.php index 07c3896..9407957 100644 --- a/HauptManager/module.php +++ b/HauptManager/module.php @@ -1,7 +1,5 @@ route('/ws', new class($this) implements \Ratchet\MessageComponentInterface { - private $module; - - public function __construct($module) - { - $this->module = $module; - } - - public function onOpen(\Ratchet\ConnectionInterface $conn) - { - $this->module->AddClient($conn); - } - - public function onClose(\Ratchet\ConnectionInterface $conn) - { - $this->module->RemoveClient($conn); - } - - public function onError(\Ratchet\ConnectionInterface $conn, \Exception $e) - { - $conn->close(); - } - - public function onMessage(\Ratchet\ConnectionInterface $from, $msg) - { - // Nachrichtenverarbeitung implementieren - } - }, ['*']); - $server->run(); + $server = new PHPWebSocket(); + $server->bind('message', function($clientID, $message, $messageLength, $binary) { + $this->onMessage($clientID, $message); + }); + $server->bind('open', function($clientID) { + $this->AddClient($clientID); + }); + $server->bind('close', function($clientID) { + $this->RemoveClient($clientID); + }); + $server->startServer('localhost', 8080); } - public function AddClient($conn) + public function AddClient($clientID) { $clients = json_decode($this->GetValue("Clients"), true); if ($clients === null) { $clients = []; } - $clients[] = (string)$conn->resourceId; + $clients[] = (string)$clientID; $this->SetValue("Clients", json_encode($clients)); $this->UpdateClientList(); } - public function RemoveClient($conn) + public function RemoveClient($clientID) { $clients = json_decode($this->GetValue("Clients"), true); if ($clients !== null) { - $index = array_search((string)$conn->resourceId, $clients); + $index = array_search((string)$clientID, $clients); if ($index !== false) { unset($clients[$index]); $clients = array_values($clients); // Reindizieren des Arrays @@ -122,5 +101,10 @@ class HauptManager extends IPSModule } $this->UpdateFormField('ClientList', 'values', json_encode($clientList)); } + + public function onMessage($clientID, $message) + { + // Nachrichtenverarbeitung implementieren + } } ?> \ No newline at end of file diff --git a/library.json b/library.json index 1a225b4..f3a34d7 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "1.103", + "version": "1.104", "build": 0, "date": 0 } \ No newline at end of file