diff --git a/composer.json b/composer.json index cca9481..0bd80a3 100644 --- a/composer.json +++ b/composer.json @@ -25,14 +25,14 @@ "wiki": "https://github.com/botuniverse/php-libonebot/wiki" }, "require": { - "php": "^7.4 || ^8.0 || ^8.1", + "php": "^7.4 || ^8.0 || ^8.1 || ^8.2", "ext-json": "*", "psr/cache": "^1.0", "psr/event-dispatcher": "^1.0", "psr/http-client": "^1.0", "psr/log": "^1.1", "rybakit/msgpack": "^0.9.0", - "choir/choir": "~0.1", + "choir/psr-http": "^1.0", "workerman/workerman": "^4.0", "zhamao/logger": "^1.0" }, diff --git a/src/OneBot/Driver/Choir/ChoirDriver.php b/src/OneBot/Driver/Choir/ChoirDriver.php deleted file mode 100644 index 1632086..0000000 --- a/src/OneBot/Driver/Choir/ChoirDriver.php +++ /dev/null @@ -1,85 +0,0 @@ -ws_client_socket as $v) { - $v->setClient(WebSocketClient::createFromAddress($v->getUrl(), array_merge($headers, $v->getHeaders()))); - } - } - - /** - * {@inheritDoc} - */ - public function createHttpClientSocket(array $config): HttpClientSocketBase - { - // TODO: Implement createHttpClientSocket() method. - throw new \Exception('Not implemented'); - } - - /** - * {@inheritDoc} - */ - protected function initInternalDriverClasses(?array $http, ?array $http_webhook, ?array $ws, ?array $ws_reverse): array - { - // TODO: Implement initInternalDriverClasses() method. - return []; - } -} diff --git a/src/OneBot/Driver/Choir/EventLoopWrapper.php b/src/OneBot/Driver/Choir/EventLoopWrapper.php deleted file mode 100644 index b7d91eb..0000000 --- a/src/OneBot/Driver/Choir/EventLoopWrapper.php +++ /dev/null @@ -1,57 +0,0 @@ -withRequest(HttpFactory::createRequest('GET', $address, $header)); - } - - /** - * @throws \Exception - */ - public function withRequest(RequestInterface $request): WebSocketClientInterface - { - // 通过 AsyncTcpConnection 建立连接 - $this->connection = new AsyncTcpConnection('ws://' . $request->getUri()->getHost() . ':' . $request->getUri()->getPort()); - // 通过 walkor 的隐藏魔法(无语了),设置请求的 Header。因为 PSR 的 Request 对象返回 Headers 是数组形式的,我们不需要重复的 Header 只取一个就行 - /* @phpstan-ignore-next-line */ - $this->connection->headers = array_map(function ($x) { - return $x[0]; - }, $request->getHeaders()); - // 如果连接建立后,可以通,则把 Request 请求中的请求包体以 WebSocket Message 发送给目标 Server。 - $this->connection->onConnect = function () use ($request) { - $this->connection->send($request->getBody()->getContents()); - $this->status = self::STATUS_ESTABLISHED; - }; - $this->request = $request; - - return $this; - } - - public function connect(): bool - { - $this->connection->connect(); - $this->status = $this->connection->getStatus(); - return $this->status <= 2; - } - - /** - * @throws \Exception - */ - public function reconnect(): bool - { - return $this->withRequest($this->request)->setMessageCallback($this->on_message)->setCloseCallback($this->on_close)->connect(); - } - - public function setMessageCallback($callable): WebSocketClientInterface - { - $this->status = $this->connection->getStatus(); - $this->on_message = $callable; - $this->connection->onMessage = function (AsyncTcpConnection $con, $data) use ($callable) { - $frame = FrameFactory::createTextFrame($data); - $callable($frame, $this); - }; - return $this; - } - - public function setCloseCallback($callable): WebSocketClientInterface - { - $this->status = $this->connection->getStatus(); - $this->on_close = $callable; - $this->connection->onClose = function (AsyncTcpConnection $con) use ($callable) { - $frame = FrameFactory::createCloseFrame(1000, ''); - $con->close(); - $callable($frame, $this, $con->getStatus(false)); - }; - return $this; - } - - public function send($data): bool - { - $this->connection->send($data); - return true; - } - - public function push($data): bool - { - return $this->send($data); - } - - public function getFd(): int - { - return $this->connection->id; - } - - public function isConnected(): bool - { - return $this->status === self::STATUS_ESTABLISHED; - } -} diff --git a/src/OneBot/global_defines.php b/src/OneBot/global_defines.php index ad684bb..e345f3f 100644 --- a/src/OneBot/global_defines.php +++ b/src/OneBot/global_defines.php @@ -13,7 +13,7 @@ use ZM\Logger\ConsoleLogger; const ONEBOT_VERSION = '12'; -const ONEBOT_LIBOB_VERSION = '0.4.4'; +const ONEBOT_LIBOB_VERSION = '0.5.0'; const ONEBOT_JSON = 1; const ONEBOT_MSGPACK = 2;