From f14128b3a4605c99b50645a7f5312803fc9361be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Wed, 17 Jul 2024 18:31:09 +0800 Subject: [PATCH] Fixed bug that socketio-server cannot work for swow engine. (#6953) * Fixed bug that socketio-server cannot work for swow engine. * Update CHANGELOG-3.1.md --- CHANGELOG-3.1.md | 1 + src/socketio-server/src/SocketIO.php | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG-3.1.md b/CHANGELOG-3.1.md index 18e9df477..868980ddf 100644 --- a/CHANGELOG-3.1.md +++ b/CHANGELOG-3.1.md @@ -3,6 +3,7 @@ ## Fixed - [#6949](https://github.com/hyperf/hyperf/pull/6949) Fixed bug that restart failed when don't have `.env`. +- [#6953](https://github.com/hyperf/hyperf/pull/6953) Fixed bug that socketio-server cannot work for swow engine. ## Optimized diff --git a/src/socketio-server/src/SocketIO.php b/src/socketio-server/src/SocketIO.php index 559dbe7b8..700788d37 100644 --- a/src/socketio-server/src/SocketIO.php +++ b/src/socketio-server/src/SocketIO.php @@ -108,26 +108,28 @@ class SocketIO implements OnMessageInterface, OnOpenInterface, OnCloseInterface public function onMessage($server, $frame): void { $response = (new Response($server))->init($frame); - if ($frame->opcode == Opcode::PING) { + $frame = Frame::from($frame); + $data = (string) $frame->getPayloadData(); + if ($frame->getOpcode() == Opcode::PING) { $response->push(new Frame(opcode: Opcode::PONG)); return; } - if ($frame->data[0] === Engine::PING) { - $this->renewInAllNamespaces($frame->fd); + if ($data[0] === Engine::PING) { + $this->renewInAllNamespaces($response->getFd()); $response->push(new Frame(payloadData: Engine::PONG)); return; } - if ($frame->data[0] === Engine::CLOSE) { + if ($data[0] === Engine::CLOSE) { $response->close(); return; } - if ($frame->data[0] !== Engine::MESSAGE) { - $this->stdoutLogger->error("EngineIO event type {$frame->data[0]} not supported"); + if ($data[0] !== Engine::MESSAGE) { + $this->stdoutLogger->error("EngineIO event type {$data[0]} not supported"); return; } - $packet = $this->decoder->decode($frame->data); + $packet = $this->decoder->decode($data); switch ($packet->type) { case Packet::OPEN: // client open $responsePacket = Packet::create([ @@ -152,7 +154,7 @@ class SocketIO implements OnMessageInterface, OnOpenInterface, OnCloseInterface $this->sender->pushFrame($response->getFd(), new Frame(payloadData: Engine::MESSAGE . $this->encoder->encode($responsePacket))); }; } - $this->dispatch($frame->fd, $packet->nsp, ...$packet->data); + $this->dispatch($response->getFd(), $packet->nsp, ...$packet->data); break; case Packet::ACK: // server ack $ackId = $packet->id;