Skip to content

Commit

Permalink
完善socket.io disconnect、close事件
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Jan 21, 2021
1 parent b2620a9 commit e9b872c
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/websocket/socketio/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down

0 comments on commit e9b872c

Please sign in to comment.