ws überarbetiet
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -6,7 +6,7 @@
|
||||
"compatibility": {
|
||||
"version": "7.1"
|
||||
},
|
||||
"version": "1.100",
|
||||
"version": "1.101",
|
||||
"build": 0,
|
||||
"date": 0
|
||||
}
|
||||
Reference in New Issue
Block a user