mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Merge pull request #1718 from jobinli/hotfix#socketio-trigger-connect
socketIo组件在onOpen中促发connect事件
This commit is contained in:
commit
a7e3b90ac6
@ -206,17 +206,13 @@ class SocketIO implements OnMessageInterface, OnOpenInterface, OnCloseInterface
|
||||
];
|
||||
$server->push($request->fd, Engine::OPEN . json_encode($data)); //socket is open
|
||||
$server->push($request->fd, Engine::MESSAGE . Packet::OPEN); //server open
|
||||
|
||||
$this->dispatchEventInAllNamespaces($request->fd, 'connect');
|
||||
}
|
||||
|
||||
public function onClose(Server $server, int $fd, int $reactorId): void
|
||||
{
|
||||
$all = SocketIORouter::list();
|
||||
if (! array_key_exists('forward', $all)) {
|
||||
return;
|
||||
}
|
||||
foreach (array_keys($all['forward']) as $nsp) {
|
||||
$this->dispatch($fd, $nsp, 'disconnect', null);
|
||||
}
|
||||
$this->dispatchEventInAllNamespaces($fd, 'disconnect');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,4 +297,15 @@ class SocketIO implements OnMessageInterface, OnOpenInterface, OnCloseInterface
|
||||
$this->addCallback($ackId, $channel, $timeout);
|
||||
}, ]);
|
||||
}
|
||||
|
||||
private function dispatchEventInAllNamespaces(int $fd, string $event)
|
||||
{
|
||||
$all = SocketIORouter::list();
|
||||
if (! array_key_exists('forward', $all)) {
|
||||
return;
|
||||
}
|
||||
foreach (array_keys($all['forward']) as $nsp) {
|
||||
$this->dispatch($fd, $nsp, $event, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user