diff --git a/README.md b/README.md index bb5c1ce..4de5244 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ packService/ ├── backend/ # Egg.js 3(纯 API;MySQL + Redis) ├── frontend/ # Vite + Vue3 + TypeScript(用户端 SPA) ├── extension/ # Chrome MV3 扩展:注入第三方 WMS 页面,把运单号加工成溯源入口 -├── desktop/ # WPF 本机软件:HTTP 17300(查询/唤起/下载)+ WS 17301(拉通道/预览/云台)+ yuncang:// 启动协议 +├── desktop/ # WPF 本机软件:HTTP 16000(查询/唤起/下载)+ WS 16001(拉通道/预览/云台)+ yuncang:// 启动协议 └── AndroidStation/ # Android 设备端:UDP 48899 被桌面端发现 + TCP 8087 推送 USB 扫码结果 ``` @@ -18,7 +18,7 @@ packService/ | 前端 dev(Vite) | **7301** | `cd frontend && npm run dev` | | 前端 preview(dist) | **7302** | `cd frontend && npm run preview` | | 后端 dev | **7300** | `cd backend && npm run dev` | -| 本机软件(WPF,只监听 loopback) | **17300**(HTTP)/ **17301**(WebSocket) | `cd desktop && dotnet run`(详见 [`desktop/README.md`](desktop/README.md)) | +| 本机软件(WPF,只监听 loopback) | **16000**(HTTP)/ **16001**(WebSocket) | `cd desktop && dotnet run`(详见 [`desktop/README.md`](desktop/README.md)) | | 扩展自测页(可选) | **7310** | `npx --yes http-server extension/test -p 7310` | - 前端端口可用 `VITE_PORT=7303 npm run dev` 覆盖;`strictPort: true` → 端口被占用时**直接报错**,不会偷偷换端口(否则代理会对不上)。 diff --git a/backend/app/controller/web/nvr.js b/backend/app/controller/web/nvr.js index 82e3633..da6704f 100644 --- a/backend/app/controller/web/nvr.js +++ b/backend/app/controller/web/nvr.js @@ -12,7 +12,7 @@ function toId(value) { * web 用户端:**我的 NVR**(`/api/web/nvrs`) * * 拉取通道是由**前端**发起的两步: - * 1. 页面直接调本机软件 `POST http://localhost:17300/api/hik/channels`(带 host/port/user/password) + * 1. 页面直接调本机软件 `POST http://localhost:16000/api/hik/channels`(带 host/port/user/password) * 2. 用户勾选通道后,把结果 POST 到 `/api/web/nvrs/:id/channels` 落库 * 后端服务器**不接触设备**(设备在用户内网)。 */ diff --git a/backend/app/router.js b/backend/app/router.js index db68a63..31a6951 100644 --- a/backend/app/router.js +++ b/backend/app/router.js @@ -174,7 +174,7 @@ module.exports = (app) => { router.get('/api/web/nvrs/:id/credential', apiAuth, subjectAuth, controller.web.nvr.credential); // ---------- 视频接入:NVR / 摄像头 / 工作台(只碰本主体的数据;仅主体管理员)---------- - // 拉取通道 = 前端调本机软件(localhost:17300/api/hik/channels)→ 勾选 → POST /nvrs/:id/channels 落库 + // 拉取通道 = 前端调本机软件(localhost:16000/api/hik/channels)→ 勾选 → POST /nvrs/:id/channels 落库 router.get('/api/web/nvrs', apiAuth, subjectAuth, subjectAdmin, controller.web.nvr.index); router.post('/api/web/nvrs', apiAuth, subjectAuth, subjectAdmin, controller.web.nvr.create); router.get('/api/web/nvrs/:id', apiAuth, subjectAuth, subjectAdmin, controller.web.nvr.show); diff --git a/desktop/App.xaml.cs b/desktop/App.xaml.cs index 35840f9..18de38b 100644 --- a/desktop/App.xaml.cs +++ b/desktop/App.xaml.cs @@ -16,7 +16,7 @@ namespace YuncangTrace.LocalService; /// 应用入口,负责五件事: /// /// 1. **防多开**:全局互斥体;第二个实例把参数(可能是 `yuncang://open?code=xxx`)送给第一个实例后自己退出; -/// 2. **本机 HTTP 服务**(127.0.0.1:17300):登录前就起来,关窗口也不停(托盘里继续跑); +/// 2. **本机 HTTP 服务**(127.0.0.1:16000):登录前就起来,关窗口也不停(托盘里继续跑); /// 3. **托盘图标**:关窗口 = 缩到托盘;只有从托盘菜单「退出」才真正退出; /// 4. **登录**:有本地令牌先验证(`/api/web/me`),失效就弹登录窗;登录成功再开主窗口。 /// @@ -127,7 +127,7 @@ public partial class App : Application _server.ServerBaseUrlProvider = () => _settings.ServerBaseUrl; _server.LoginRequested += OnLoginRequested; - // 实时预览的 WebSocket 通道(17301):网页预览/满帧率窗口**只走 WS**,HTTP 17300 不再提供预览接口。 + // 实时预览的 WebSocket 通道(16001):网页预览/满帧率窗口**只走 WS**,HTTP 16000 不再提供预览接口。 // 会话池(HikPreviewService)与原生窗口共用同一个 HikStreamService,避免两套码流服务。 _stream = new HikStreamService(_hik); _preview = new HikPreviewService(_hik, _stream, new HikFfmpegService()); @@ -518,7 +518,7 @@ public partial class App : Application } /// - /// 托盘菜单「重启软件」:先让本进程退出(释放单实例互斥体与 17300 端口),2 秒后再拉起自己。 + /// 托盘菜单「重启软件」:先让本进程退出(释放单实例互斥体与 16000 端口),2 秒后再拉起自己。 /// 直接用 Process.Start 会撞上单实例检测(新进程把参数转发给正在退出的旧进程后就没了)。 /// 用 explorer 拉起:即使当前是管理员进程,新实例也会是**普通权限**(否则协议唤起会失效)。 /// diff --git a/desktop/README.md b/desktop/README.md index 797559e..5037e43 100644 --- a/desktop/README.md +++ b/desktop/README.md @@ -4,14 +4,14 @@ Windows 桌面端,用**前端 `/local` 公共页**和 **Chrome 插件**做对 - **登录页**:账号密码登录后端(`POST /api/web/auth/login`)拿 user JWT,令牌存本机; 下次启动先用 `/api/web/me` 验证,还有效就直接进主界面; -- 在 `127.0.0.1:17300` 起一个本机 HTTP 服务,浏览器里的页面直接查询本机数据; +- 在 `127.0.0.1:16000` 起一个本机 HTTP 服务,浏览器里的页面直接查询本机数据; - 注册 `yuncang://` 启动协议,网页可以「叫醒」本软件(前提是已安装); - **托盘图标**:关窗口只是缩到托盘(本机服务不能因关窗断掉),双击托盘恢复窗口, 右键菜单有「打开主界面 / 重启软件 / 退出」; - **界面不展示服务地址**:登录页和主界面都不显示后端地址 / 本机端口,它们属于内部实现细节; 后端地址由构建注入(`package.config.json` 的 `serverBaseUrl`),需要临时指向别处时用启动参数 `--server=http://x.x.x.x:7300`(只对本次运行生效,不写进界面)。 -- **防多开**:全局互斥体 + 命名管道 —— 第二个实例不会抢 17300 端口,而是把 +- **防多开**:全局互斥体 + 命名管道 —— 第二个实例不会抢 16000 端口,而是把 `yuncang://open?code=xxx` 转给已运行的实例(在托盘里也会被叫出来并直接查询),然后自己退出。 ``` @@ -23,9 +23,9 @@ desktop/ ├── LoginWindow.xaml / .xaml.cs # 账号 / 密码 / 记住账号 / 自动恢复登录(不展示服务地址) ├── MainWindow.xaml / .xaml.cs # 服务状态、测试查询、菜单、退出登录 └── Services/ - ├── LocalHttpServer.cs # 本机 HTTP(17300):查询 / 唤起登录 / 下载录像 + ├── LocalHttpServer.cs # 本机 HTTP(16000):查询 / 唤起登录 / 下载录像 ├── LoopbackHttpServer.cs # 回环 HTTP/1.1 服务端(TcpListener 自实现,不依赖 HTTP.sys) - ├── LocalWsServer.cs # WebSocket(17301):拉通道 / 预览推帧 / 云台 / 满帧率窗口 + ├── LocalWsServer.cs # WebSocket(16001):拉通道 / 预览推帧 / 云台 / 满帧率窗口 ├── OrderQueryService.cs # ★ 按运单号查数据(接真实数据源的地方) ├── ApiClient.cs # 登录 / 校验令牌(用到的全部后端接口) ├── SessionStore.cs # 登录态(%LOCALAPPDATA%\YuncangTrace\session.json) @@ -41,13 +41,13 @@ desktop/ | 场景 | 行为 | | --- | --- | -| 首次启动 | 先起本机服务(17300 HTTP + 17301 WS)与托盘,再弹登录页 → 登录成功才出主窗口 | +| 首次启动 | 先起本机服务(16000 HTTP + 16001 WS)与托盘,再弹登录页 → 登录成功才出主窗口 | | 启动时检查更新 | 进登录页的同时就开始查 `GET /download/version.json`(老版本用户卡在登录页也能收到提示)。**查到的版本不会塞进登录窗的模态循环**:登录窗还开着就先记下,等主窗口显示完再弹(`_pendingUpdate`)。以前直接盖在登录页上,会撞上「登录窗要关闭、但它挂着模态子窗」→ 父子窗一起被隐藏、两个模态循环互等,**主界面永远出不来**(日志停在 `已恢复登录` 之后,进程还在但没有任何窗口) | | 已有令牌 | 登录窗一闪而过:`/api/web/me` 通过就直接进主窗口;失效则清掉令牌留在登录页 | | 关窗口(X) | 隐藏到托盘,本机服务继续跑(第一次会冒一个气泡提示) | | 再次双击 exe / 点网页「启动本机软件」 | 不会开第二个:把 `yuncang://open?code=…` 通过命名管道转给已运行实例;**没带参数(双击快捷方式)也会转发一条 `--show`**,让已运行实例把主界面叫到前面 —— 以前这种情况什么都不发、第二个实例直接退出,表现就是「点图标没反应」 | | 托盘双击 / 右键「打开主界面」 | 恢复窗口 | -| 托盘右键「重启软件」 | 等 2 秒后拉起新进程(先退出才能释放单实例互斥体与 17300) | +| 托盘右键「重启软件」 | 等 2 秒后拉起新进程(先退出才能释放单实例互斥体与 16000) | | 「退出登录」 | 清令牌 → 关闭主窗口 → 回到登录页(取消登录则退出程序) | | 网页请求唤起登录(`POST /api/activate-login`) | 未登录:登录窗弹到最前;已登录:主界面弹到最前(不影响本机服务) | | 托盘右键「退出」 | 真正退出(dispose 托盘与本机服务) | @@ -379,7 +379,7 @@ cd desktop\installer 2. 关掉正在运行的软件(单文件自解压出来的真实进程); 3. 带 `YUNCANG_AUTO_UPDATE=1` 启动**旧版本**(更新窗口出现后自动下载,不用手点); 4. 轮询 `%LOCALAPPDATA%\Programs\YuncangTrace\*.exe` 的 `ProductVersion`,直到变成目标版本; -5. 检查本机服务 17300 是否有响应、进程是否已恢复。 +5. 检查本机服务 16000 是否有响应、进程是否已恢复。 输出形如: @@ -391,7 +391,7 @@ cd desktop\installer [6.1s] 安装版本 = [10.4s] 安装版本 = 1.0.7+d32656a… ✔ 自动更新完成:1.0.6 → 1.0.7(耗时 10.4s) -✔ 本机服务 17300 有响应(HTTP 401) +✔ 本机服务 16000 有响应(HTTP 401) ✔ 软件进程已恢复(PID 12024) ``` @@ -403,12 +403,12 @@ cd desktop\installer | 端口 | 协议 | 用途 | | --- | --- | --- | -| **17300** | HTTP | 运单查询 / 唤起登录 / 按运单下载录像(低频、无状态) | -| **17301** | WebSocket | 拉通道 / 实时预览(推 JPEG 帧)/ 云台 / 满帧率窗口(预览相关全在这里) | +| **16000** | HTTP | 运单查询 / 唤起登录 / 按运单下载录像(低频、无状态) | +| **16001** | WebSocket | 拉通道 / 实时预览(推 JPEG 帧)/ 云台 / 满帧率窗口(预览相关全在这里) | -### HTTP 17300(前端 `/local` 页用的就是这两个) +### HTTP 16000(前端 `/local` 页用的就是这两个) -服务固定监听 `http://localhost:17300`(端口写在前端页面与插件里)。 +服务固定监听 `http://localhost:16000`(端口写在前端页面与插件里)。 `LoopbackHttpServer` 直接监听 **127.0.0.1 和 ::1**,所以 `localhost` / `127.0.0.1` 两种写法都能连 (前端改 `VITE_LOCAL_SERVICE` 时不会碰到「回 400」)。请求的 `Host` 不是回环地址会被直接断开。 @@ -416,7 +416,7 @@ cd desktop\installer > 或者卡在 STOP_PENDING 时,`HttpListener.Start()` 会抛 `句柄无效(6)`,HTTP 与 WS 会**同时**起不来 > (2026-10-23 升级 1.0.113 后的现场故障就是它)。自建 TcpListener 不需要 HTTP.sys / urlacl / 管理员权限。 -浏览器直接打开 会看到一个说明页(列了接口,方便排查)。 +浏览器直接打开 会看到一个说明页(列了接口,方便排查)。 | 方法 | 路径 | 说明 | | --- | --- | --- | @@ -424,10 +424,10 @@ cd desktop\installer | POST | `/api/activate-login` | 把本机软件的**登录窗叫到前台**(已登录时把主界面叫到前台)。网页收到 `need-login` 时自动调它 | | POST | `/api/playback/download` | 按运单下载录像(存到本机设置目录) | -> ⚠️ 以前的海康接口(`/api/hik/channels`、`/api/hik/preview*`、`/api/hik/ptz*`)**已全部迁移到 WS 17301**, +> ⚠️ 以前的海康接口(`/api/hik/channels`、`/api/hik/preview*`、`/api/hik/ptz*`)**已全部迁移到 WS 16001**, > HTTP 侧不再提供(访问会得到 404「接口不存在」)。前端 `api/localWs.ts` 是唯一调用入口。 -### WebSocket 17301(预览 / 云台 / 拉通道) +### WebSocket 16001(预览 / 云台 / 拉通道) 一条连接可同时推多路画面(一条工作台合成画面 4 路没问题)。文本请求 `{id, action, ...}`, 回复 `{id, ok, data | message}`;二进制帧 = `[1 字节 sid 长度][sid ASCII][JPEG]`。 @@ -447,7 +447,7 @@ cd desktop\installer > `start_preview` / `get_channels` / `open_window` / `ptz*` 在服务端**并发执行**,不会把 > 「停止预览 / 云台停转」堵在消息循环后面;云台命令之间按连接串行化,保证「开始转 → 停」不乱序。 > -> 端口可用 `YUNCANG_LOCAL_WS_PORT` 覆盖;前端用 `VITE_LOCAL_WS` 覆盖默认 `ws://127.0.0.1:17301/`。 +> 端口可用 `YUNCANG_LOCAL_WS_PORT` 覆盖;前端用 `VITE_LOCAL_WS` 覆盖默认 `ws://127.0.0.1:16001/`。 #### 预览延迟(子码流 / 主码流是两条完全不同的链路) @@ -503,9 +503,9 @@ cd desktop\installer 示例: ```powershell -curl http://localhost:17300/api/query/321408064481776 -curl http://localhost:17300/api/query/ # 400 bad-request,但带着登录状态 -curl -X POST http://localhost:17300/api/activate-login +curl http://localhost:16000/api/query/321408064481776 +curl http://localhost:16000/api/query/ # 400 bad-request,但带着登录状态 +curl -X POST http://localhost:16000/api/activate-login ``` 为什么唤起登录用 **POST**:GET 会被浏览器/聊天工具的链接预取误触发,POST 不会。 @@ -569,7 +569,7 @@ reg query "HKCU\Software\Classes\yuncang\shell\open\command" 1. 点击 → 隐藏 iframe 触发 `yuncang://open?code=xxx`(不能导航当前页,否则协议没注册会变成错误页); 2. **判断到底成没成,不看页面焦点,看本机服务在不在**:协议触发后每 0.7s 探测一次 - `http://localhost:17300/api/query/`(任何 HTTP 响应都算成功,扩展带 host 权限,不受页面 CSP 影响); + `http://localhost:16000/api/query/`(任何 HTTP 响应都算成功,扩展带 host 权限,不受页面 CSP 影响); - 探测到 → 什么也不做(软件本来就在跑时也能正确判定,不会误报); - 8 秒都探测不到 → 认为没起来,右下角弹出兜底卡片: - **在网页中查看** → 打开插件设置里的「唤不起时的兜底页」(默认 `http://localhost:7301/local?code={code}`, @@ -741,7 +741,7 @@ xstack 只做一遍。实测(本机 i5-12400 + UHD 730,机器同时在跑别 | 报端口被占用(`AddressAlreadyInUse`) | 已经开了一个实例(单实例会把参数转过去);检查任务管理器里的残留进程 | | 双击图标没反应 / 主界面打不开,托盘图标还在 | 1.0.134 起:再次启动会把已运行实例的主界面叫到前面(托盘双击也行)。更老的版本点了没反应是正常的(第二个实例直接退出),从托盘打开即可 | | 升级后主界面仍然出不来 | 看日志最后几行:停在 `准备显示更新窗口…` 之后就是老版本的「更新窗盖在登录窗上」死锁,装新版本即可;有 `[app] 主窗口没建:server=… session=… api=…` 说明登录态没建立 | -| 网页提示服务不可用,但软件在跑 | 先用浏览器直接打开 `http://localhost:17300/api/query/`(会回 400 但带登录状态):打不开→防火墙/端口;打得开→多半是 CORS 头没回。预览类问题则看 `ws://127.0.0.1:17301/` 能不能打开(直接浏览器访问应该返回一小段 JSON) | +| 网页提示服务不可用,但软件在跑 | 先用浏览器直接打开 `http://localhost:16000/api/query/`(会回 400 但带登录状态):打不开→防火墙/端口;打得开→多半是 CORS 头没回。预览类问题则看 `ws://127.0.0.1:16001/` 能不能打开(直接浏览器访问应该返回一小段 JSON) | | 点网页「启动本机软件」没反应 | 协议没注册(界面看「启动协议」状态);或浏览器拦了自动跳转(必须用户点击) | | 唤起时弹「You must install .NET Desktop Runtime」 | 唤起的是 `bin\Debug` 这类 framework-dependent 的 exe(拿不到 `DOTNET_ROOT`)。用自包含发布产物,并让它启动一次以校正注册表 | | 改了协议名 | 注册表重注册 + 前端 `VITE_APP_PROTOCOL` 同步 + 插件目标地址同步 | diff --git a/desktop/Services/Agent/AgentHost.cs b/desktop/Services/Agent/AgentHost.cs index 30fa015..21c49e3 100644 --- a/desktop/Services/Agent/AgentHost.cs +++ b/desktop/Services/Agent/AgentHost.cs @@ -162,7 +162,7 @@ public static class AgentHost await scan.StartAsync().ConfigureAwait(false); scan.StartDiscovery(); // 常驻发现:设备 DHCP 换 IP 时能自己重连 - // 自检要尽早:worker 一就绪,局域网询问才有应答(UDP 17310)。 + // 自检要尽早:worker 一就绪,局域网询问才有应答(UDP 16100)。 // 以前延后 20 秒,导致「刚启动/刚更新完」这段时间本机查询探测不到设备管理服务, // 白白退化成云端中转 —— 而云任务反过来才把 worker 拉起来,形成恶性循环。 _ = Task.Run(async () => diff --git a/desktop/Services/Agent/HikWorkerProtocol.cs b/desktop/Services/Agent/HikWorkerProtocol.cs index 910b82f..2a74800 100644 --- a/desktop/Services/Agent/HikWorkerProtocol.cs +++ b/desktop/Services/Agent/HikWorkerProtocol.cs @@ -113,7 +113,8 @@ public static class HikWorkerOps } /// -/// 局域网发现用的端口(与 17300/17301 同族,但独立进程独立端口)。 +/// 局域网发现用的端口(与桌面端本机端口 16000/16001 同段,但独立进程独立端口)。 +/// 取 161xx 而不是 160xx:16010 常被向日葵等远控软件占用。 /// /// - :收桌面端的广播询问(**询问-应答**,不是主动公告); /// - :取流健康端点,桌面端用一次 TCP 连接就能判定"是否同 LAN"。 @@ -121,10 +122,10 @@ public static class HikWorkerOps public static class HikWorkerPorts { /// 可用 YUNCANG_EDGE_UDP_PORT 临时覆盖(同机并行跑两个实例测试时用) - public static int UdpQuery { get; } = Resolve("YUNCANG_EDGE_UDP_PORT", 17310); + public static int UdpQuery { get; } = Resolve("YUNCANG_EDGE_UDP_PORT", 16100); /// 可用 YUNCANG_EDGE_HTTP_PORT 临时覆盖 - public static int Http { get; } = Resolve("YUNCANG_EDGE_HTTP_PORT", 17311); + public static int Http { get; } = Resolve("YUNCANG_EDGE_HTTP_PORT", 16101); /// /// 监听地址。默认 0.0.0.0(局域网可发现可直连); diff --git a/desktop/Services/Agent/ServiceInstaller.cs b/desktop/Services/Agent/ServiceInstaller.cs index 0196a25..9dff85a 100644 --- a/desktop/Services/Agent/ServiceInstaller.cs +++ b/desktop/Services/Agent/ServiceInstaller.cs @@ -2,6 +2,7 @@ using System; using System.ComponentModel; using System.Diagnostics; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Text.Json; using System.Threading; @@ -359,6 +360,13 @@ public static class ServiceInstaller return new HelperResult { Ok = true, Message = "后台服务已卸载" }; } + /// 旧版本用 17xxx 端口时的防火墙规则名(升级时清掉,别继续占着别人项目的端口) + private static readonly string[] LegacyFirewallRuleNames = + { + "YuncangTrace Edge (TCP 17311)", + "YuncangTrace Edge (UDP 17310)", + }; + /// /// 放行局域网发现端口(TCP 取流健康端点 + UDP 询问应答)。 /// @@ -370,8 +378,14 @@ public static class ServiceInstaller /// private static void EnsureFirewallRules() { - AddFirewallRule("YuncangTrace Edge (TCP 17311)", "TCP", "17311"); - AddFirewallRule("YuncangTrace Edge (UDP 17310)", "UDP", "17310"); + AddFirewallRule("YuncangTrace Edge (TCP 16101)", "TCP", "16101"); + AddFirewallRule("YuncangTrace Edge (UDP 16100)", "UDP", "16100"); + + // 老版本(17xxx)装过的规则名带端口号,升级后不会自动消失,这里顺手清掉 + foreach (var name in LegacyFirewallRuleNames) + { + RunTool("netsh.exe", "advfirewall", "firewall", "delete", "rule", $"name={name}"); + } } private static void AddFirewallRule(string name, string protocol, string port) @@ -393,7 +407,8 @@ public static class ServiceInstaller private static void RemoveFirewallRules() { - foreach (var name in new[] { "YuncangTrace Edge (TCP 17311)", "YuncangTrace Edge (UDP 17310)" }) + foreach (var name in new[] { "YuncangTrace Edge (TCP 16101)", "YuncangTrace Edge (UDP 16100)" } + .Concat(LegacyFirewallRuleNames)) { RunTool("netsh.exe", "advfirewall", "firewall", "delete", "rule", $"name={name}"); } diff --git a/desktop/Services/Hik/HikPreviewService.cs b/desktop/Services/Hik/HikPreviewService.cs index c3ee9c3..a008a1b 100644 --- a/desktop/Services/Hik/HikPreviewService.cs +++ b/desktop/Services/Hik/HikPreviewService.cs @@ -6,7 +6,7 @@ using System.Threading; namespace YuncangTrace.LocalService.Services.Hik; /// -/// 预览会话管理(实时预览唯一入口,由 WS 17301 驱动)。 +/// 预览会话管理(实时预览唯一入口,由 WS 16001 驱动)。 /// /// 为什么要有「会话」这层: /// - 网页预览时凭据只发一次(走 WS 的 start_preview),之后每帧按 sid 区分, diff --git a/desktop/Services/LocalHttpServer.cs b/desktop/Services/LocalHttpServer.cs index 04aeb76..6f1efa2 100644 --- a/desktop/Services/LocalHttpServer.cs +++ b/desktop/Services/LocalHttpServer.cs @@ -26,13 +26,13 @@ namespace YuncangTrace.LocalService.Services; /// public sealed class LocalHttpServer : IDisposable { - /// 监听端口(前端/插件里写死的 17300;可用 YUNCANG_LOCAL_PORT 临时覆盖,便于自测) + /// 监听端口(前端/插件里写死的 16000;可用 YUNCANG_LOCAL_PORT 临时覆盖,便于自测) public static int Port { get; } = ResolvePort(); private static int ResolvePort() { var raw = Environment.GetEnvironmentVariable("YUNCANG_LOCAL_PORT"); - return int.TryParse(raw, out var port) && port is > 0 and < 65536 ? port : 17300; + return int.TryParse(raw, out var port) && port is > 0 and < 65536 ? port : 16000; } private readonly LoopbackHttpServer _listener; @@ -140,7 +140,7 @@ public sealed class LocalHttpServer : IDisposable return; } - // ⚠️ 海康相关(拉通道 / 实时预览 / 云台 / 满帧率窗口)已全部迁到 WS 17301(LocalWsServer),这里不再提供。 + // ⚠️ 海康相关(拉通道 / 实时预览 / 云台 / 满帧率窗口)已全部迁到 WS 16001(LocalWsServer),这里不再提供。 // 按运单下载录像:POST /api/playback/download { code } // 网页查件页(/local?code=)用 —— 任何装了本机软件的电脑都能下,存到本机设置的目录 @@ -152,12 +152,12 @@ public sealed class LocalHttpServer : IDisposable if (!request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase)) { - // 只剩 GET 接口了;旧的 POST /api/hik/* 会走到这里(预览/云台/拉通道已迁到 WS 17301) + // 只剩 GET 接口了;旧的 POST /api/hik/* 会走到这里(预览/云台/拉通道已迁到 WS 16001) await WriteJsonAsync(response, 404, new { ok = false, state = "not-found", - message = "接口不存在(拉通道 / 预览 / 云台已迁到 WebSocket 17301)", + message = "接口不存在(拉通道 / 预览 / 云台已迁到 WebSocket 16001)", }).ConfigureAwait(false); return; } @@ -238,13 +238,13 @@ public sealed class LocalHttpServer : IDisposable

云仓视频溯源软件(本机服务)

-

服务运行中,只监听本机(127.0.0.1:17300)。

+

服务运行中,只监听本机(127.0.0.1:16000)。

  • /api/query/{运单号} 查询(同时返回服务/登录状态;没登录回 401)
  • POST /api/activate-login 把登录窗叫到前台
  • POST /api/playback/download 按运单下载录像
-

拉通道 / 实时预览 / 云台 / 满帧率窗口走 WebSocket:ws://127.0.0.1:17301

+

拉通道 / 实时预览 / 云台 / 满帧率窗口走 WebSocket:ws://127.0.0.1:16001

"""; await WriteHtmlAsync(response, 200, html).ConfigureAwait(false); return; diff --git a/desktop/Services/LocalWsServer.cs b/desktop/Services/LocalWsServer.cs index 5228df6..354f260 100644 --- a/desktop/Services/LocalWsServer.cs +++ b/desktop/Services/LocalWsServer.cs @@ -13,7 +13,7 @@ using YuncangTrace.LocalService.Services.Hik; namespace YuncangTrace.LocalService.Services; /// -/// 本机 WebSocket 服务(只监听 127.0.0.1,默认端口 17301) +/// 本机 WebSocket 服务(只监听 127.0.0.1,默认端口 16001) /// /// 给网页的实时预览 / 云台 / 拉通道用:以前走 HTTP(先 POST 建会话、再用 <img> 拉 MJPEG), /// 跨域/代理/多标签场景下都要多一次请求,而且浏览器对 MJPEG 的复用不总是如意;WS 下一条连接可以: @@ -40,7 +40,7 @@ public sealed class LocalWsServer : IDisposable private static int ResolvePort() { var raw = Environment.GetEnvironmentVariable("YUNCANG_LOCAL_WS_PORT"); - return int.TryParse(raw, out var port) && port is > 0 and < 65536 ? port : 17301; + return int.TryParse(raw, out var port) && port is > 0 and < 65536 ? port : 16001; } /// RFC 6455 规定的握手固定串 @@ -121,7 +121,7 @@ public sealed class LocalWsServer : IDisposable private async Task HandleContextAsync(LocalHttpRequest request, LocalHttpResponse response) { - // 非 WS 请求:给网页/排障一个轻量探活(浏览器直接打开 ws://127.0.0.1:17301/ 就看这个) + // 非 WS 请求:给网页/排障一个轻量探活(浏览器直接打开 ws://127.0.0.1:16001/ 就看这个) if (!request.IsWebSocketRequest) { await WriteProbeAsync(response).ConfigureAwait(false); diff --git a/desktop/Services/SingleInstance.cs b/desktop/Services/SingleInstance.cs index c2255aa..25063e3 100644 --- a/desktop/Services/SingleInstance.cs +++ b/desktop/Services/SingleInstance.cs @@ -11,7 +11,7 @@ namespace YuncangTrace.LocalService.Services; /// 单实例 + 参数转发(命名管道) /// /// 场景:窗口已经开着,用户又点了一次 WMS 页面上的「查看打包视频」→ 系统按协议再启动一次本程序。 -/// 这时第二个实例**不应该**去抢 17300 端口,而是把 `yuncang://open?code=xxx` 通过管道送给第一个实例, +/// 这时第二个实例**不应该**去抢 16000 端口,而是把 `yuncang://open?code=xxx` 通过管道送给第一个实例, /// 由它把窗口激活并查询那个运单号。 /// public sealed class SingleInstance : IDisposable diff --git a/desktop/YuncangTrace.LocalService.csproj b/desktop/YuncangTrace.LocalService.csproj index bf49e48..95517c2 100644 --- a/desktop/YuncangTrace.LocalService.csproj +++ b/desktop/YuncangTrace.LocalService.csproj @@ -42,7 +42,7 @@ http://127.0.0.1:7300 https://packs.example.com - 1.0.161 + 1.0.162 云仓视频溯源软件 云仓 云仓视频溯源软件(本机服务) diff --git a/desktop/installer/test-update.ps1 b/desktop/installer/test-update.ps1 index 52643e2..1fa1bd9 100644 --- a/desktop/installer/test-update.ps1 +++ b/desktop/installer/test-update.ps1 @@ -12,7 +12,7 @@ 3. 关掉正在运行的软件(含单文件自解压出来的真实进程); 4. 启动**旧版本**,并设置 YUNCANG_AUTO_UPDATE=1(更新窗口出现后自动开始下载); 5. 轮询安装目录的 ProductVersion,直到变成目标版本(或超时); - 6. 检查本机服务 17300 是否有响应、进程是否已恢复。 + 6. 检查本机服务 16000 是否有响应、进程是否已恢复。 .PARAMETER TimeoutSeconds 等更新完成的最长时间,默认 180 秒。 @@ -112,16 +112,16 @@ $probeDeadline = (Get-Date).AddSeconds(60) $localCode = $null $processes = @() while ((Get-Date) -lt $probeDeadline) { - $localCode = & curl.exe -s -o NUL -w "%{http_code}" --max-time 3 "http://127.0.0.1:17300/api/query/" + $localCode = & curl.exe -s -o NUL -w "%{http_code}" --max-time 3 "http://127.0.0.1:16000/api/query/" $processes = @(Get-CimInstance Win32_Process | Where-Object { $_.Name -like '*Yuncang*' }) if ($processes.Count -gt 0 -and $localCode -and $localCode -ne '000') { break } Start-Sleep -Seconds 3 } if ($localCode -and $localCode -ne '000') { - Write-Host "✔ 本机服务 17300 有响应(HTTP $localCode)" -ForegroundColor Green + Write-Host "✔ 本机服务 16000 有响应(HTTP $localCode)" -ForegroundColor Green } else { - Write-Host "✘ 本机服务 17300 无响应" -ForegroundColor Red + Write-Host "✘ 本机服务 16000 无响应" -ForegroundColor Red } if ($processes.Count -gt 0) { diff --git a/extension/README.md b/extension/README.md index 0923376..8570946 100644 --- a/extension/README.md +++ b/extension/README.md @@ -265,11 +265,11 @@ npx --yes http-server extension/test -p 7310 # → http://127.0.0.1:7310/wms | `storage` | 存下发下来的配置(优先 `storage.sync`,超 8KB 自动退到 `storage.local`) | | `alarms` | 每 5 分钟定时拉配置(MV3 的 service worker 会被回收,不能用 `setInterval`) | | `host_permissions: https://pack.wms.gztbyc.com/*` | 拉 `GET /api/web/extension/config` | -| `host_permissions: http(s)://localhost:17300/*` | 探测本机软件是否在跑(协议唤起兜底) | +| `host_permissions: http(s)://localhost:16000/*` | 探测本机软件是否在跑(协议唤起兜底) | | content script `matches: http(s)://*/*` | 需要注入任意第三方系统,无法预先枚举域名 | - 不请求 `tabs` / `scripting` / `cookies`,**不读页面 cookie**;唯一的出站请求就是上面那个配置接口 - (以及本机 17300 的探测)。点击只是把算好的 URL 交给 `chrome.tabs.create` / `chrome.windows.create`。 + (以及本机 16000 的探测)。点击只是把算好的 URL 交给 `chrome.tabs.create` / `chrome.windows.create`。 - 注入走隔离世界(ISOLATED),不注入页面上下文,不受宿主页 CSP 影响。 - 想收窄范围:改 `manifest.json` 里 `content_scripts[0].matches` 为具体域名(如 `https://wms.wms.gztbyc.com/*`), 重新加载扩展即可;规则层面的范围由「生效站点」控制。 diff --git a/extension/STORE-SUBMISSION.md b/extension/STORE-SUBMISSION.md index ce4cab5..4f1692c 100644 --- a/extension/STORE-SUBMISSION.md +++ b/extension/STORE-SUBMISSION.md @@ -117,7 +117,7 @@ Policy: https://pack.wms.gztbyc.com/extension-privacy.html | `alarms` | 每 5 分钟拉取一次配置,保证管理员改完尽快生效。 | Periodic (5 min) refresh of the read-only configuration. | | `content_scripts` 全站(`http://*/*`, `https://*/*`) | 客户的 WMS 域名/内网地址无法预知,需在页面上识别运单号;实际只在白名单站点工作,其它站点立即退出且不读取 DOM。 | Customers' WMS hosts cannot be enumerated in advance. Matching only runs on an allow-listed site; otherwise the script exits without reading the DOM. | | `host_permissions: https://pack.wms.gztbyc.com/*` | 只用于拉取只读配置与最新客户端版本信息。 | Fetches read-only configuration and the latest client version info. | -| `host_permissions: http://localhost:17300/*`、`http://127.0.0.1:17300/*` | 与本机安装的桌面客户端通信(判断是否安装、传递运单号)。 | Talks to the desktop client installed on the same machine (availability probe and tracking-number hand-off). | +| `host_permissions: http://localhost:16000/*`、`http://127.0.0.1:16000/*` | 与本机安装的桌面客户端通信(判断是否安装、传递运单号)。 | Talks to the desktop client installed on the same machine (availability probe and tracking-number hand-off). | **数据使用声明(Data usage 表单)**:全部选「不收集」—— 只做本地匹配;不收集浏览历史、页面内容、个人身份信息、位置、财务信息; @@ -166,7 +166,7 @@ Policy: https://pack.wms.gztbyc.com/extension-privacy.html ## 8. 提交时逐字段对照表(Package 上传之后) 上传包后,`Packages` 那张表应显示:`YuncangTraceExtension-.zip`、版本号、**Status = Complete**、 -权限识别为 `storage, alarms, http://localhost:17300/*, http://127.0.0.1:17300/*, https://pack.wms.gztbyc.com/*`。 +权限识别为 `storage, alarms, http://localhost:16000/*, http://127.0.0.1:16000/*, https://pack.wms.gztbyc.com/*`。 > `Languages in package:` 为空是**正常**的(包内没有 `_locales` 多语言资源);商店页面的语言在 > Store listing 里单独选,不影响审核。 diff --git a/extension/manifest.json b/extension/manifest.json index 071c680..3361466 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -15,8 +15,8 @@ "permissions": ["storage", "alarms"], "host_permissions": [ - "http://localhost:17300/*", - "http://127.0.0.1:17300/*", + "http://localhost:16000/*", + "http://127.0.0.1:16000/*", "https://pack.wms.gztbyc.com/*" ], diff --git a/extension/src/background.js b/extension/src/background.js index 169ee1a..cb83f94 100644 --- a/extension/src/background.js +++ b/extension/src/background.js @@ -73,13 +73,13 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { * * 为什么不去看「页面有没有失焦」:软件已经在跑时,协议只是把参数转给已有实例, * 窗口可能不抢焦点;冷启动也可能超过几秒 —— 两种都会误报「没打开」。 - * 但软件只要在跑就一定监听 17300,**任何 HTTP 响应(200/400/401)都算成功**。 + * 但软件只要在跑就一定监听 16000,**任何 HTTP 响应(200/400/401)都算成功**。 */ async function probeLocalService(timeoutMs = 1500) { const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeoutMs); try { - const res = await fetch('http://localhost:17300/api/query/', { + const res = await fetch('http://localhost:16000/api/query/', { cache: 'no-store', signal: controller.signal, }); diff --git a/extension/src/content.js b/extension/src/content.js index 3353722..4486aac 100644 --- a/extension/src/content.js +++ b/extension/src/content.js @@ -248,7 +248,7 @@ window.addEventListener('blur', onLeave); document.addEventListener('visibilitychange', onLeave); - // 更可靠的判据:本机服务是否有响应(软件在跑就一定监听 17300)。 + // 更可靠的判据:本机服务是否有响应(软件在跑就一定监听 16000)。 // 仅看「页面失焦」会误报:软件本来就在跑时只是转发参数,窗口不一定抢焦点。 const timer = setInterval(async () => { if (settled) return; diff --git a/frontend/.env.production b/frontend/.env.production index c2b6c09..fca5767 100644 --- a/frontend/.env.production +++ b/frontend/.env.production @@ -3,10 +3,10 @@ # 生产由后端同源托管页面与 /api,所以 API_BASE 留空即可。 VITE_API_BASE= -# 本机桌面端约定:yuncang:// 协议 + HTTP 17300 + WebSocket 17301 +# 本机桌面端约定:yuncang:// 协议 + HTTP 16000 + WebSocket 16001 VITE_APP_PROTOCOL=yuncang -VITE_LOCAL_SERVICE=http://localhost:17300 -VITE_LOCAL_WS=ws://127.0.0.1:17301/ +VITE_LOCAL_SERVICE=http://localhost:16000 +VITE_LOCAL_WS=ws://127.0.0.1:16001/ # /download/version.json 取不到时的兜底安装包地址(留空则只依赖 version.json) VITE_SOFTWARE_DOWNLOAD_URL= diff --git a/frontend/public/extension-privacy.html b/frontend/public/extension-privacy.html index 2ea0241..fd73bce 100644 --- a/frontend/public/extension-privacy.html +++ b/frontend/public/extension-privacy.html @@ -53,7 +53,7 @@ 匹配到的运单号 - 当你点击该运单号时,运单号会通过本机回环地址 http://localhost:17300 + 当你点击该运单号时,运单号会通过本机回环地址 http://localhost:16000 交给同一台电脑上已安装的「云仓视频溯源」桌面客户端(不经过互联网)。 若未安装客户端,则按管理员配置的模板在浏览器里打开溯源页面。 @@ -88,7 +88,7 @@ 因此需要在页面上识别运单号。只有在管理员配置的站点白名单内才会工作; 其它站点上脚本立即退出,不读取也不改动页面。 https://pack.wms.gztbyc.com拉取上述只读配置与客户端版本信息。 - http://localhost:17300、http://127.0.0.1:17300 + http://localhost:16000、http://127.0.0.1:16000 与本机安装的桌面客户端通信(判断是否已安装、传递运单号)。 diff --git a/frontend/src/api/local.ts b/frontend/src/api/local.ts index 23a5a7c..12a9d1a 100644 --- a/frontend/src/api/local.ts +++ b/frontend/src/api/local.ts @@ -1,19 +1,19 @@ /** - * 本机软件 HTTP 客户端(17300) + * 本机软件 HTTP 客户端(16000) * * 现在 HTTP 只负责**低频、无状态**的事,剩三个接口: * - `GET /api/query/{code}` 查信息,**同时返回服务/登录状态**(没登录回 401 `state:need-login`) * - `POST /api/activate-login` 把本机软件的登录窗/主界面叫到前台 * - `POST /api/playback/download` 按运单下载录像 * - * ⚠️ 海康相关(拉通道 / 实时预览 / 云台 / 满帧率窗口)**全部走 WebSocket 17301**, + * ⚠️ 海康相关(拉通道 / 实时预览 / 云台 / 满帧率窗口)**全部走 WebSocket 16001**, * 见 {@link ./localWs.ts};这里只留通道列表的类型,供那边的返回值复用。 * * 为什么不再单独做探活接口:探活通过 ≠ 真正查询时软件还在(用户可能中途退了), * 两次请求之间的状态可能已经变了。合并成一个接口后,页面只发一次请求就能决定 * 「展示结果」还是「提示可以唤起」。 * - * ⚠️ 这是**跨域**请求(页面同源是我们的站点,目标是 localhost:17300): + * ⚠️ 这是**跨域**请求(页面同源是我们的站点,目标是 localhost:16000): * 本机软件必须允许 CORS(`Access-Control-Allow-Origin` 放行站点来源),否则浏览器会拦掉, * 表现和「软件没启动」一样 —— 页面统一提示「服务暂不可用」。 * @@ -21,7 +21,7 @@ */ /** 本机服务地址(去掉末尾斜杠) */ -export const LOCAL_BASE = ((import.meta.env.VITE_LOCAL_SERVICE as string | undefined) || 'http://localhost:17300') +export const LOCAL_BASE = ((import.meta.env.VITE_LOCAL_SERVICE as string | undefined) || 'http://localhost:16000') .replace(/\/+$/, ''); /** 本机服务返回非 2xx / 超时 / 跨域失败时抛它 */ diff --git a/frontend/src/api/localWs.ts b/frontend/src/api/localWs.ts index 6ca1653..c463d7d 100644 --- a/frontend/src/api/localWs.ts +++ b/frontend/src/api/localWs.ts @@ -1,7 +1,7 @@ /** * 本机软件的 WebSocket 通道(实时预览 / 云台 / 拉通道) * - * 端口约定:本机桌面端 `LocalWsServer` 监听 **17301**(可用 `VITE_LOCAL_WS` 覆盖)。 + * 端口约定:本机桌面端 `LocalWsServer` 监听 **16001**(可用 `VITE_LOCAL_WS` 覆盖)。 * * 协议(服务端见 `desktop/Services/LocalWsServer.cs`): * - 文本:`{ id, action, ... }` → 回复 `{ id, ok, data | message }` @@ -16,7 +16,7 @@ import { launchApp } from '@/api/local'; import type { HikChannelsPayload } from '@/api/local'; /** WS 地址 */ -export const LOCAL_WS = (import.meta.env.VITE_LOCAL_WS as string | undefined) || 'ws://127.0.0.1:17301/'; +export const LOCAL_WS = (import.meta.env.VITE_LOCAL_WS as string | undefined) || 'ws://127.0.0.1:16001/'; /** 云台连续动作(方向 / 变倍 / 聚焦 / 光圈 / 自动扫描) */ export type WsPtzCommand = diff --git a/frontend/src/components/LocalServiceGate.vue b/frontend/src/components/LocalServiceGate.vue index 9ad62e3..c8811a2 100644 --- a/frontend/src/components/LocalServiceGate.vue +++ b/frontend/src/components/LocalServiceGate.vue @@ -2,7 +2,7 @@ /** * 「连接不上本机软件」统一提示窗 * - * 网页的拉通道 / 实时预览 / 云台都依赖本机软件(HTTP 17300 + WebSocket 17301), + * 网页的拉通道 / 实时预览 / 云台都依赖本机软件(HTTP 16000 + WebSocket 16001), * 浏览器没法判断到底是「没安装」还是「装了没启动」,所以统一弹这个: * - **启动本机软件**:用 `yuncang://` 协议唤起,再等 WS 连上(连上就 emit `ready` 让调用方重试); * - **立即下载**:后端 `version.json` 里的最新安装包(拿不到就退回环境变量兜底地址)。 @@ -25,7 +25,7 @@ const props = withDefaults(defineProps<{ message?: string; /** 唤起后最多等多久(毫秒) */ waitMs?: number; - /** 探活方式:ws = WebSocket 17301(预览类);http = HTTP 17300 根路径(查件页,兼容老版本) */ + /** 探活方式:ws = WebSocket 16001(预览类);http = HTTP 16000 根路径(查件页,兼容老版本) */ probe?: 'ws' | 'http'; }>(), { title: '连接不上本机软件', @@ -56,7 +56,7 @@ watch(() => props.open, async open => { async function probeReady(): Promise { if (props.probe === 'http') { - // 查件页走 HTTP 17300(老版本软件也有这个端口,但不一定有 WS) + // 查件页走 HTTP 16000(老版本软件也有这个端口,但不一定有 WS) const deadline = Date.now() + props.waitMs; while (Date.now() < deadline) { try { diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index a3deb2a..c34c36a 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -24,7 +24,7 @@ const routes: RouteRecordRaw[] = [ // 手机扫码后打开:确认登录(公开) { path: '/wechat', name: 'wechat-confirm', component: () => import('@/views/WechatConfirmView.vue'), meta: { public: true, bare: true } }, // 本机软件(打印服务)公共页:**不需要登录**,Chrome 插件打开 `/local?code=<运单号>` - // 页面自己查 http://localhost:17300/api/query/{code}(状态和结果一起回来), + // 页面自己查 http://localhost:16000/api/query/{code}(状态和结果一起回来), // 没启动就提示下载/唤起,没登录就唤起软件登录 { path: '/local', diff --git a/frontend/src/utils/localSoftware.ts b/frontend/src/utils/localSoftware.ts index b10f636..7fc9bca 100644 --- a/frontend/src/utils/localSoftware.ts +++ b/frontend/src/utils/localSoftware.ts @@ -29,8 +29,8 @@ export interface SoftwareRelease { /** 兜底下载地址(后端没放 version.json 时用) */ const FALLBACK_DOWNLOAD_URL = (import.meta.env.VITE_SOFTWARE_DOWNLOAD_URL as string | undefined) || ''; -// 探活统一走 `waitForLocalWs()`(api/localWs.ts):预览/云台/拉通道都在 17301, -// 还走 HTTP 17300 探活会出现「HTTP 起来了但预览通道没起来」的错位。 +// 探活统一走 `waitForLocalWs()`(api/localWs.ts):预览/云台/拉通道都在 16001, +// 还走 HTTP 16000 探活会出现「HTTP 起来了但预览通道没起来」的错位。 /** 用自定义协议唤起本机软件(必须在用户手势里调用) */ export function launchLocalSoftware(): void { diff --git a/frontend/src/views/CamerasView.vue b/frontend/src/views/CamerasView.vue index 6414bb3..6d53e22 100644 --- a/frontend/src/views/CamerasView.vue +++ b/frontend/src/views/CamerasView.vue @@ -341,7 +341,7 @@ async function openPreview(camera: Camera, streamType = previewStreamType.value) // 子码流走 SDK 取流 + PlayM4 解码(640×360、25fps)。 const mode = streamType === 0 ? 'ffmpeg' : 'stream'; - // 预览**只走本机 WebSocket(17301)**:二进制 JPEG 帧,一条连接可同时推多路。 + // 预览**只走本机 WebSocket(16001)**:二进制 JPEG 帧,一条连接可同时推多路。 try { await localWs.connect(2500); } catch { diff --git a/frontend/src/views/LocalServiceView.vue b/frontend/src/views/LocalServiceView.vue index 8a3cf6a..fe91216 100644 --- a/frontend/src/views/LocalServiceView.vue +++ b/frontend/src/views/LocalServiceView.vue @@ -312,7 +312,7 @@ onMounted(load); - +