Files
youle_app_ios_v2/ylgamehall/Source/Bridge/Handlers/VoicePlayingHandler.swift
T
joywayer 5463b07fb6 voicePlaying 回包对齐原项目:从 "Response from voicePlaying" 改为 "voicePlaying"
契约影响:H5-Native-Contract.md §3.1 [6] voicePlaying responseCallback。
新外壳此前按其它 handler 的 "Response from XXX" 模式套写,与原项目
gameController.m:573 / NewRootVC.m:451 不一致(原项目这里就是 handler 名本身
作回包,是历史包袱)。虽然 H5 通常不校验 cb 内容,但字面保持一致是契约硬约束。
2026-06-24 00:07:25 +08:00

38 lines
1.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// VoicePlayingHandler.swift
// ylgamehall
//
// H5 → Native handlervoicePlaying — 远端语音播放总开关
// 契约: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"voicePlaying"(字面与 handler 名相同,不是 "Response from voicePlaying"
bridge.register("voicePlaying") { data, callback in
let on = (data?.asInt ?? 0) == 1
Task { await VoiceCenter.shared.setEnabled(on) }
// 注意回包字面是 "voicePlaying",不是 "Response from voicePlaying"。
// 与其它 handler 的 "Response from XXX" 模式不一致是原项目历史包袱
// daoqi/msext gameController.m:573、NewRootVC.m:451 都是 responseCallback(@"voicePlaying")
callback?(.string("voicePlaying"))
}
}
}