feat: 完善机巢任务实时状态、双路图传与继续查看入口
This commit is contained in:
@@ -7,22 +7,23 @@ enum DroneDockSnapshotAcceptance {
|
||||
|
||||
/// 先解析业务码再解析 data,兼容订阅失败时 data=[]。
|
||||
enum DroneDockShootingSocketMessage {
|
||||
case opened
|
||||
case subscribed(taskID: Int, hasSnapshot: Bool)
|
||||
case snapshot(DroneDockShootingResponse)
|
||||
case rejected(code: Int, message: String)
|
||||
case unrelated
|
||||
|
||||
/// WebSocket 成功码为 0,不使用 HTTP 的 100000 Envelope。
|
||||
/// 按新版协议解析 100000 成功包,欢迎帧仅用于触发 310,不代表订阅成功。
|
||||
static func decode(_ data: Data) throws -> Self {
|
||||
// 服务端建连先发 Opened。它不代表 310 订阅成功,也不能取消订阅超时或 HTTP 兜底。
|
||||
if String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) == "Opened" {
|
||||
return .unrelated
|
||||
return .opened
|
||||
}
|
||||
let json = try JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed)
|
||||
if json as? String == "Opened" { return .unrelated }
|
||||
if json as? String == "Opened" { return .opened }
|
||||
guard let root = json as? [String: Any],
|
||||
let code = root["code"] as? Int else { throw APIError.invalidResponse }
|
||||
if code != 0 {
|
||||
if code != 100000 {
|
||||
return .rejected(code: code, message: root["msg"] as? String ?? "任务订阅失败")
|
||||
}
|
||||
guard let body = root["data"] as? [String: Any] else { throw APIError.invalidResponse }
|
||||
|
||||
Reference in New Issue
Block a user