feat(onebot): share HTTP listeners with WebSocket clients
Add an opt-in HTTP server setting that accepts OneBot WebSocket connections on the same port and access token while preserving standalone WebSocket server configurations. Reuse the existing connection lifecycle for authentication, roles, events, heartbeat, streaming actions, token rotation, and shutdown. Expose the switch in WebUI and persist it through strict configuration validation and restore paths. Refs: #281
This commit is contained in:
12 files changed
+859
-158
No files matched your search
@@ -44,13 +44,14 @@ const httpServersTab: NetworkTabDescriptor<'httpServers'> = {
|
||||
summarize: (it: HttpServerNetwork) => {
|
||||
const host = it.host?.trim() || '0.0.0.0';
|
||||
const path = (it.path?.trim() || '/').replace(/^\/?/, '/');
|
||||
return `${host}:${it.port}${path}`;
|
||||
return `${host}:${it.port}${path}${it.enableWebSocket === true ? ' · WebSocket' : ''}`;
|
||||
},
|
||||
defaultEntry: (suffix): HttpServerNetwork => ({
|
||||
name: `http-${suffix}`,
|
||||
host: '0.0.0.0',
|
||||
port: 3000,
|
||||
path: '/',
|
||||
enableWebSocket: false,
|
||||
accessToken: genToken(),
|
||||
messageFormat: 'array',
|
||||
reportSelfMessage: false,
|
||||
|
||||
@@ -88,6 +88,7 @@ export function NodeEditDialog<K extends NetworkKind>(props: NodeEditDialogProps
|
||||
const patch = (changes: Partial<AnyAdapter<K>>) => setDraft({ ...draft, ...changes } as AnyAdapter<K>);
|
||||
|
||||
const isWs = kind === 'wsServers' || kind === 'wsClients';
|
||||
const isHttpServer = kind === 'httpServers';
|
||||
const role = ((draft as WsServerNetwork | WsClientNetwork).role ?? 'Universal') as WsRole;
|
||||
|
||||
return (
|
||||
@@ -155,6 +156,16 @@ export function NodeEditDialog<K extends NetworkKind>(props: NodeEditDialogProps
|
||||
|
||||
<Section caption="行为" delay={0.15}>
|
||||
<div className="divide-y divide-border/60">
|
||||
{isHttpServer && (
|
||||
<SettingRow label="启用 WebSocket" desc="复用当前 HTTP 端口和授权 Token 接收 WebSocket 连接">
|
||||
<ToggleSwitch
|
||||
value={(draft as HttpServerNetwork).enableWebSocket === true}
|
||||
onChange={(v) => patch({ enableWebSocket: v } as unknown as Partial<AnyAdapter<K>>)}
|
||||
ariaLabel="启用 WebSocket"
|
||||
/>
|
||||
</SettingRow>
|
||||
)}
|
||||
|
||||
<SettingRow label="消息格式" desc="数组为标准 OneBot 段,CQ 码为兼容字符串">
|
||||
<DropdownSelect
|
||||
className="w-32"
|
||||
|
||||
@@ -72,6 +72,7 @@ export interface HttpServerNetwork extends NetworkBase {
|
||||
host?: string;
|
||||
port: number;
|
||||
path?: string;
|
||||
enableWebSocket?: boolean;
|
||||
}
|
||||
|
||||
export interface HttpClientNetwork extends NetworkBase {
|
||||
|
||||
Reference in new issue
Block a user