|
@ -10,6 +10,7 @@ export type CmdDatagram = { |
|
|
// commandName: DebugCmd;
|
|
|
// commandName: DebugCmd;
|
|
|
status: CmdSuccess | CmdFailure; |
|
|
status: CmdSuccess | CmdFailure; |
|
|
message: string; |
|
|
message: string; |
|
|
|
|
|
success: boolean; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -76,7 +77,7 @@ export type StatusDatagram = { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
export type Datagram = CmdDatagram | WarnDatagram | StatusDatagram; |
|
|
export type Datagram = CmdDatagram | WarnDatagram | StatusDatagram; |
|
|
export type DatagramType = Datagram['type'] |
|
|
|
|
|
|
|
|
export type DatagramType = Datagram["type"]; |
|
|
|
|
|
|
|
|
export type SocketState = "open" | "close" | "error"; |
|
|
export type SocketState = "open" | "close" | "error"; |
|
|
|
|
|
|
|
@ -130,9 +131,13 @@ class WebSocketClient { |
|
|
// 接收消息的处理
|
|
|
// 接收消息的处理
|
|
|
this.ws.onmessage = (event: MessageEvent) => { |
|
|
this.ws.onmessage = (event: MessageEvent) => { |
|
|
try { |
|
|
try { |
|
|
const data = JSON.parse(event.data); |
|
|
|
|
|
|
|
|
const data = JSON.parse(event.data) as Datagram; |
|
|
// console.log('🚀 ~ WebSocketClient ~ bindEvents ~ data:', data)
|
|
|
// console.log('🚀 ~ WebSocketClient ~ bindEvents ~ data:', data)
|
|
|
|
|
|
if (data.type === "cmd") { |
|
|
|
|
|
this.dataSub.next({ type: data.type, data: { ...data.data, success: data.data.status === "D0000" } }); |
|
|
|
|
|
} else { |
|
|
this.dataSub.next(data); |
|
|
this.dataSub.next(data); |
|
|
|
|
|
} |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error("消息解析错误:", error); |
|
|
console.error("消息解析错误:", error); |
|
|
} |
|
|
} |
|
|