fix(bridge): WS桥接统一回显_msgId/_callId,响应严格按ID匹配避免广播误匹配

This commit is contained in:
liufumingren 2026-08-24 02:20:48 +08:00
parent 5bb8c30e12
commit ffd2d238c2

View File

@ -250,9 +250,11 @@ class WSServer {
ws.send(JSON.stringify({ success: false, message: '消息解析失败' }));
return;
}
const { method, data, _callId } = parsed;
const { method, data, _callId, _msgId } = parsed;
// 统一回显请求 ID:优先 _msgId(Electron 桥接),兼容 _callId(页面直连)
const replyId = _msgId || _callId;
if (!method) {
ws.send(JSON.stringify({ success: false, message: 'method不能为空', _callId }));
ws.send(JSON.stringify({ success: false, message: 'method不能为空', _msgId: replyId, _callId: replyId }));
return;
}
// 支持多级目录结构,如 index.index.index
@ -265,17 +267,18 @@ class WSServer {
if (typeof serviceFn === 'function') {
try {
const result = await serviceFn(data);
ws.send(JSON.stringify({ success: true, method, result, _callId }));
ws.send(JSON.stringify({ success: true, method, result, _msgId: replyId, _callId: replyId }));
} catch (err) {
//console.log(err);
ws.send(JSON.stringify({ success: false, method, message: '服务方法执行失败: ' + err.message, _callId }));
ws.send(JSON.stringify({ success: false, method, message: '服务方法执行失败: ' + err.message, _msgId: replyId, _callId: replyId }));
}
} else {
ws.send(JSON.stringify({
success: false,
method,
message: '未找到对应服务方法',
_callId,
_msgId: replyId,
_callId: replyId,
debug: {
method,
methodPath,