2024-03-22 15:46:25 +08:00
|
|
|
//
|
|
|
|
// YinRoomAgoraManager.swift
|
|
|
|
// yinmeng-ios
|
|
|
|
//
|
2024-03-23 20:47:19 +08:00
|
|
|
// Created by yinmeng on 2024/3/22.
|
2024-03-22 15:46:25 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class YinRoomAgoraManager: NSObject {
|
|
|
|
|
|
|
|
func initAgora(roomUid:String){
|
|
|
|
manager.setClientRole(.audience)
|
|
|
|
let i = manager.joinChannel(byToken: nil, channelId: roomUid, info: nil, uid: UInt(AuthManager.userUid)) { c, uid, e in
|
|
|
|
self.manager.muteAllRemoteAudioStreams(false)
|
|
|
|
self.muteLocalAudio(mute: false)
|
|
|
|
}
|
|
|
|
print(i)
|
|
|
|
|
|
|
|
}
|
|
|
|
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 lazy var manager:AgoraRtcEngineKit = {
|
|
|
|
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
|
|
|
|
return _manager
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
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"])
|
|
|
|
}
|
|
|
|
}
|