// // VoicePlayingHandler.swift // ylgamehall // // H5 → Native handler:voicePlaying — 远端语音播放总开关 // 契约:docs/H5-Native-Contract.md §3.1 [6] // // Phase 2.4 仅实现"开关位",真正的 mediaTypeAudio 播放在 Phase 3 AudioKit // 完整时接入。开关位由 actor VoiceCenter 持有,跨 handler 共享。 // import Foundation /// 远端语音播放总开关(actor 隔离,跨 bridge handler 安全共享)。 /// Phase 3 mediaTypeAudio handler 读此 isEnabled 决定是否播放。 public actor VoiceCenter { public static let shared = VoiceCenter() public private(set) var isEnabled: Bool = true public func setEnabled(_ on: Bool) { isEnabled = on } } public enum VoicePlayingHandler { public static func register(on bridge: any BridgeProtocol) { // 【6】voicePlaying // 入参 int 1=允许 / 其它=静默 // cb:"Response from voicePlaying" bridge.register("voicePlaying") { data, callback in let on = (data?.asInt ?? 0) == 1 Task { await VoiceCenter.shared.setEnabled(on) } callback?(.string("Response from voicePlaying")) } } }