ws überarbetiet

This commit is contained in:
2025-02-28 07:24:29 +01:00
parent 81de3f5fe4
commit f0a6348e79
2 changed files with 29 additions and 32 deletions

View File

@@ -53,7 +53,34 @@ class HauptManager extends IPSModule
private function StartWebSocketServer()
{
$server = new \Ratchet\App('localhost', 8080);
$server->route('/ws', new WebSocketHandler($this), ['*']);
$server->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();
}
@@ -82,34 +109,4 @@ class HauptManager extends IPSModule
$this->UpdateFormField('ClientList', 'values', json_encode($clientList));
}
}
class WebSocketHandler 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
}
}
?>

View File

@@ -6,7 +6,7 @@
"compatibility": {
"version": "7.1"
},
"version": "1.100",
"version": "1.101",
"build": 0,
"date": 0
}