ws überarbetiet

This commit is contained in:
dh
2025-02-28 07:24:29 +01:00
parent 81de3f5fe4
commit f0a6348e79
2 changed files with 29 additions and 32 deletions
+28 -31
View File
@@ -53,7 +53,34 @@ class HauptManager extends IPSModule
private function StartWebSocketServer() private function StartWebSocketServer()
{ {
$server = new \Ratchet\App('localhost', 8080); $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(); $server->run();
} }
@@ -82,34 +109,4 @@ class HauptManager extends IPSModule
$this->UpdateFormField('ClientList', 'values', json_encode($clientList)); $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
}
}
?> ?>
+1 -1
View File
@@ -6,7 +6,7 @@
"compatibility": { "compatibility": {
"version": "7.1" "version": "7.1"
}, },
"version": "1.100", "version": "1.101",
"build": 0, "build": 0,
"date": 0 "date": 0
} }