auf php websocket
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require __DIR__ . '/vendor/autoload.php'; // Autoload-Datei einbinden
|
|
||||||
|
|
||||||
class HauptManager extends IPSModule
|
class HauptManager extends IPSModule
|
||||||
{
|
{
|
||||||
public function Create()
|
public function Create()
|
||||||
@@ -53,54 +51,35 @@ class HauptManager extends IPSModule
|
|||||||
|
|
||||||
private function StartWebSocketServer()
|
private function StartWebSocketServer()
|
||||||
{
|
{
|
||||||
$server = new \Ratchet\App('localhost', 8080);
|
$server = new PHPWebSocket();
|
||||||
$server->route('/ws', new class($this) implements \Ratchet\MessageComponentInterface {
|
$server->bind('message', function($clientID, $message, $messageLength, $binary) {
|
||||||
private $module;
|
$this->onMessage($clientID, $message);
|
||||||
|
});
|
||||||
public function __construct($module)
|
$server->bind('open', function($clientID) {
|
||||||
{
|
$this->AddClient($clientID);
|
||||||
$this->module = $module;
|
});
|
||||||
|
$server->bind('close', function($clientID) {
|
||||||
|
$this->RemoveClient($clientID);
|
||||||
|
});
|
||||||
|
$server->startServer('localhost', 8080);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onOpen(\Ratchet\ConnectionInterface $conn)
|
public function AddClient($clientID)
|
||||||
{
|
|
||||||
$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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function AddClient($conn)
|
|
||||||
{
|
{
|
||||||
$clients = json_decode($this->GetValue("Clients"), true);
|
$clients = json_decode($this->GetValue("Clients"), true);
|
||||||
if ($clients === null) {
|
if ($clients === null) {
|
||||||
$clients = [];
|
$clients = [];
|
||||||
}
|
}
|
||||||
$clients[] = (string)$conn->resourceId;
|
$clients[] = (string)$clientID;
|
||||||
$this->SetValue("Clients", json_encode($clients));
|
$this->SetValue("Clients", json_encode($clients));
|
||||||
$this->UpdateClientList();
|
$this->UpdateClientList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function RemoveClient($conn)
|
public function RemoveClient($clientID)
|
||||||
{
|
{
|
||||||
$clients = json_decode($this->GetValue("Clients"), true);
|
$clients = json_decode($this->GetValue("Clients"), true);
|
||||||
if ($clients !== null) {
|
if ($clients !== null) {
|
||||||
$index = array_search((string)$conn->resourceId, $clients);
|
$index = array_search((string)$clientID, $clients);
|
||||||
if ($index !== false) {
|
if ($index !== false) {
|
||||||
unset($clients[$index]);
|
unset($clients[$index]);
|
||||||
$clients = array_values($clients); // Reindizieren des Arrays
|
$clients = array_values($clients); // Reindizieren des Arrays
|
||||||
@@ -122,5 +101,10 @@ class HauptManager extends IPSModule
|
|||||||
}
|
}
|
||||||
$this->UpdateFormField('ClientList', 'values', json_encode($clientList));
|
$this->UpdateFormField('ClientList', 'values', json_encode($clientList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onMessage($clientID, $message)
|
||||||
|
{
|
||||||
|
// Nachrichtenverarbeitung implementieren
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
"compatibility": {
|
"compatibility": {
|
||||||
"version": "7.1"
|
"version": "7.1"
|
||||||
},
|
},
|
||||||
"version": "1.103",
|
"version": "1.104",
|
||||||
"build": 0,
|
"build": 0,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user