From e9b872cf23ece9dd0ddb02455c0652215fcf6f2f Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Thu, 21 Jan 2021 12:18:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84socket.io=20disconnect?= =?UTF-8?q?=E3=80=81close=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/websocket/socketio/Handler.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/websocket/socketio/Handler.php b/src/websocket/socketio/Handler.php index 302c4a7..5e7be3c 100644 --- a/src/websocket/socketio/Handler.php +++ b/src/websocket/socketio/Handler.php @@ -61,7 +61,7 @@ protected function onConnect($fd, $data = null) $payload .= json_encode(['sid' => base64_encode(uniqid())]); } } catch (Exception $exception) { - $payload = sprintf(Packet::MESSAGE . Packet::CONNECT_ERROR . '"%s"', $exception->getMessage()); + $payload = Packet::MESSAGE . Packet::CONNECT_ERROR . json_encode(['message' => $exception->getMessage()]); } if ($this->server->isEstablished($fd)) { $this->server->push($fd, $payload); @@ -100,6 +100,9 @@ public function onMessage(Frame $frame) $this->server->push($frame->fd, $this->pack(Packet::ACK . $id, end($result))); } break; + case Packet::DISCONNECT: + $this->event->trigger('swoole.websocket.Disconnect'); + break; } break; case Packet::PING: @@ -112,18 +115,6 @@ public function onMessage(Frame $frame) return true; } - /** - * "onClose" listener. - * - * @param int $fd - * @param int $reactorId - * @return bool - */ - public function onClose($fd, $reactorId) - { - - } - protected function decode($payload) { $data = json_decode($payload, true);