diff --git a/ws_server.php b/ws_server.php deleted file mode 100644 index 2baf968..0000000 --- a/ws_server.php +++ /dev/null @@ -1,69 +0,0 @@ -clients = new \SplObjectStorage; - $this->subscriptions = []; - } - - public function onOpen(ConnectionInterface $conn) { - $this->clients->attach($conn); - } - - public function onMessage(ConnectionInterface $from, $msg) { - $data = json_decode($msg, true); - if ($data['action'] === 'subscribe') { - $configId = $data['configId']; - $this->subscriptions[$configId][] = $from; - } - } - - public function onClose(ConnectionInterface $conn) { - $this->clients->detach($conn); - foreach ($this->subscriptions as $configId => $subscribers) { - $this->subscriptions[$configId] = array_filter($subscribers, function($subscriber) use ($conn) { - return $subscriber !== $conn; - }); - } - } - - public function onError(ConnectionInterface $conn, \Exception $e) { - $conn->close(); - } - - public function notifyClients($configId) { - if (isset($this->subscriptions[$configId])) { - foreach ($this->subscriptions[$configId] as $client) { - $client->send(json_encode(['action' => 'reload', 'configId' => $configId])); - } - } - } -} - -$server = IoServer::factory( - new HttpServer( - new WsServer( - new ConfigChangeNotifier() - ) - ), - 8080 -); - -$server->run(); -?>