From 043388df3dc996f7d47d3fa3be3ad7cf7469932f Mon Sep 17 00:00:00 2001 From: MKStoler1024 <158786854+MKStoler1024@users.noreply.github.com> Date: Sat, 1 Feb 2025 03:53:55 +0800 Subject: [PATCH] =?UTF-8?q?del:=20=E6=97=A0=E7=94=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ws_server.php | 69 --------------------------------------------------- 1 file changed, 69 deletions(-) delete mode 100644 ws_server.php 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(); -?>