mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
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
This commit is contained in:
parent
d01e384836
commit
f14128b3a4
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user