// 网关连接设置的 localStorage 工具函数 // 原 SettingsModal 组件已删除(功能由 ConfigPage 的 Connection Tab 承担), // 仅保留 App.tsx 使用的 getGatewaySettings / buildWsUrl / GatewaySettings 工具函数 import { getAuthToken } from '../../api/client'; export interface GatewaySettings { host: string; port: number; } const DEFAULT_HOST = '127.0.0.1'; const DEFAULT_PORT = 19876; export function getGatewaySettings(): GatewaySettings { try { const host = localStorage.getItem('picobot-gateway-host') || DEFAULT_HOST; const portStr = localStorage.getItem('picobot-gateway-port'); const port = portStr ? parseInt(portStr, 10) : DEFAULT_PORT; return { host, port: isNaN(port) ? DEFAULT_PORT : port }; } catch { return { host: DEFAULT_HOST, port: DEFAULT_PORT }; } } export function buildWsUrl(settings: GatewaySettings): string { // HTTPS 页面下浏览器禁止混合内容(ws://),需使用 wss:// const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; const base = `${protocol}://${settings.host}:${settings.port}/ws`; // 远程访问时需要携带认证 token(浏览器原生 WebSocket 不支持自定义 header) const token = getAuthToken(); return token ? `${base}?token=${encodeURIComponent(token)}` : base; }