feat: 统一机巢加载体验并对齐到达态界面
工作台、准备页、任务首次读取和景区空境库复用应用通用 Loading;到达态按 Web 展示,保留倒计时及手动开拍权限。新增图传几何诊断,不改变 Fit 渲染或设备连接行为。 验证:App 与测试包无签名 build-for-testing 编译通过,git diff --check 通过。iPhone 11 当前 unavailable,真机回归待设备重连后执行。
This commit is contained in:
@@ -4,6 +4,8 @@ import UIKit
|
||||
/// 可替换的双路图传播放器;测试注入内存替身,不初始化 RTC 或连接设备。
|
||||
@MainActor
|
||||
protocol DroneDockLivePlaying: AnyObject {
|
||||
/// 设置只读几何事件出口;不触发播放、连接或任务状态刷新。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?)
|
||||
/// 同一播放会话可增补或更新凭证,不重建未变化的房间。
|
||||
func start(_ configurations: [DroneDockVolcLiveConfiguration], in view: UIView,
|
||||
onEvent: @escaping @MainActor (DroneDockLivePlaybackEvent) -> Void)
|
||||
@@ -11,11 +13,21 @@ protocol DroneDockLivePlaying: AnyObject {
|
||||
func stop()
|
||||
}
|
||||
|
||||
extension DroneDockLivePlaying {
|
||||
/// 旧播放器替身无需实现诊断能力。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?) {}
|
||||
}
|
||||
|
||||
/// 真实 SDK 入口始终执行编译期禁飞保护,没有运行时放行参数。
|
||||
@MainActor
|
||||
final class DroneDockVolcLivePlayer: DroneDockLivePlaying {
|
||||
private let receiver = DroneDockLiveReceiver(makeEngine: DroneDockVolcEngineAdapter.make)
|
||||
|
||||
/// 几何事件与业务播放事件分离,不改变播放状态机。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?) {
|
||||
receiver.setGeometryHandler(handler)
|
||||
}
|
||||
|
||||
/// Release 通过接收器播放;Debug 在创建 SDK 之前拒绝连接。
|
||||
func start(_ configurations: [DroneDockVolcLiveConfiguration], in view: UIView,
|
||||
onEvent: @escaping @MainActor (DroneDockLivePlaybackEvent) -> Void) {
|
||||
@@ -51,6 +63,12 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
private var failedRoles: Set<String> = []
|
||||
private var generation = UUID()
|
||||
private var onEvent: (@MainActor (DroneDockLivePlaybackEvent) -> Void)?
|
||||
private var onGeometry: (@MainActor (DroneDockLiveGeometry) -> Void)?
|
||||
|
||||
/// 复用调用方的任务诊断会话,不在接收器中另建日志通道。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?) {
|
||||
onGeometry = handler
|
||||
}
|
||||
|
||||
/// 加入只收视频的房间;同一来源只更新 Token,避免后台重查导致画面闪断。
|
||||
func start(_ configurations: [DroneDockVolcLiveConfiguration], in view: UIView,
|
||||
@@ -201,6 +219,8 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
_ = engine?.setVideoView(nil, streamID: id)
|
||||
_ = source.room.subscribeVideo(id, subscribe: false)
|
||||
source.streamID = nil
|
||||
source.frameGeometry = nil
|
||||
source.reportedFirstFrame = false
|
||||
markReady(false, source: source)
|
||||
return
|
||||
}
|
||||
@@ -209,9 +229,13 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
let render = engine?.setVideoView(source.view, streamID: id)
|
||||
let subscribe = source.room.subscribeVideo(id, subscribe: true)
|
||||
if render != 0 || subscribe != 0 { sourceFailed(source.configuration.role, message: "图传订阅失败(\(render ?? -1)/\(subscribe)),请重试") }
|
||||
case .frame(let id, let roomID):
|
||||
case .frame(let id, let roomID, let geometry):
|
||||
guard let source = source(in: roomID), source.streamID == id else { return }
|
||||
if let geometry { updateFrameGeometry(geometry, source: source, isFirstFrame: true) }
|
||||
markReady(true, source: source)
|
||||
case .videoSizeChanged(let id, let roomID, let geometry):
|
||||
guard let source = source(in: roomID), source.streamID == id else { return }
|
||||
updateFrameGeometry(geometry, source: source, isFirstFrame: false)
|
||||
case .videoState(let id, let roomID, let state):
|
||||
guard let source = source(in: roomID), source.streamID == id else { return }
|
||||
switch state {
|
||||
@@ -236,6 +260,27 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
sources.values.first { $0.configuration.roomID == roomID }
|
||||
}
|
||||
|
||||
private func updateFrameGeometry(_ geometry: DroneDockVideoFrameGeometry,
|
||||
source: DroneDockVolcSource, isFirstFrame: Bool) {
|
||||
let changed = source.frameGeometry != geometry
|
||||
source.frameGeometry = geometry
|
||||
if isFirstFrame, !source.reportedFirstFrame {
|
||||
source.reportedFirstFrame = true
|
||||
emitGeometry(source, trigger: "first_frame")
|
||||
} else if changed {
|
||||
emitGeometry(source, trigger: "video_size_changed")
|
||||
}
|
||||
}
|
||||
|
||||
private func emitGeometry(_ source: DroneDockVolcSource, trigger: String) {
|
||||
guard let streamID = source.streamID, let container else { return }
|
||||
onGeometry?(DroneDockLiveGeometry(trigger: trigger, role: source.configuration.role,
|
||||
roomID: source.configuration.roomID, streamID: streamID, frame: source.frameGeometry,
|
||||
containerWidth: Double(source.view.bounds.width), containerHeight: Double(source.view.bounds.height),
|
||||
hostWidth: Double(container.bounds.width), hostHeight: Double(container.bounds.height),
|
||||
isSelected: selection.selectedRole == source.configuration.role, sdkVersion: engine?.sdkVersion))
|
||||
}
|
||||
|
||||
private func markReady(_ ready: Bool, source: DroneDockVolcSource) {
|
||||
selection.setReady(ready, role: source.configuration.role)
|
||||
if ready {
|
||||
@@ -267,6 +312,7 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
if let role, let view = sources[role]?.view { container?.bringSubviewToFront(view) }
|
||||
guard displayedRole != role else { return }
|
||||
displayedRole = role
|
||||
if let role, let source = sources[role] { emitGeometry(source, trigger: "source_changed") }
|
||||
onEvent?(.sourceChanged(role))
|
||||
}
|
||||
}
|
||||
@@ -279,6 +325,8 @@ private final class DroneDockVolcSource {
|
||||
let room: any DroneDockRTCReceivingRoom
|
||||
let view: UIView
|
||||
var streamID: String?
|
||||
var frameGeometry: DroneDockVideoFrameGeometry?
|
||||
var reportedFirstFrame = false
|
||||
var timeoutTask: Task<Void, Never>?
|
||||
var expiryTask: Task<Void, Never>?
|
||||
|
||||
@@ -290,7 +338,8 @@ private final class DroneDockVolcSource {
|
||||
/// SDK 工作线程只转交值类型事件;事件带房间和流身份以隔离两路回调。
|
||||
enum DroneDockVolcEvent: Sendable {
|
||||
case published(String, String, Bool)
|
||||
case frame(String, String)
|
||||
case frame(String, String, DroneDockVideoFrameGeometry? = nil)
|
||||
case videoSizeChanged(String, String, DroneDockVideoFrameGeometry)
|
||||
case videoState(String, String, ByteRTCRemoteVideoState)
|
||||
case roomFailed(String, Int)
|
||||
case connectionLost
|
||||
@@ -313,7 +362,17 @@ final class DroneDockVolcDelegate: NSObject, ByteRTCEngineDelegate, ByteRTCRoomD
|
||||
func rtcEngine(_ engine: ByteRTCEngine, onFirstRemoteVideoFrameDecoded streamId: String,
|
||||
info: ByteRTCStreamInfo, withFrameInfo frameInfo: ByteRTCVideoFrameInfo) {
|
||||
// 未展示的画布也能解码,不能依赖被隐藏视图的 rendered 回调判断首帧。
|
||||
emit(.frame(streamId, info.roomId))
|
||||
emit(.frame(streamId, info.roomId, Self.geometry(frameInfo)))
|
||||
}
|
||||
|
||||
func rtcEngine(_ engine: ByteRTCEngine, onRemoteVideoSizeChanged streamId: String,
|
||||
info: ByteRTCStreamInfo, withFrameInfo frameInfo: ByteRTCVideoFrameInfo) {
|
||||
emit(.videoSizeChanged(streamId, info.roomId, Self.geometry(frameInfo)))
|
||||
}
|
||||
|
||||
private static func geometry(_ frameInfo: ByteRTCVideoFrameInfo) -> DroneDockVideoFrameGeometry {
|
||||
DroneDockVideoFrameGeometry(width: frameInfo.width, height: frameInfo.height,
|
||||
rotation: frameInfo.rotation.rawValue)
|
||||
}
|
||||
|
||||
func rtcEngine(_ engine: ByteRTCEngine, onRemoteVideoStateChanged streamId: String, info: ByteRTCStreamInfo,
|
||||
|
||||
Reference in New Issue
Block a user