From 111309985b0c22011d7fe09c794bdf52867ee653 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Fri, 22 Jan 2021 02:15:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9php7.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/websocket/socketio/EnginePacket.php | 2 +- src/websocket/socketio/Handler.php | 8 ++++---- src/websocket/socketio/Parser.php | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/websocket/socketio/EnginePacket.php b/src/websocket/socketio/EnginePacket.php index 1c18bb6..d0b8e97 100644 --- a/src/websocket/socketio/EnginePacket.php +++ b/src/websocket/socketio/EnginePacket.php @@ -71,7 +71,7 @@ public static function message($payload) public static function fromString(string $packet) { - return new static($packet{0}, substr($packet, 1) ?? ''); + return new static(substr($packet, 0, 1), substr($packet, 1) ?? ''); } public function toString() diff --git a/src/websocket/socketio/Handler.php b/src/websocket/socketio/Handler.php index 9ead8af..00036a7 100644 --- a/src/websocket/socketio/Handler.php +++ b/src/websocket/socketio/Handler.php @@ -85,14 +85,14 @@ public function onMessage(Frame $frame) $this->onConnect($packet->data); break; case Packet::EVENT: - case Packet::ACK: - $result = $this->event->trigger('swoole.websocket.Event', $packet->data); + [$type, $data] = $packet->data; + $result = $this->event->trigger('swoole.websocket.Event', ['type' => $type, 'data' => $data]); if ($packet->id !== null) { $responsePacket = Packet::create(Packet::ACK, [ 'id' => $packet->id, 'nsp' => $packet->nsp, - 'data' => end($result), + 'data' => $result, ]); $this->push($responsePacket); @@ -160,7 +160,7 @@ protected function resetPingTimeout($timeout) protected function schedulePing() { Timer::clear($this->pingIntervalTimer); - $this->pingIntervalTimer = Timer::after($this->pingIntervalTimer, function () { + $this->pingIntervalTimer = Timer::after($this->pingInterval, function () { $this->push(EnginePacket::ping()); $this->resetPingTimeout($this->pingTimeout); }); diff --git a/src/websocket/socketio/Parser.php b/src/websocket/socketio/Parser.php index 4ce4e5f..35ebb42 100644 --- a/src/websocket/socketio/Parser.php +++ b/src/websocket/socketio/Parser.php @@ -12,7 +12,7 @@ public static function encode(Packet $packet) $str .= $packet->nsp . ','; } - if (!empty($packet->id)) { + if ($packet->id !== null) { $str .= $packet->id; } @@ -26,13 +26,13 @@ public static function decode(string $str) { $i = 0; - $packet = new Packet((int) $str{0}); + $packet = new Packet((int) substr($str, 0, 1)); // look up namespace (if any) - if ('/' === $str{$i + 1}) { + if ('/' === substr($str, $i + 1, 1)) { $nsp = ''; while (++$i) { - $c = $str{$i}; + $c = substr($str, $i, 1); if (',' === $c) { break; } @@ -47,16 +47,16 @@ public static function decode(string $str) } // look up id - $next = $str{$i + 1}; + $next = substr($str, $i + 1, 1); if ('' !== $next && is_numeric($next)) { $id = ''; while (++$i) { - $c = $str{$i}; + $c = substr($str, $i, 1); if (null == $c || !is_numeric($c)) { --$i; break; } - $id .= $str{$i}; + $id .= substr($str, $i, 1); if ($i === strlen($str)) { break; } @@ -65,7 +65,7 @@ public static function decode(string $str) } // look up json data - if ($str{++$i}) { + if (substr($str, ++$i, 1)) { $packet->data = json_decode(substr($str, $i), true); }