This commit is contained in:
2021-08-01 11:24:52 +08:00
parent a0f1d7d933
commit 7700c16b56
2 changed files with 21 additions and 5 deletions
+6 -5
View File
@@ -338,8 +338,10 @@ class ServerManager extends Abstracts\Server
$this->server->on('handshake', [$reflect, 'onHandshake']);
$this->server->on('message', [$reflect, 'onMessage']);
$this->server->on('close', [$reflect, 'onClose']);
$this->server->on('disconnect', [$reflect, 'onDisconnect']);
$reflect->setEvents(Constant::HANDSHAKE, $settings['events'][Constant::HANDSHAKE] ?? null);
$reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null);
$reflect->setEvents(Constant::MESSAGE, $settings['events'][Constant::MESSAGE] ?? null);
$reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null);
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
@@ -388,13 +390,12 @@ class ServerManager extends Abstracts\Server
*/
private function addCloseOrDisconnect($reflect, $settings): void
{
if (swoole_version() >= '4.7.0') {
$this->server->on('disconnect', [$reflect, 'onDisconnect']);
if (swoole_version() >= '4.7') {
$reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null);
} else {
$this->server->on('close', [$reflect, 'onClose']);
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
$this->server->on('disconnect', [$reflect, 'onDisconnect']);
}
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
$this->server->on('close', [$reflect, 'onClose']);
}