完成监听服务端下发退出登录的指令并退出登录

This commit is contained in:
2026-03-13 15:56:51 +08:00
parent 775926dc32
commit 67b9907eec
2 changed files with 66 additions and 9 deletions

View File

@@ -43,8 +43,26 @@ class NetMessageDispatcher {
}
/// 示例解析方法:将 0x12 指令解析为 JSON 并转为模型
// Stream<Map<String, dynamic>> onJsonMessage(int cmd) {
// return onCommand(cmd).map((p) => jsonDecode(utf8.decode(p.payload)));
// }
Stream<Map<String, dynamic>> onJsonMessage(int cmd) {
return onCommand(cmd).map((p) => jsonDecode(utf8.decode(p.payload)));
print('🔵 [Dispatcher] 开始监听 0x${cmd.toRadixString(16)} 指令的 JSON 流');
return onCommand(cmd).map((p) {
try {
final jsonString = utf8.decode(p.payload);
print('🔵 [Dispatcher] 收到 0x${cmd.toRadixString(16)} 原始数据: $jsonString');
final jsonMap = jsonDecode(jsonString);
print('🔵 [Dispatcher] JSON 解析成功:$jsonMap');
return jsonMap;
} catch (e) {
print('❌ [Dispatcher] 0x${cmd.toRadixString(16)} JSON 解析失败:$e, payload=${p.payload}');
return {}; // 返回空 map,避免流中断
}
});
}
//监听路径规划的开始作业的指令的应答