Skip to content

Commit

Permalink
Trigger events for Ping and Pong.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Nov 17, 2023
1 parent 04a7dab commit 4bf5f1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/websocket/Event.php
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/websocket/socketio/Handler.php
Expand Up @@ -23,7 +23,7 @@ class Handler implements HandlerInterface

protected $eio;

protected $pingTimeoutTimer = 0;
protected $pingTimeoutTimer = 0;
protected $pingIntervalTimer = 0;

protected $pingInterval;
Expand Down Expand Up @@ -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) {
Expand All @@ -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:
Expand Down

0 comments on commit 4bf5f1f

Please sign in to comment.