Fixed bug that the socket-io server always restart when using coroutine style server. (#4854)

This commit is contained in:
李铭昕 2022-06-20 09:53:54 +08:00 committed by GitHub
parent c8d4d666aa
commit bb3f034c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -105,3 +105,4 @@ composer analyse
- [#4549](https://github.com/hyperf/hyperf/pull/4549) Fixed bug that `PhpParser::getExprFromValue()` does not support assoc array.
- [#4835](https://github.com/hyperf/hyperf/pull/4835) Fixed the lost description when using property `$description` and `$signature` for `hyperf/command`.
- [#4851](https://github.com/hyperf/hyperf/pull/4851) Fixed bug that prometheus server will not be closed automatically when using command which enable event dispatcher.
- [#4854](https://github.com/hyperf/hyperf/pull/4854) Fixed bug that the `socket-io` client always reconnect when using coroutine style server.

View File

@ -27,6 +27,7 @@ use Hyperf\SocketIOServer\Parser\Packet;
use Hyperf\SocketIOServer\Room\EphemeralInterface;
use Hyperf\SocketIOServer\SidProvider\SidProviderInterface;
use Hyperf\Utils\ApplicationContext;
use Hyperf\WebSocketServer\Constant\Opcode;
use Hyperf\WebSocketServer\Sender;
use Swoole\Atomic;
use Swoole\Http\Request;
@ -105,6 +106,15 @@ class SocketIO implements OnMessageInterface, OnOpenInterface, OnCloseInterface
*/
public function onMessage($server, $frame): void
{
if ($frame->opcode == Opcode::PING) {
if ($server instanceof Response) {
$server->push('', Opcode::PONG);
} else {
$server->push($frame->fd, '', Opcode::PONG);
}
return;
}
if ($frame->data[0] === Engine::PING) {
$this->renewInAllNamespaces($frame->fd);
if ($server instanceof Response) {