60 lines
1.9 KiB
Swift
60 lines
1.9 KiB
Swift
//
|
|
// YinRoomAgoraManager.swift
|
|
// yinmeng-ios
|
|
//
|
|
// Created by yinmeng on 2024/3/22.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class YinRoomAgoraManager: NSObject {
|
|
func initAgora(){
|
|
let manager = AgoraRtcEngineKit.sharedEngine(withAppId: AppKeys.agoraKey, delegate: self)
|
|
manager.setChannelProfile(.liveBroadcasting)
|
|
manager.startLastmileProbeTest(nil)
|
|
manager.setParameters("{\"che.audio.keep.audiosession\":true}")
|
|
manager.enableAudio()
|
|
manager.disableVideo()
|
|
manager.enableAudioVolumeIndication(900, smooth: 3, reportVad: true)
|
|
manager.setAudioProfile(.musicStandard)
|
|
manager.setAudioScenario(.gameStreaming)
|
|
#if DEBUG
|
|
manager.setLogFilter(0x000f)
|
|
#else
|
|
manager.setLogFilter(0)
|
|
#endif
|
|
self.manager = manager
|
|
}
|
|
func setAgora(roomUid:String){
|
|
manager?.setClientRole(.audience)
|
|
manager?.joinChannel(byToken: nil, channelId: roomUid, info: nil, uid: UInt(AuthManager.userUid)) { c, uid, e in
|
|
self.manager?.muteAllRemoteAudioStreams(false)
|
|
self.muteLocalAudio(mute: false)
|
|
}
|
|
|
|
|
|
}
|
|
func muteLocalAudio(mute:Bool){
|
|
manager?.muteLocalAudioStream(mute)
|
|
}
|
|
func setBroadcast(isChange:Bool){
|
|
manager?.setClientRole(isChange ? .broadcaster : .audience)
|
|
}
|
|
func exitRoom(){
|
|
manager?.leaveChannel { stats in
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func destroySharedIntance(){
|
|
AgoraRtcEngineKit.destroy()
|
|
}
|
|
private var manager:AgoraRtcEngineKit?
|
|
}
|
|
extension YinRoomAgoraManager:AgoraRtcEngineDelegate{
|
|
func rtcEngine(_ engine: AgoraRtcEngineKit, reportAudioVolumeIndicationOfSpeakers speakers: [AgoraRtcAudioVolumeInfo], totalVolume: Int) {
|
|
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kReceiveUserVoiceVolume") , object: nil, userInfo: ["userVolumes":speakers,"totalVolume":totalVolume,"type":"agora"])
|
|
}
|
|
}
|