|
|
@ -1,4 +1,33 @@ |
|
|
|
import { Subject } from "rxjs"; |
|
|
|
import type { DebugCmd } from "./debug/debugApi"; |
|
|
|
|
|
|
|
export type CmdSuccess = "D0000"; |
|
|
|
export type CmdFailure = "D1111"; |
|
|
|
export type CmdDatagram = { |
|
|
|
type: "cmd"; // 指令
|
|
|
|
data: { |
|
|
|
commandId: string; |
|
|
|
commandName: DebugCmd; |
|
|
|
status: CmdSuccess | CmdFailure; |
|
|
|
message: string; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
export type WarnDatagram = { |
|
|
|
type: "warn"; // 报警
|
|
|
|
data: { |
|
|
|
message: string; |
|
|
|
}; |
|
|
|
}; |
|
|
|
export type StatusDatagram = { |
|
|
|
type: "status"; // 状态
|
|
|
|
data: { |
|
|
|
message: string; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
export type Datagram = CmdDatagram | WarnDatagram | StatusDatagram; |
|
|
|
export type DatagramType = Datagram['type'] |
|
|
|
|
|
|
|
export type SocketState = "open" | "close" | "error"; |
|
|
|
|
|
|
@ -9,7 +38,7 @@ class WebSocketClient { |
|
|
|
private maxReconnectAttempts: number = 5; |
|
|
|
private reconnectInterval: number = 3000; |
|
|
|
|
|
|
|
private dataSub = new Subject(); |
|
|
|
private dataSub = new Subject<Datagram>(); |
|
|
|
get dataOb() { |
|
|
|
return this.dataSub.asObservable(); |
|
|
|
} |
|
|
|