From 4bf5f1fcf2a457ffc73ffd90bd3c9d2a4f4a8953 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Fri, 17 Nov 2023 20:59:54 +0800 Subject: [PATCH] Trigger events for Ping and Pong. --- src/websocket/Event.php | 2 +- src/websocket/socketio/Handler.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/websocket/Event.php b/src/websocket/Event.php index 4e18475..891bf3a 100644 --- a/src/websocket/Event.php +++ b/src/websocket/Event.php @@ -7,7 +7,7 @@ class Event public $type; public $data; - public function __construct($type, $data) + public function __construct($type, $data = null) { $this->type = $type; $this->data = $data; diff --git a/src/websocket/socketio/Handler.php b/src/websocket/socketio/Handler.php index 3150bec..4c7ac8a 100644 --- a/src/websocket/socketio/Handler.php +++ b/src/websocket/socketio/Handler.php @@ -23,7 +23,7 @@ class Handler implements HandlerInterface protected $eio; - protected $pingTimeoutTimer = 0; + protected $pingTimeoutTimer = 0; protected $pingIntervalTimer = 0; protected $pingInterval; @@ -89,8 +89,8 @@ public function onMessage(Frame $frame) $this->onConnect($packet->data); break; case Packet::EVENT: - $type = array_shift($packet->data); - $data = $packet->data; + $type = array_shift($packet->data); + $data = $packet->data; $result = $this->event->trigger('swoole.websocket.Event', new WsEvent($type, $data)); if ($packet->id !== null) { @@ -113,9 +113,11 @@ public function onMessage(Frame $frame) } break; case EnginePacket::PING: + $this->event->trigger('swoole.websocket.Ping'); $this->push(EnginePacket::pong($enginePacket->data)); break; case EnginePacket::PONG: + $this->event->trigger('swoole.websocket.Pong'); $this->schedulePing(); break; default: