diff --git a/src/ZM/Event/Swoole/WSCloseEvent.php b/src/ZM/Event/Swoole/WSCloseEvent.php index 2e1a6be1..8a6e418d 100644 --- a/src/ZM/Event/Swoole/WSCloseEvent.php +++ b/src/ZM/Event/Swoole/WSCloseEvent.php @@ -4,6 +4,7 @@ namespace ZM\Event\Swoole; +use Closure; use Doctrine\Common\Annotations\AnnotationException; use Framework\ZMBuf; use Swoole\Server; @@ -11,8 +12,6 @@ use ZM\Annotation\Swoole\SwooleEventAfter; use ZM\Annotation\Swoole\SwooleEventAt; use ZM\Connection\ConnectionManager; use ZM\Event\EventHandler; -use ZM\ModBase; -use ZM\ModHandleType; use ZM\Utils\ZMUtil; class WSCloseEvent implements SwooleEvent @@ -32,7 +31,7 @@ class WSCloseEvent implements SwooleEvent */ public function onActivate() { ZMUtil::checkWait(); - set_coroutine_params(["server" => $this->server, "fd" => $this->fd]); + set_coroutine_params(["server" => $this->server, "fd" => $this->fd, "connection" => ConnectionManager::get($this->fd)]); foreach(ZMBuf::$events[SwooleEventAt::class] ?? [] as $v) { if(strtolower($v->type) == "close" && $this->parseSwooleRule($v)) { $c = $v->class; @@ -60,6 +59,11 @@ class WSCloseEvent implements SwooleEvent } private function parseSwooleRule($v) { + switch (explode(":", $v->rule)[0]) { + case "connectType": //websocket连接类型 + if ($v->callback instanceof Closure) return call_user_func($v->callback, ConnectionManager::get($this->fd)); + break; + } return true; } }