fix: 自动开启机巢图传并修复日志崩溃与订阅重连
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// 朱工任务图传参数服务;请求可能启动设备图传,Release 可手动开启,Debug 只允许隔离模拟注入。
|
||||
/// 朱工任务图传参数服务;请求可能启动设备图传,Release 随页面自动开启,Debug 只允许隔离模拟注入。
|
||||
protocol DroneDockLiveServing: Sendable {
|
||||
/// 读取同一订单飞行任务的图传回执,不创建任务或更换飞机。
|
||||
@MainActor
|
||||
|
||||
@@ -14,7 +14,13 @@ enum DroneDockShootingSocketMessage {
|
||||
|
||||
/// WebSocket 成功码为 0,不使用 HTTP 的 100000 Envelope。
|
||||
static func decode(_ data: Data) throws -> Self {
|
||||
guard let root = try JSONSerialization.jsonObject(with: data) as? [String: Any],
|
||||
// 服务端建连先发 Opened。它不代表 310 订阅成功,也不能取消订阅超时或 HTTP 兜底。
|
||||
if String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) == "Opened" {
|
||||
return .unrelated
|
||||
}
|
||||
let json = try JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed)
|
||||
if json as? String == "Opened" { return .unrelated }
|
||||
guard let root = json as? [String: Any],
|
||||
let code = root["code"] as? Int else { throw APIError.invalidResponse }
|
||||
if code != 0 {
|
||||
return .rejected(code: code, message: root["msg"] as? String ?? "任务订阅失败")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// 任务图传的单次请求与生命周期;正式图传手动开启,模拟来源单独注入。
|
||||
/// 任务图传的单次请求与生命周期;页面可见时自动开启,模拟来源单独注入。
|
||||
final class DroneDockLiveViewModel {
|
||||
/// 当前图传所属的账号、景区与门店范围。
|
||||
let context: DroneDockHomeContext
|
||||
@@ -14,8 +14,8 @@ final class DroneDockLiveViewModel {
|
||||
private(set) var isLoading = false
|
||||
/// 仅显式正式入口允许解析设备 RTC;本地模拟即使收到参数也不连接设备。
|
||||
let allowsDevicePlayback: Bool
|
||||
/// 正式图传必须手动开启;演示入口可自动载入本地样片。
|
||||
var loadsAutomatically: Bool { !allowsDevicePlayback }
|
||||
/// 每次进入页面或回前台仅从空闲态自动加载,状态刷新不重复启动图传。
|
||||
var loadsAutomatically: Bool { canLoad && state == .idle }
|
||||
private(set) var rtcConfiguration: DroneDockVolcLiveConfiguration?
|
||||
private(set) var playbackSessionID: UUID?
|
||||
|
||||
@@ -68,7 +68,7 @@ final class DroneDockLiveViewModel {
|
||||
var message: String {
|
||||
switch state {
|
||||
case .restricted: return "禁飞调试期间不启动设备图传"
|
||||
case .idle: return allowsDevicePlayback ? "点击开启当前任务的实时图传" : "按当前任务获取图传信息"
|
||||
case .idle: return allowsDevicePlayback ? "正在准备连接图传" : "按当前任务获取图传信息"
|
||||
case .loading: return "请稍候"
|
||||
case .unavailable(let reason), .failed(let reason): return reason
|
||||
case .localPreview: return "仅播放本地样片,未连接无人机"
|
||||
@@ -80,14 +80,14 @@ final class DroneDockLiveViewModel {
|
||||
/// 操作名称跟随当前阶段,模拟来源始终显式标记。
|
||||
var actionTitle: String? {
|
||||
guard service != nil else { return nil }
|
||||
if isLoading { return "正在加载…" }
|
||||
if isLoading { return allowsDevicePlayback ? nil : "正在加载…" }
|
||||
switch state {
|
||||
case .restricted: return nil
|
||||
case .idle: return allowsDevicePlayback ? "开启实时图传" : (localPreviewURL == nil ? "获取图传信息" : "查看模拟图传")
|
||||
case .loading: return "正在加载…"
|
||||
case .idle: return nil
|
||||
case .loading: return allowsDevicePlayback ? nil : "正在加载…"
|
||||
case .failed, .unavailable: return "重试"
|
||||
case .localPreview: return "重新加载模拟图传"
|
||||
case .connecting: return "重新连接"
|
||||
case .connecting: return nil
|
||||
case .playing: return "刷新图传"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user