改名
This commit is contained in:
@@ -338,8 +338,10 @@ class ServerManager extends Abstracts\Server
|
|||||||
$this->server->on('handshake', [$reflect, 'onHandshake']);
|
$this->server->on('handshake', [$reflect, 'onHandshake']);
|
||||||
$this->server->on('message', [$reflect, 'onMessage']);
|
$this->server->on('message', [$reflect, 'onMessage']);
|
||||||
$this->server->on('close', [$reflect, 'onClose']);
|
$this->server->on('close', [$reflect, 'onClose']);
|
||||||
|
$this->server->on('disconnect', [$reflect, 'onDisconnect']);
|
||||||
|
|
||||||
$reflect->setEvents(Constant::HANDSHAKE, $settings['events'][Constant::HANDSHAKE] ?? null);
|
$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::MESSAGE, $settings['events'][Constant::MESSAGE] ?? null);
|
||||||
$reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null);
|
$reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null);
|
||||||
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? 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
|
private function addCloseOrDisconnect($reflect, $settings): void
|
||||||
{
|
{
|
||||||
if (swoole_version() >= '4.7.0') {
|
if (swoole_version() >= '4.7') {
|
||||||
$this->server->on('disconnect', [$reflect, 'onDisconnect']);
|
|
||||||
$reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null);
|
$reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null);
|
||||||
} else {
|
$this->server->on('disconnect', [$reflect, 'onDisconnect']);
|
||||||
$this->server->on('close', [$reflect, 'onClose']);
|
|
||||||
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
|
|
||||||
}
|
}
|
||||||
|
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
|
||||||
|
$this->server->on('close', [$reflect, 'onClose']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class WebSocketServerListener extends Abstracts\Server
|
|||||||
$reflect = Snowflake::getDi()->getReflect(static::class)?->newInstance();
|
$reflect = Snowflake::getDi()->getReflect(static::class)?->newInstance();
|
||||||
$reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null);
|
$reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null);
|
||||||
$reflect->setEvents(Constant::HANDSHAKE, $settings['events'][Constant::HANDSHAKE] ?? null);
|
$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::MESSAGE, $settings['events'][Constant::MESSAGE] ?? null);
|
||||||
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
|
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ class WebSocketServerListener extends Abstracts\Server
|
|||||||
static::$_http->on('connect', [$reflect, 'onConnect']);
|
static::$_http->on('connect', [$reflect, 'onConnect']);
|
||||||
static::$_http->on('handshake', [$reflect, 'onHandshake']);
|
static::$_http->on('handshake', [$reflect, 'onHandshake']);
|
||||||
static::$_http->on('message', [$reflect, 'onMessage']);
|
static::$_http->on('message', [$reflect, 'onMessage']);
|
||||||
|
static::$_http->on('disconnect', [$reflect, 'onDisconnect']);
|
||||||
static::$_http->on('close', [$reflect, 'onClose']);
|
static::$_http->on('close', [$reflect, 'onClose']);
|
||||||
|
|
||||||
return static::$_http;
|
return static::$_http;
|
||||||
@@ -145,4 +147,17 @@ class WebSocketServerListener extends Abstracts\Server
|
|||||||
$this->_event->dispatch(Event::SYSTEM_RESOURCE_RELEASES);
|
$this->_event->dispatch(Event::SYSTEM_RESOURCE_RELEASES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Server $server
|
||||||
|
* @param int $fd
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function onDisconnect(Server $server, int $fd)
|
||||||
|
{
|
||||||
|
$this->runEvent(Constant::DISCONNECT, fn() => $server->confirm($fd), [$server, $fd]);
|
||||||
|
|
||||||
|
$this->_event->dispatch(Event::SYSTEM_RESOURCE_RELEASES);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user