add ws_socket function to get ws server socket

This commit is contained in:
crazywhalecc 2023-03-05 14:36:58 +08:00 committed by Jerry
parent 1a7c4607ee
commit a3c7ffa892

View File

@ -6,6 +6,7 @@ use Choir\Http\HttpFactory;
use OneBot\Driver\Coroutine\Adaptive;
use OneBot\Driver\Coroutine\CoroutineInterface;
use OneBot\Driver\Process\ExecutionResult;
use OneBot\Driver\Socket\WSServerSocketBase;
use OneBot\V12\Object\MessageSegment;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
@ -13,8 +14,10 @@ use Psr\SimpleCache\CacheInterface;
use ZM\Config\Environment;
use ZM\Config\ZMConfig;
use ZM\Container\ContainerHolder;
use ZM\Framework;
use ZM\Logger\ConsoleLogger;
use ZM\Middleware\MiddlewareHandler;
use ZM\Plugin\OneBot\BotMap;
use ZM\Schedule\Timer;
use ZM\Store\Database\DBException;
use ZM\Store\Database\DBQueryBuilder;
@ -327,3 +330,18 @@ function zm_http_response(int $status_code = 200, ?string $reason = null, array
{
return HttpFactory::createResponse($status_code, $reason, $headers, $body, $protocol);
}
/**
* 【助手函数】获取驱动的 WebSocket 服务器对应 Socket 操作对象
*
* @param int $flag 对应的 Server 端口标记
* @throws Exception
*/
function ws_socket(int $flag = 1): WSServerSocketBase
{
$a = Framework::getInstance()->getDriver()->getWSServerSocketByFlag($flag);
if ($a === null) {
throw new Exception('找不到目标的 server socket请检查 flag 值');
}
return $a;
}