完善机巢任务实时同步并开放双构建真实操作
订阅明确无缓存时使用新发起的有效 HTTP 全量响应衔接首包,保留任务、批次和版本校验。 移除 Debug/Release 的设备指令、图传和 RTC 构建拦截,保留后端权限、身份、防重复提交及结果未知保护。 更新开发约定并补充隔离传输、飞控状态和页面回归测试。 验证:iPhone 真机 500 项相关测试通过;iOS Release 无签名编译通过。
This commit is contained in:
@@ -318,7 +318,6 @@ final class DroneDockHomeViewController: GlobalLoadingPageViewController {
|
||||
planeStatusService: DroneDockPlaneStatusAPI(client: NetworkServices.shared.apiClient),
|
||||
taskCreationService: DroneDockTaskCreationAPI(client: NetworkServices.shared.apiClient),
|
||||
shootService: DroneDockShootAPI(client: NetworkServices.shared.apiClient),
|
||||
allowsTaskSubmission: !DeviceCommandDebugPolicy.blocksFlightRequests,
|
||||
currentContext: { Self.currentContext() }
|
||||
))
|
||||
}
|
||||
|
||||
@@ -66,8 +66,7 @@ final class DroneDockRemotePreparationViewController: GlobalLoadingPageViewContr
|
||||
navigationItem.rightBarButtonItem = records
|
||||
}
|
||||
#if DEBUG
|
||||
if simulationRecordsProvider == nil, DeviceCommandDebugPolicy.blocksLiveRequests,
|
||||
viewModel.isTaskSubmissionBlocked {
|
||||
if simulationRecordsProvider == nil {
|
||||
let simulation = UIBarButtonItem(title: "本地模拟", style: .plain,
|
||||
target: self, action: #selector(openLocalSimulation))
|
||||
simulation.accessibilityIdentifier = "drone.preparation.mock.entry"
|
||||
@@ -192,8 +191,7 @@ final class DroneDockRemotePreparationViewController: GlobalLoadingPageViewContr
|
||||
"scenic_id": viewModel.context.scenicID,
|
||||
"spot_id": viewModel.selectedSpotID as Any? ?? NSNull(),
|
||||
"air_line_id": viewModel.selectedRouteID as Any? ?? NSNull(),
|
||||
"enabled": viewModel.isPrimaryActionEnabled,
|
||||
"blocked": viewModel.isTaskSubmissionBlocked
|
||||
"enabled": viewModel.isPrimaryActionEnabled
|
||||
])
|
||||
guard !isRefreshing, !isStartingCreation else {
|
||||
logPreparationEvent("preparation.confirm_rejected", fields: ["reason": "refresh_or_submission_in_progress"])
|
||||
@@ -325,7 +323,6 @@ final class DroneDockRemotePreparationViewController: GlobalLoadingPageViewContr
|
||||
fields["app_active"] = isApplicationActive
|
||||
fields["refreshing"] = isRefreshing
|
||||
fields["submitting"] = isStartingCreation
|
||||
fields["debug_flight_blocked"] = DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
viewModel.recordPreparationEvent(name, fields: fields)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import UIKit
|
||||
/// 组装真实拍摄任务页;构造时不发请求,页面出现后才读取同一任务。
|
||||
@MainActor
|
||||
enum DroneDockShootingTaskEntry {
|
||||
/// 使用已有任务读取状态;Release 注入已授权的真实控制,Debug 保持只读。
|
||||
/// 使用已有任务读取状态,两种构建均注入真实服务并按后端权限操作。
|
||||
static func makeController(taskID: Int, order: DroneDockHomeOrder,
|
||||
context: DroneDockHomeContext) -> UIViewController {
|
||||
makeController(taskID: taskID, order: order, context: context, coverURL: nil)
|
||||
@@ -20,15 +20,15 @@ enum DroneDockShootingTaskEntry {
|
||||
identityIsCurrent: { context.hasSameIdentity(as: DroneDockHomeViewController.currentContext()) })
|
||||
let live = DroneDockLiveViewModel(
|
||||
context: context, taskID: taskID,
|
||||
service: DeviceCommandDebugPolicy.blocksLiveRequests ? nil : DroneDockLiveAPI(client: client),
|
||||
allowsDevicePlayback: !DeviceCommandDebugPolicy.blocksLiveRequests,
|
||||
service: DroneDockLiveAPI(client: client),
|
||||
allowsDevicePlayback: true,
|
||||
currentContext: { DroneDockHomeViewController.currentContext() })
|
||||
return DroneDockShootingTaskViewController(viewModel: DroneDockShootingTaskViewModel(
|
||||
context: context, taskID: taskID, order: order,
|
||||
service: DroneDockShootingAPI(client: client),
|
||||
startService: DeviceCommandDebugPolicy.blocksFlightRequests ? nil : DroneDockStartShootAPI(client: client),
|
||||
commandService: DeviceCommandDebugPolicy.blocksFlightRequests ? nil : DroneDockCommandAPI(client: client),
|
||||
resummonService: DeviceCommandDebugPolicy.blocksFlightRequests ? nil : DroneDockShootAPI(client: client),
|
||||
startService: DroneDockStartShootAPI(client: client),
|
||||
commandService: DroneDockCommandAPI(client: client),
|
||||
resummonService: DroneDockShootAPI(client: client),
|
||||
initialSummonReceipt: initialSummonReceipt,
|
||||
currentContext: { DroneDockHomeViewController.currentContext() }
|
||||
), liveViewModel: live, coverURL: coverURL, realtimeSession: realtime)
|
||||
|
||||
@@ -95,6 +95,9 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
realtimeSession?.onConnectionState = { [weak self] state in
|
||||
self?.connectionStateChanged(state)
|
||||
}
|
||||
realtimeSession?.onHTTPSeedRequired = { [weak self] in
|
||||
self?.refreshTaskIfVisible(isPolling: true)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
@@ -439,18 +442,30 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
cancelScheduledPoll()
|
||||
requestGeneration &+= 1
|
||||
let generation = requestGeneration
|
||||
let httpSeedRequest = realtimeSession?.pendingHTTPSeedRequest
|
||||
isRequesting = true
|
||||
applySnapshot()
|
||||
refreshTask = Task { @MainActor [weak self] in
|
||||
guard let self else { return }
|
||||
await self.viewModel.refresh()
|
||||
let seedResult: DroneDockHTTPSnapshotResult?
|
||||
if httpSeedRequest != nil { seedResult = await self.viewModel.refreshForRealtimeSeed() }
|
||||
else { await self.viewModel.refresh(); seedResult = nil }
|
||||
guard self.isPageVisible, self.isApplicationActive,
|
||||
self.requestGeneration == generation, !Task.isCancelled else { return }
|
||||
self.refreshTask = nil
|
||||
self.isRequesting = false
|
||||
if let httpSeedRequest, let seedResult {
|
||||
self.realtimeSession?.acceptHTTPSeed(seedResult, requestID: httpSeedRequest)
|
||||
}
|
||||
self.applySnapshot()
|
||||
if self.viewModel.canContinuePolling { self.realtimeSession?.start() }
|
||||
else { self.realtimeSession?.stop() }
|
||||
// 无缓存提示可能在旧 HTTP 读取途中到达;旧请求不充当首包,结束后再串行补读。
|
||||
if let pendingSeed = self.realtimeSession?.pendingHTTPSeedRequest, pendingSeed != httpSeedRequest,
|
||||
self.viewModel.canContinuePolling {
|
||||
self.refreshTaskIfVisible(isPolling: true)
|
||||
return
|
||||
}
|
||||
self.scheduleNextPoll()
|
||||
if !isPolling, self.viewModel.response != nil, let error = self.viewModel.errorMessage {
|
||||
self.showToast("刷新失败,当前显示上次数据:\(error)")
|
||||
@@ -571,7 +586,7 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
|
||||
/// 重召唤使用原任务 ID,回执后再查询状态,避免从受理结果推断设备已到达。
|
||||
private func resummonIfAllowed() {
|
||||
guard allowsControlActions, isPageVisible, isApplicationActive,
|
||||
guard isPageVisible, isApplicationActive,
|
||||
!isResummoningAction, !isStartingAction, !isSendingSafetyAction,
|
||||
viewModel.canResummon else { return }
|
||||
cancelPendingReadForAction()
|
||||
@@ -655,10 +670,10 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
feedPlaceholder.apply(liveViewModel)
|
||||
}
|
||||
|
||||
/// 返航会中断任务,先明确展示其含义再提交一次;Debug 只开放隔离模拟入口。
|
||||
/// 返航会中断任务,先明确展示其含义再提交一次。
|
||||
private func safetyCommandTriggered(_ command: DroneDockSafetyCommand) {
|
||||
logEvent("action.safety", fields: ["command": command.rawValue, "enabled": viewModel.canSendCommand(command)])
|
||||
guard allowsControlActions, isPageVisible, isApplicationActive,
|
||||
guard isPageVisible, isApplicationActive,
|
||||
presentedViewController == nil, !submittingCommands.contains(command), !isStartingAction,
|
||||
!isResummoningAction, viewModel.canSendCommand(command) else {
|
||||
logSafetyRejection(command, stage: "tap")
|
||||
@@ -686,7 +701,7 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
|
||||
/// 同步锁只覆盖同一按钮;不同安全动作可各自等待,设备确认由 ViewModel 和快照处理。
|
||||
private func sendSafetyCommand(_ command: DroneDockSafetyCommand) {
|
||||
guard allowsControlActions, isPageVisible, isApplicationActive,
|
||||
guard isPageVisible, isApplicationActive,
|
||||
!submittingCommands.contains(command), !isStartingAction, !isResummoningAction,
|
||||
viewModel.canSendCommand(command) else {
|
||||
logSafetyRejection(command, stage: "submit")
|
||||
@@ -757,9 +772,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
fields["page_visible"] = isPageVisible
|
||||
fields["app_active"] = isApplicationActive
|
||||
fields["view_in_window"] = isViewLoaded && view.window != nil
|
||||
fields["debug_flight_blocked"] = DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
fields["debug_live_blocked"] = DeviceCommandDebugPolicy.blocksLiveRequests
|
||||
fields["allows_control_actions"] = allowsControlActions
|
||||
viewModel.recordTaskEvent(name, fields: fields)
|
||||
}
|
||||
|
||||
@@ -779,7 +791,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
"submitting_commands": submittingCommands.map(\.rawValue).sorted()])
|
||||
var liveFields = feedPlaceholder.diagnosticFields
|
||||
switch liveViewModel.state {
|
||||
case .restricted: liveFields["state"] = "restricted"
|
||||
case .idle: liveFields["state"] = "idle"
|
||||
case .loading: liveFields["state"] = "loading"
|
||||
case .connecting: liveFields["state"] = "connecting"
|
||||
@@ -823,7 +834,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
|
||||
private func logSafetyRejection(_ command: DroneDockSafetyCommand, stage: String) {
|
||||
var reasons: [String] = []
|
||||
if !allowsControlActions { reasons.append("debug_policy") }
|
||||
if !isPageVisible { reasons.append("page_hidden") }
|
||||
if !isApplicationActive { reasons.append("app_inactive") }
|
||||
if stage == "tap", presentedViewController != nil { reasons.append("modal_presented") }
|
||||
@@ -835,9 +845,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
"reasons": reasons, "safety": safetyView.diagnosticFields])
|
||||
}
|
||||
|
||||
private var allowsControlActions: Bool {
|
||||
simulationRecordsProvider != nil || !DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
}
|
||||
}
|
||||
|
||||
/// 以可选择的 JSON 文本展示本地模拟请求与回执,避免与真实接口联调混淆。
|
||||
@@ -940,7 +947,6 @@ private final class DroneDockTaskSafetyView: UIView {
|
||||
/// 两个按钮始终表示暂停与返航;已暂停、返航中和回巢使用本地文案,恢复入口位于中央。
|
||||
func apply(model: DroneDockShootingTaskViewModel, isSimulation: Bool, isInteractive: Bool,
|
||||
submittingCommands: Set<DroneDockSafetyCommand> = []) {
|
||||
let allowsControls = isSimulation || !DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
let phase = model.presentation.phase
|
||||
var controlState = model.flightControlState
|
||||
if model.response?.flightControl == nil {
|
||||
@@ -974,7 +980,7 @@ private final class DroneDockTaskSafetyView: UIView {
|
||||
subtitle = "结果待核对"
|
||||
}
|
||||
let loading = submittingCommands.contains(command) || model.isCommandLoading(command)
|
||||
let enabled = allowsControls && isInteractive && model.canSendCommand(command)
|
||||
let enabled = isInteractive && model.canSendCommand(command)
|
||||
button.apply(title: title, subtitle: subtitle, enabled: enabled, isLoading: loading)
|
||||
button.setControlSymbol(command == .pause ? "pause.circle" : "arrow.uturn.backward")
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ enum DroneDockStartShootSimulation {
|
||||
service: DroneDockPreparationAPI(client: client),
|
||||
planeStatusService: DroneDockPlaneStatusAPI(client: client),
|
||||
taskCreationService: DroneDockTaskCreationAPI(client: client),
|
||||
shootService: DroneDockShootAPI(client: client), allowsTaskSubmission: true,
|
||||
shootService: DroneDockShootAPI(client: client),
|
||||
currentContext: { context })
|
||||
return DroneDockRemotePreparationViewController(viewModel: model,
|
||||
taskControllerFactory: taskFactory,
|
||||
|
||||
@@ -31,7 +31,7 @@ protocol DroneDockRTCReceivingRoom: AnyObject {
|
||||
func destroy()
|
||||
}
|
||||
|
||||
/// 火山 SDK 适配器;真实创建点再次拦截 Debug,测试不能通过注入绕开保护。
|
||||
/// 火山 SDK 适配器,封装当前任务的只收视频引擎与房间。
|
||||
@MainActor
|
||||
final class DroneDockVolcEngineAdapter: DroneDockRTCReceivingEngine {
|
||||
private let engine: ByteRTCEngine
|
||||
@@ -45,9 +45,8 @@ final class DroneDockVolcEngineAdapter: DroneDockRTCReceivingEngine {
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
/// 仅在构建策略允许真实图传时构造 SDK。
|
||||
/// 按已验证的当前任务播放配置构造 SDK。
|
||||
static func make(appID: String, onEvent: @escaping @Sendable (DroneDockVolcEvent) -> Void) -> (any DroneDockRTCReceivingEngine)? {
|
||||
guard !DeviceCommandDebugPolicy.blocksLiveRequests else { return nil }
|
||||
let delegate = DroneDockVolcDelegate(emit: onEvent)
|
||||
let config = ByteRTCEngineConfig()
|
||||
config.appID = appID
|
||||
|
||||
@@ -18,7 +18,7 @@ extension DroneDockLivePlaying {
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?) {}
|
||||
}
|
||||
|
||||
/// 真实 SDK 入口始终执行编译期禁飞保护,没有运行时放行参数。
|
||||
/// 通过双路接收器播放真实图传,生命周期由任务页管理。
|
||||
@MainActor
|
||||
final class DroneDockVolcLivePlayer: DroneDockLivePlaying {
|
||||
private let receiver = DroneDockLiveReceiver(makeEngine: DroneDockVolcEngineAdapter.make)
|
||||
@@ -28,12 +28,9 @@ final class DroneDockVolcLivePlayer: DroneDockLivePlaying {
|
||||
receiver.setGeometryHandler(handler)
|
||||
}
|
||||
|
||||
/// Release 通过接收器播放;Debug 在创建 SDK 之前拒绝连接。
|
||||
/// 两种构建均通过同一接收器播放当前任务的图传。
|
||||
func start(_ configurations: [DroneDockVolcLiveConfiguration], in view: UIView,
|
||||
onEvent: @escaping @MainActor (DroneDockLivePlaybackEvent) -> Void) {
|
||||
guard !DeviceCommandDebugPolicy.blocksLiveRequests else {
|
||||
stop(); onEvent(.failed(DeviceCommandDebugPolicy.blockedMessage)); return
|
||||
}
|
||||
receiver.start(configurations, in: view, onEvent: onEvent)
|
||||
}
|
||||
|
||||
@@ -48,7 +45,7 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
private let makeEngine: (String, @escaping @Sendable (DroneDockVolcEvent) -> Void) -> (any DroneDockRTCReceivingEngine)?
|
||||
private let firstFrameDelay: @Sendable () async throws -> Void
|
||||
|
||||
/// 生产环境注入带 Debug 保护的适配器;测试只注入内存接收端。
|
||||
/// 正式页面注入 SDK 适配器;测试注入内存接收端。
|
||||
init(makeEngine: @escaping (String, @escaping @Sendable (DroneDockVolcEvent) -> Void) -> (any DroneDockRTCReceivingEngine)?,
|
||||
firstFrameDelay: @escaping @Sendable () async throws -> Void = { try await Task.sleep(for: .seconds(20)) }) {
|
||||
self.makeEngine = makeEngine
|
||||
|
||||
Reference in New Issue
Block a user