优化: 跨端链路协议对齐

- miniapp 配置域旧端点强制重置
- df-tunnel 隧道协议与 relay 现网对齐
- relay e2e 例程入 examples
This commit is contained in:
lxy
2026-10-04 16:27:31 +08:00
parent 7aa0da32f2
commit d9e0ce73d1
9 changed files with 248 additions and 126 deletions
+10 -9
View File
@@ -1,10 +1,11 @@
/**
* df-relay WS 客户端(uni-app 跨端适配)
* u-relay WS 客户端(uni-app 跨端适配)
*
* 协议(对齐 crates/df-relay/src/relay.rs handle_connection):
* 1. 建立 WS 连接到 `/ws/miniapp`
* 2. 首帧发 Hello{kind:'miniapp', device_id, token} 身份宣告(relay.rs:197-208,10s 超时)
* 3. 校验通过后进入收发循环;失败 relay 发 Error 帧 + Close
* 协议(对齐 E:/wk-lab/u-relay/src/relay.rs handle_connection):
* 1. 建立 WS 连接到 `/ws/commander`
* 2. 首帧发 Hello{kind:'commander', channel_id, token} 身份宣告(relay 10s 超时)
* 3. 校验通过 → relay 回 hello_ack;失败 relay 发 error 帧 + Close
* (错误码:handshake_failed/kind_mismatch/invalid_channel_id/server_misconfigured/auth_failed)
*
* 跨端适配:
* - 微信小程序:uni.connectSocket(微信原生 API,非浏览器 WebSocket)
@@ -176,10 +177,10 @@ class WsClient {
}
/**
* 发送 Command(miniapp → device)
* 发送 Command(commander → agent)
*
* 不包装 BroadcastMessage —— relay.rs:332-365 入站文本帧直接当 payload 包成
* BroadcastMessage(device_id/kind/source/from 由 relay 填),故客户端仅发业务 JSON。
* BroadcastMessage(channel_id/kind/source/from 由 relay 填),故客户端仅发业务 JSON。
*/
send(cmd: MiniCommand): boolean {
if (DEBUG) console.log('[dbg:ws] send', cmd.cmd, 'socket=', !!this.socket, 'handshaked=', this.handshaked)
@@ -314,8 +315,8 @@ class WsClient {
this.setStatus('handshaking')
const cfg = getConfig()
const hello: Hello = {
kind: 'miniapp',
device_id: cfg.deviceId,
kind: 'commander',
channel_id: cfg.channelId,
token: cfg.token,
}
try {