From aeb26daad657dfec05e44880110aee9eda14fafd Mon Sep 17 00:00:00 2001 From: liyuhua <15626451870@163.com> Date: Fri, 22 Mar 2024 15:46:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E5=A3=B0=E7=BD=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Podfile | 2 + yinmeng-ios.xcodeproj/project.pbxproj | 4 + .../Security/yinmeng-ios-Bridging-Header.h | 1 + yinmeng-ios/Base/Utils/AppKeys.swift | 2 + .../Modules/Room/Model/RoomDataModel.swift | 1 + .../Room/Tool/YinRoomAgoraManager.swift | 59 +++++++ .../Room/Tool/YinRoomAudioManager.swift | 69 +++++++- .../Room/Tool/YinRoomTRTCManager.swift | 64 ++++++- yinmeng-ios/Modules/Room/VC/RoomVC.swift | 23 ++- .../NormalMicSeatSuperView.swift | 160 +++++++----------- .../SubView/NormalMicSeatView.swift | 29 ++-- .../View/RoomMenuView/View/RoomMenuView.swift | 24 +-- 12 files changed, 296 insertions(+), 142 deletions(-) create mode 100644 yinmeng-ios/Modules/Room/Tool/YinRoomAgoraManager.swift diff --git a/Podfile b/Podfile index b0d34e3..fcd0f6c 100644 --- a/Podfile +++ b/Podfile @@ -35,6 +35,8 @@ target 'yinmeng-ios' do pod 'FFPopup' pod 'TXLiteAVSDK_TRTC', '~> 11.4.14530' pod 'MJExtension' +#声网 + pod 'AgoraRtcEngine_iOS', '~> 4.2.2' # Pods for yinmeng-ios end diff --git a/yinmeng-ios.xcodeproj/project.pbxproj b/yinmeng-ios.xcodeproj/project.pbxproj index 672caf6..524dac6 100644 --- a/yinmeng-ios.xcodeproj/project.pbxproj +++ b/yinmeng-ios.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ 23630BBB2BAD2EBB003AD25D /* YinClientInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBA2BAD2EBB003AD25D /* YinClientInfoModel.swift */; }; 23630BBD2BAD379C003AD25D /* YinRoomAudioManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */; }; 23630BBF2BAD37B7003AD25D /* YinRoomTRTCManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.swift */; }; + 23630BC12BAD5537003AD25D /* YinRoomAgoraManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BC02BAD5537003AD25D /* YinRoomAgoraManager.swift */; }; 238A900C2BAAC6C600828123 /* HomeVoiceSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 238A900B2BAAC6C600828123 /* HomeVoiceSearchView.swift */; }; 23EE96E02B9EB22100475D69 /* RoomMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE96DF2B9EB22100475D69 /* RoomMenuView.swift */; }; 23EE96E22B9EB22F00475D69 /* RoomSendTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE96E12B9EB22F00475D69 /* RoomSendTextView.swift */; }; @@ -219,6 +220,7 @@ 23630BBA2BAD2EBB003AD25D /* YinClientInfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinClientInfoModel.swift; sourceTree = ""; }; 23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomAudioManager.swift; sourceTree = ""; }; 23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomTRTCManager.swift; sourceTree = ""; }; + 23630BC02BAD5537003AD25D /* YinRoomAgoraManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomAgoraManager.swift; sourceTree = ""; }; 238A900B2BAAC6C600828123 /* HomeVoiceSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeVoiceSearchView.swift; sourceTree = ""; }; 23EE96DF2B9EB22100475D69 /* RoomMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMenuView.swift; sourceTree = ""; }; 23EE96E12B9EB22F00475D69 /* RoomSendTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomSendTextView.swift; sourceTree = ""; }; @@ -394,6 +396,7 @@ children = ( 23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */, 23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.swift */, + 23630BC02BAD5537003AD25D /* YinRoomAgoraManager.swift */, ); path = Tool; sourceTree = ""; @@ -1343,6 +1346,7 @@ 2311D6B32B906EDA001C70AB /* HomeVoiceGuideView.swift in Sources */, E8D15ABF2B8B885700369467 /* UserObject.swift in Sources */, 2311D6B52B907053001C70AB /* HomeVoiceUserInfoView.swift in Sources */, + 23630BC12BAD5537003AD25D /* YinRoomAgoraManager.swift in Sources */, E86A43BF2B8620C40084C04D /* Utils.swift in Sources */, E86A43BA2B85F1360084C04D /* AuthLoginVC.swift in Sources */, E8D15ABC2B8B87BA00369467 /* UserViewModel.swift in Sources */, diff --git a/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h b/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h index 4772c04..d3892fc 100644 --- a/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h +++ b/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h @@ -12,3 +12,4 @@ #import #import #import +#import diff --git a/yinmeng-ios/Base/Utils/AppKeys.swift b/yinmeng-ios/Base/Utils/AppKeys.swift index 6e42024..090526c 100644 --- a/yinmeng-ios/Base/Utils/AppKeys.swift +++ b/yinmeng-ios/Base/Utils/AppKeys.swift @@ -10,8 +10,10 @@ enum AppKeys { #if DEBUG static let nimAppid = "5d5a833a2d0ff1304a5d8bed53d2af5b" static let api = "http://beta.api.ymlive.fun/" + static let agoraKey = "5b4d929b6c4e4af190550c4a2ec5cd4c" #else static let nimAppid = "5e76ec47632d86c30ce18eabfa332b6a" static let api = "https://api.ymlive.fun/" + static let agoraKey = "5b4d929b6c4e4af190550c4a2ec5cd4c" #endif } diff --git a/yinmeng-ios/Modules/Room/Model/RoomDataModel.swift b/yinmeng-ios/Modules/Room/Model/RoomDataModel.swift index ea2dc57..1d5675e 100644 --- a/yinmeng-ios/Modules/Room/Model/RoomDataModel.swift +++ b/yinmeng-ios/Modules/Room/Model/RoomDataModel.swift @@ -23,5 +23,6 @@ struct RoomDataModel : HandyJSON { var onlineNum:Int = 0 var defUser = "" var type:Int = 3 + var audioSdkType = "" } diff --git a/yinmeng-ios/Modules/Room/Tool/YinRoomAgoraManager.swift b/yinmeng-ios/Modules/Room/Tool/YinRoomAgoraManager.swift new file mode 100644 index 0000000..8551262 --- /dev/null +++ b/yinmeng-ios/Modules/Room/Tool/YinRoomAgoraManager.swift @@ -0,0 +1,59 @@ +// +// YinRoomAgoraManager.swift +// yinmeng-ios +// +// Created by duoban on 2024/3/22. +// + +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"]) + } +} diff --git a/yinmeng-ios/Modules/Room/Tool/YinRoomAudioManager.swift b/yinmeng-ios/Modules/Room/Tool/YinRoomAudioManager.swift index 2901e42..59b9af7 100644 --- a/yinmeng-ios/Modules/Room/Tool/YinRoomAudioManager.swift +++ b/yinmeng-ios/Modules/Room/Tool/YinRoomAudioManager.swift @@ -7,6 +7,71 @@ import UIKit -class YinRoomAudMioanager: NSObject { - +enum YinRoomAudMioanagerType { +case trtc,agora +} + +class YinRoomAudMioanager: NSObject { + static let share = YinRoomAudMioanager() + var type:YinRoomAudMioanagerType = .trtc + + + func dealWithChatData(roomData:RoomDataModel){ + type = roomData.audioSdkType == "trtc" ? .trtc : .agora + if type == .trtc{ + roomTRTCManager.roomData = roomData + roomTRTCManager.setTRTC() + }else{ + + agoraManager.initAgora(roomUid: roomData.roomId) + + + } + + } + + func muteLocalAudio(mute:Bool){ + if type == .trtc{ + roomTRTCManager.muteLocalAudio(mute: mute) + }else{ + agoraManager.muteLocalAudio(mute: mute) + } + } + func setBroadcast(isChange:Bool){ + if type == .trtc{ + roomTRTCManager.setBroadcast(isChange: isChange) + }else{ + agoraManager.setBroadcast(isChange: isChange) + } + } + func exitRoom(){ + if type == .trtc{ + roomTRTCManager.exitRoom() + }else{ + agoraManager.exitRoom() + } + } + + func destroySharedIntance(){ + if type == .trtc{ + roomTRTCManager.destroySharedIntance() + }else{ + agoraManager.destroySharedIntance() + } + } + + + + + //MARK: - 懒加载 + private lazy var roomTRTCManager:YinRoomTRTCManager = { + let _roomTRTCManager = YinRoomTRTCManager() + + return _roomTRTCManager + }() + private lazy var agoraManager:YinRoomAgoraManager = { + let _agoraManager = YinRoomAgoraManager() + + return _agoraManager + }() } diff --git a/yinmeng-ios/Modules/Room/Tool/YinRoomTRTCManager.swift b/yinmeng-ios/Modules/Room/Tool/YinRoomTRTCManager.swift index 2d07769..add2d60 100644 --- a/yinmeng-ios/Modules/Room/Tool/YinRoomTRTCManager.swift +++ b/yinmeng-ios/Modules/Room/Tool/YinRoomTRTCManager.swift @@ -8,8 +8,12 @@ import UIKit class YinRoomTRTCManager: NSObject { + + + override init() { - + super.init() + initRTRC() } private func initRTRC(){ let cloud = TRTCCloud.sharedInstance() @@ -19,8 +23,64 @@ class YinRoomTRTCManager: NSObject { TRTCCloud.setConsoleEnabled(false) TRTCCloud.sharedInstance().addDelegate(self) } + var roomData:RoomDataModel? + func setTRTC(){ + if let roomId = self.roomData?.roomId,let uid = self.roomData?.uid{ + let cloud = TRTCCloud.sharedInstance() + let curRoomId = (Int(roomId) ?? 0) > INT_MAX ? uid : roomId + let params = TRTCAudioVolumeEvaluateParams() + params.interval = 900 + cloud.enableAudioVolumeEvaluation(true, with: params) + let yinParams = TRTCParams() + if AuthViewModel.authVM.appId.isEmpty{ + + yinParams.sdkAppId = UInt32("1400798783") ?? 0 + }else{ + yinParams.sdkAppId = UInt32(AuthViewModel.authVM.appId) ?? 0 + } + yinParams.roomId = UInt32(curRoomId) ?? 0 + let uid = "\(AuthManager.userUid)" + yinParams.userId = uid + let sign = self.roomData?.trtcSig ?? "" + yinParams.userSig = sign + yinParams.role = TRTCRoleType.audience + TRTCCloud.sharedInstance().enterRoom(yinParams, appScene: TRTCAppScene.LIVE) + TRTCCloud.sharedInstance().muteAllRemoteAudio(false) + TRTCCloud.sharedInstance().muteLocalAudio(false) + RoomVCViewModel.roomVM.isMute = false + } + } + + func muteLocalAudio(mute:Bool){ + TRTCCloud.sharedInstance().muteLocalAudio(mute) + } + func setBroadcast(isChange:Bool){ + TRTCCloud.sharedInstance().switch(isChange ? .anchor : .audience) + if (isChange){ + let text = "{\"api\":\"setAudioQualityEx\",\"params\":{\"sampleRate\":48000,\"channel\":2,\"bitrate\":192,\"encodeMode\":1,\"systemVolumeType\":1}}" + TRTCCloud.sharedInstance().callExperimentalAPI(text) + let aecText = "{\"api\":\"enableAudioAEC\",\"params\":{\"enable\":1,\"level\":100}}" + TRTCCloud.sharedInstance().callExperimentalAPI(aecText) + TRTCCloud.sharedInstance().startLocalAudio(.music) + }else{ + TRTCCloud.sharedInstance().stopLocalAudio() + } + } + func exitRoom(){ + TRTCCloud.sharedInstance().exitRoom() + TRTCCloud.sharedInstance().muteAllRemoteAudio(false) + TRTCCloud.sharedInstance().muteLocalAudio(false) + } + + + func destroySharedIntance(){ + TRTCCloud.destroySharedIntance() + } } extension YinRoomTRTCManager:TRTCCloudDelegate{ - + func onUserVoiceVolume(_ userVolumes: [TRTCVolumeInfo], totalVolume: Int) { + + NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kReceiveUserVoiceVolume") , object: nil, userInfo: ["userVolumes":userVolumes,"totalVolume":totalVolume,"type":"trtc"]) + } } diff --git a/yinmeng-ios/Modules/Room/VC/RoomVC.swift b/yinmeng-ios/Modules/Room/VC/RoomVC.swift index cc4cc63..fcbaf6e 100644 --- a/yinmeng-ios/Modules/Room/VC/RoomVC.swift +++ b/yinmeng-ios/Modules/Room/VC/RoomVC.swift @@ -13,7 +13,7 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol { self.roomUid = roomUid } deinit { - TRTCCloud.destroySharedIntance() + YinRoomAudMioanager.share.destroySharedIntance() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") @@ -43,18 +43,14 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol { topView.didClickTypeBlcok = {[weak self] (type,uid) in guard let self = self else { return} if type == 0{ - TRTCCloud.sharedInstance().exitRoom() - TRTCCloud.sharedInstance().muteAllRemoteAudio(false) - TRTCCloud.sharedInstance().muteLocalAudio(false) + YinRoomAudMioanager.share.exitRoom() RoomVCViewModel.roomVM.isMute = true NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "") self.dismiss(animated: true, completion: nil) }else if type == 1 { - TRTCCloud.sharedInstance().exitRoom() - TRTCCloud.sharedInstance().muteAllRemoteAudio(false) - TRTCCloud.sharedInstance().muteLocalAudio(false) + YinRoomAudMioanager.share.exitRoom() RoomVCViewModel.roomVM.isMute = true NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "") self.dismiss(animated: true, completion: nil) @@ -161,11 +157,13 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol { } private func dealWithChatData(chatData:NIMChatroom){ - self.topView.roomData = self.roomInfo - self.micSeatView.roomData = self.roomInfo - self.micSeatView.setTRTC() - self.micSeatView.setMicList() - self.menuView.roomUid = self.roomInfo?.roomId ?? "" + topView.roomData = self.roomInfo + micSeatView.roomData = self.roomInfo + if let roomInfo = self.roomInfo{ + YinRoomAudMioanager.share.dealWithChatData(roomData:roomInfo) + } + micSeatView.setMicList() + menuView.roomUid = self.roomInfo?.roomId ?? "" } private func dealWithRoomData(roomData:RoomDataModel){ let uid = AuthManager.userUid @@ -231,6 +229,7 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol { return _chatListVC }() + } extension RoomVC : NIMChatManagerDelegate, NIMChatroomManagerDelegate, NIMLoginManagerDelegate, NIMConversationManagerDelegate{ diff --git a/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/NormalMicSeatSuperView.swift b/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/NormalMicSeatSuperView.swift index 03d94fc..203a906 100644 --- a/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/NormalMicSeatSuperView.swift +++ b/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/NormalMicSeatSuperView.swift @@ -14,15 +14,69 @@ typealias ShowUserInfoBlock = (_ user:UserObject)->Void class NormalMicSeatSuperView: MicSeatSuperView { var showUserInfoBlock:ShowUserInfoBlock? + deinit{ + NotificationCenter.default.removeObserver(self) + } override init(frame: CGRect) { super.init(frame: frame) setUILayout() setUserList() registerCell() - initRTRC() - + + NotificationCenter.default.addObserver(self, selector: #selector(receiveUserVoiceVolume(not:)), name: NSNotification.Name(rawValue: "kReceiveUserVoiceVolume"), object: nil) + } + @objc func receiveUserVoiceVolume(not:Notification){ + + if let userInfo = not.userInfo as? [NSString:Any],let type = userInfo["type"] as? String{ + var uidList:[String] = [] + if let userVolumes: [TRTCVolumeInfo] = userInfo["userVolumes"] as? [TRTCVolumeInfo],let totalVolume = userInfo["totalVolume"] as? Int ,type == "trtc"{ + + for item in userVolumes { + + if item.userId == nil{ + if (item.volume > 2){ + uidList.append("\(AuthManager.userUid)") + } + + }else{ + if item.volume > 2{ + + uidList.append(item.userId!) + } + } + + } + + }else{ + if let userVolumes: [AgoraRtcAudioVolumeInfo] = userInfo["userVolumes"] as? [AgoraRtcAudioVolumeInfo] { + for item in userVolumes { + if item.volume > 15{ + if item.uid == 0{ + uidList.append("\(AuthManager.userUid)") + }else{ + uidList.append("\(item.uid)") + } + } + } + } + } + for uid in uidList { + if RoomVCViewModel.roomVM.isMute == true,uid == "\(AuthManager.userUid)"{ + continue + } + if let user = roomOwnerView.user,let curUid = user.uid,uid == "\(curUid)"{ + roomOwnerView.startPlay() + } + for i in 0..<8 { + if let cell = collectionView.cellForItem(at: IndexPath(row: i, section: 0)) as? NormalMicSeatCell{ + if let user = cell.user,let curUid = user.uid,"\(curUid)" == uid{ + cell.micSeatView.startPlay() + } + } + } + } + } } - required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -76,15 +130,12 @@ class NormalMicSeatSuperView: MicSeatSuperView { popUpView.senderView.setTitle("确定", for: .normal) popUpView.bgPointView.isHidden = true popUpView.pointTextView.isHidden = true - popUpView.clickSendBlcok = {[weak self] in + popUpView.clickSendBlcok = { let downRequest = NIMChatroomQueueRemoveRequest() downRequest.key = "\(-1)" downRequest.roomId = roomid - NIMSDK.shared().chatroomManager.removeChatroomQueueObject(downRequest) {[weak self] (error, info) in - guard let self = self else{return} - if error == nil{ - - } + NIMSDK.shared().chatroomManager.removeChatroomQueueObject(downRequest) { (error, info) in + } } @@ -115,40 +166,8 @@ class NormalMicSeatSuperView: MicSeatSuperView { collectionView.delegate = self collectionView.dataSource = self } - private func initRTRC(){ - let cloud = TRTCCloud.sharedInstance() - let params = TRTCAudioVolumeEvaluateParams() - params.interval = 900 - cloud.enableAudioVolumeEvaluation(true, with: params) - TRTCCloud.setConsoleEnabled(false) - TRTCCloud.sharedInstance().addDelegate(self) - } - func setTRTC(){ - if let roomId = self.roomData?.roomId,let uid = self.roomData?.uid{ - let cloud = TRTCCloud.sharedInstance() - let curRoomId = (Int(roomId) ?? 0) > INT_MAX ? uid : roomId - let params = TRTCAudioVolumeEvaluateParams() - params.interval = 900 - cloud.enableAudioVolumeEvaluation(true, with: params) - let yinParams = TRTCParams() - if AuthViewModel.authVM.appId.isEmpty{ - - yinParams.sdkAppId = UInt32("1400798783") ?? 0 - }else{ - yinParams.sdkAppId = UInt32(AuthViewModel.authVM.appId) ?? 0 - } - yinParams.roomId = UInt32(curRoomId) ?? 0 - let uid = "\(AuthManager.userUid)" - yinParams.userId = uid - let sign = self.roomData?.trtcSig ?? "" - yinParams.userSig = sign - yinParams.role = TRTCRoleType.audience - TRTCCloud.sharedInstance().enterRoom(yinParams, appScene: TRTCAppScene.LIVE) - TRTCCloud.sharedInstance().muteAllRemoteAudio(false) - TRTCCloud.sharedInstance().muteLocalAudio(false) - RoomVCViewModel.roomVM.isMute = false - } - } + + func setMicList(){ if let roomid = self.roomData?.roomId{ NIMSDK.shared().chatroomManager.fetchChatroomQueue(roomid) { error, data in @@ -293,7 +312,7 @@ extension NormalMicSeatSuperView:UICollectionViewDelegate,UICollectionViewDataSo roomOwnerView.user = userData }else if changeType == 2{ roomOwnerView.user = nil - roomOwnerView.speakView.isHidden = true + } }else{ if changeType == 1,let i = Int(pos){ @@ -302,7 +321,7 @@ extension NormalMicSeatSuperView:UICollectionViewDelegate,UICollectionViewDataSo }else if changeType == 2,let i = Int(pos){ let user = roomUserList[i] if let cell = collectionView.cellForItem(at: IndexPath(row: i, section: 0)) as? NormalMicSeatCell{ - cell.micSeatView.speakView.isHidden = true + user.user = nil } } @@ -375,54 +394,5 @@ extension NormalMicSeatSuperView:UICollectionViewDelegate,UICollectionViewDataSo } } -extension NormalMicSeatSuperView:TRTCCloudDelegate{ - func onUserVoiceVolume(_ userVolumes: [TRTCVolumeInfo], totalVolume: Int) { - - var uidList:[String] = [] - for item in userVolumes { - - if item.userId == nil{ - if (item.volume > 2){ - uidList.append("\(AuthManager.userUid)") - } - - }else{ - if item.volume > 2{ - - uidList.append(item.userId!) - } - } - - } - roomOwnerView.speakView.isHidden = true - for i in 0..<8 { - if let cell = collectionView.cellForItem(at: IndexPath(row: i, section: 0)) as? NormalMicSeatCell{ - cell.micSeatView.speakView.isHidden = true - } - - - - } - for uid in uidList { - if RoomVCViewModel.roomVM.isMute == true,uid == "\(AuthManager.userUid)"{ - continue - } - if let user = roomOwnerView.user,let curUid = user.uid,uid == "\(curUid)"{ - - roomOwnerView.speakView.isHidden = false - - - } - for i in 0..<8 { - if let cell = collectionView.cellForItem(at: IndexPath(row: i, section: 0)) as? NormalMicSeatCell{ - if let user = cell.user,let curUid = user.uid,"\(curUid)" == uid{ - cell.micSeatView.speakView.isHidden = false - }else{ - cell.micSeatView.speakView.isHidden = true - } - } - } - } - } -} + diff --git a/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/SubView/NormalMicSeatView.swift b/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/SubView/NormalMicSeatView.swift index d8f4bbd..5e77a5f 100644 --- a/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/SubView/NormalMicSeatView.swift +++ b/yinmeng-ios/Modules/Room/View/MicSeatView/View/MicSeatSuperView/SubView/NormalMicSeatView.swift @@ -23,7 +23,7 @@ class NormalMicSeatView: UIView { } var user:UserObject? = nil{ didSet{ - speakView.isHidden = true + guard let _user = user else { if isOwner { @@ -82,15 +82,6 @@ class NormalMicSeatView: UIView { genderView.isHidden = true postionView.isHidden = true - speakParser.parse(withNamed: "YinSpeak", in: Bundle.main) {[weak self] videoItem in - - self?.speakView.videoItem = videoItem - self?.speakView.loops = 100000; - self?.speakView.clearsAfterStop = false - self?.speakView.startAnimation() - } failureBlock: { error in - - } } private func setUILayout(){ addSubview(speakView) @@ -128,11 +119,16 @@ class NormalMicSeatView: UIView { avatarView.layer.cornerRadius = UIDevice.scaleWidth(width: 50) / 2 genderView.isHidden = true postionView.isHidden = false + + } + func startPlay(){ + if isPlay {return} speakParser.parse(withNamed: "YinSpeak", in: Bundle.main) {[weak self] videoItem in self?.speakView.videoItem = videoItem - self?.speakView.loops = 100000; - self?.speakView.clearsAfterStop = false + self?.speakView.loops = 1; + self?.speakView.clearsAfterStop = true + self?.isPlay = true self?.speakView.startAnimation() } failureBlock: { error in @@ -183,12 +179,17 @@ class NormalMicSeatView: UIView { let _speakView = SVGAImageView() _speakView.contentMode = .scaleAspectFill _speakView.isUserInteractionEnabled = true - _speakView.isHidden = true + _speakView.delegate = self return _speakView }() private lazy var speakParser:SVGAParser = { let _speakParser = SVGAParser() return _speakParser }() + var isPlay = false +} +extension NormalMicSeatView:SVGAPlayerDelegate{ + func svgaPlayerDidFinishedAnimation(_ player: SVGAPlayer!) { + self.isPlay = false + } } - diff --git a/yinmeng-ios/Modules/Room/View/RoomMenuView/View/RoomMenuView.swift b/yinmeng-ios/Modules/Room/View/RoomMenuView/View/RoomMenuView.swift index 638222b..4f37a1f 100644 --- a/yinmeng-ios/Modules/Room/View/RoomMenuView/View/RoomMenuView.swift +++ b/yinmeng-ios/Modules/Room/View/RoomMenuView/View/RoomMenuView.swift @@ -66,11 +66,11 @@ class RoomMenuView: UIView { @objc func clickMicBtnAction(){ micBtn.isSelected = !micBtn.isSelected if micBtn.isSelected { - TRTCCloud.sharedInstance().muteLocalAudio(true) + YinRoomAudMioanager.share.muteLocalAudio(mute: true) RoomVCViewModel.roomVM.isMute = true return } - TRTCCloud.sharedInstance().muteLocalAudio(false) + YinRoomAudMioanager.share.muteLocalAudio(mute: false) RoomVCViewModel.roomVM.isMute = false } @@ -91,14 +91,14 @@ class RoomMenuView: UIView { micBtn.isHidden = false micBtn.isSelected = true isHaveChange = true - TRTCCloud.sharedInstance().muteLocalAudio(true) + YinRoomAudMioanager.share.muteLocalAudio(mute: true) RoomVCViewModel.roomVM.isMute = true } }else if changeType == 2{ if AuthManager.userUid == userData.uid{ micBtn.isHidden = true - TRTCCloud.sharedInstance().muteLocalAudio(true) + YinRoomAudMioanager.share.muteLocalAudio(mute: true) RoomVCViewModel.roomVM.isMute = true } } @@ -106,7 +106,8 @@ class RoomMenuView: UIView { } if isHaveChange{ - setBroadcast(isChange: isHaveChange) + YinRoomAudMioanager.share.setBroadcast(isChange: isHaveChange) + } } @@ -117,18 +118,7 @@ class RoomMenuView: UIView { } } } - func setBroadcast(isChange:Bool){ - TRTCCloud.sharedInstance().switch(isChange ? .anchor : .audience) - if (isChange){ - let text = "{\"api\":\"setAudioQualityEx\",\"params\":{\"sampleRate\":48000,\"channel\":2,\"bitrate\":192,\"encodeMode\":1,\"systemVolumeType\":1}}" - TRTCCloud.sharedInstance().callExperimentalAPI(text) - let aecText = "{\"api\":\"enableAudioAEC\",\"params\":{\"enable\":1,\"level\":100}}" - TRTCCloud.sharedInstance().callExperimentalAPI(aecText) - TRTCCloud.sharedInstance().startLocalAudio(.music) - }else{ - TRTCCloud.sharedInstance().stopLocalAudio() - } - } + var sendTextView:RoomSendTextView = { let bottom = ScreenHeight + 40 let _sendTextView = RoomSendTextView(frame: CGRect(x: 0, y: bottom, width: ScreenWidth, height: UIDevice.scaleWidth(width: 40)))