接入声网
This commit is contained in:
2
Podfile
2
Podfile
@@ -35,6 +35,8 @@ target 'yinmeng-ios' do
|
|||||||
pod 'FFPopup'
|
pod 'FFPopup'
|
||||||
pod 'TXLiteAVSDK_TRTC', '~> 11.4.14530'
|
pod 'TXLiteAVSDK_TRTC', '~> 11.4.14530'
|
||||||
pod 'MJExtension'
|
pod 'MJExtension'
|
||||||
|
#声网
|
||||||
|
pod 'AgoraRtcEngine_iOS', '~> 4.2.2'
|
||||||
# Pods for yinmeng-ios
|
# Pods for yinmeng-ios
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@@ -69,6 +69,7 @@
|
|||||||
23630BBB2BAD2EBB003AD25D /* YinClientInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBA2BAD2EBB003AD25D /* YinClientInfoModel.swift */; };
|
23630BBB2BAD2EBB003AD25D /* YinClientInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBA2BAD2EBB003AD25D /* YinClientInfoModel.swift */; };
|
||||||
23630BBD2BAD379C003AD25D /* YinRoomAudioManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */; };
|
23630BBD2BAD379C003AD25D /* YinRoomAudioManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */; };
|
||||||
23630BBF2BAD37B7003AD25D /* YinRoomTRTCManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.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 */; };
|
238A900C2BAAC6C600828123 /* HomeVoiceSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 238A900B2BAAC6C600828123 /* HomeVoiceSearchView.swift */; };
|
||||||
23EE96E02B9EB22100475D69 /* RoomMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE96DF2B9EB22100475D69 /* RoomMenuView.swift */; };
|
23EE96E02B9EB22100475D69 /* RoomMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE96DF2B9EB22100475D69 /* RoomMenuView.swift */; };
|
||||||
23EE96E22B9EB22F00475D69 /* RoomSendTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE96E12B9EB22F00475D69 /* RoomSendTextView.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 = "<group>"; };
|
23630BBA2BAD2EBB003AD25D /* YinClientInfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinClientInfoModel.swift; sourceTree = "<group>"; };
|
||||||
23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomAudioManager.swift; sourceTree = "<group>"; };
|
23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomAudioManager.swift; sourceTree = "<group>"; };
|
||||||
23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomTRTCManager.swift; sourceTree = "<group>"; };
|
23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomTRTCManager.swift; sourceTree = "<group>"; };
|
||||||
|
23630BC02BAD5537003AD25D /* YinRoomAgoraManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YinRoomAgoraManager.swift; sourceTree = "<group>"; };
|
||||||
238A900B2BAAC6C600828123 /* HomeVoiceSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeVoiceSearchView.swift; sourceTree = "<group>"; };
|
238A900B2BAAC6C600828123 /* HomeVoiceSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeVoiceSearchView.swift; sourceTree = "<group>"; };
|
||||||
23EE96DF2B9EB22100475D69 /* RoomMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMenuView.swift; sourceTree = "<group>"; };
|
23EE96DF2B9EB22100475D69 /* RoomMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMenuView.swift; sourceTree = "<group>"; };
|
||||||
23EE96E12B9EB22F00475D69 /* RoomSendTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomSendTextView.swift; sourceTree = "<group>"; };
|
23EE96E12B9EB22F00475D69 /* RoomSendTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomSendTextView.swift; sourceTree = "<group>"; };
|
||||||
@@ -394,6 +396,7 @@
|
|||||||
children = (
|
children = (
|
||||||
23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */,
|
23630BBC2BAD379C003AD25D /* YinRoomAudioManager.swift */,
|
||||||
23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.swift */,
|
23630BBE2BAD37B7003AD25D /* YinRoomTRTCManager.swift */,
|
||||||
|
23630BC02BAD5537003AD25D /* YinRoomAgoraManager.swift */,
|
||||||
);
|
);
|
||||||
path = Tool;
|
path = Tool;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -1343,6 +1346,7 @@
|
|||||||
2311D6B32B906EDA001C70AB /* HomeVoiceGuideView.swift in Sources */,
|
2311D6B32B906EDA001C70AB /* HomeVoiceGuideView.swift in Sources */,
|
||||||
E8D15ABF2B8B885700369467 /* UserObject.swift in Sources */,
|
E8D15ABF2B8B885700369467 /* UserObject.swift in Sources */,
|
||||||
2311D6B52B907053001C70AB /* HomeVoiceUserInfoView.swift in Sources */,
|
2311D6B52B907053001C70AB /* HomeVoiceUserInfoView.swift in Sources */,
|
||||||
|
23630BC12BAD5537003AD25D /* YinRoomAgoraManager.swift in Sources */,
|
||||||
E86A43BF2B8620C40084C04D /* Utils.swift in Sources */,
|
E86A43BF2B8620C40084C04D /* Utils.swift in Sources */,
|
||||||
E86A43BA2B85F1360084C04D /* AuthLoginVC.swift in Sources */,
|
E86A43BA2B85F1360084C04D /* AuthLoginVC.swift in Sources */,
|
||||||
E8D15ABC2B8B87BA00369467 /* UserViewModel.swift in Sources */,
|
E8D15ABC2B8B87BA00369467 /* UserViewModel.swift in Sources */,
|
||||||
|
@@ -12,3 +12,4 @@
|
|||||||
#import <TXLiteAVSDK_TRTC/TRTCCloud.h>
|
#import <TXLiteAVSDK_TRTC/TRTCCloud.h>
|
||||||
#import <JXCategoryView/JXCategoryView.h>
|
#import <JXCategoryView/JXCategoryView.h>
|
||||||
#import <JXCategoryView/JXCategoryListContainerView.h>
|
#import <JXCategoryView/JXCategoryListContainerView.h>
|
||||||
|
#import <AgoraRtcKit/AgoraRtcEngineKit.h>
|
||||||
|
@@ -10,8 +10,10 @@ enum AppKeys {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
static let nimAppid = "5d5a833a2d0ff1304a5d8bed53d2af5b"
|
static let nimAppid = "5d5a833a2d0ff1304a5d8bed53d2af5b"
|
||||||
static let api = "http://beta.api.ymlive.fun/"
|
static let api = "http://beta.api.ymlive.fun/"
|
||||||
|
static let agoraKey = "5b4d929b6c4e4af190550c4a2ec5cd4c"
|
||||||
#else
|
#else
|
||||||
static let nimAppid = "5e76ec47632d86c30ce18eabfa332b6a"
|
static let nimAppid = "5e76ec47632d86c30ce18eabfa332b6a"
|
||||||
static let api = "https://api.ymlive.fun/"
|
static let api = "https://api.ymlive.fun/"
|
||||||
|
static let agoraKey = "5b4d929b6c4e4af190550c4a2ec5cd4c"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -23,5 +23,6 @@ struct RoomDataModel : HandyJSON {
|
|||||||
var onlineNum:Int = 0
|
var onlineNum:Int = 0
|
||||||
var defUser = ""
|
var defUser = ""
|
||||||
var type:Int = 3
|
var type:Int = 3
|
||||||
|
var audioSdkType = ""
|
||||||
|
|
||||||
}
|
}
|
||||||
|
59
yinmeng-ios/Modules/Room/Tool/YinRoomAgoraManager.swift
Normal file
59
yinmeng-ios/Modules/Room/Tool/YinRoomAgoraManager.swift
Normal file
@@ -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"])
|
||||||
|
}
|
||||||
|
}
|
@@ -7,6 +7,71 @@
|
|||||||
|
|
||||||
import UIKit
|
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
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
@@ -8,8 +8,12 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class YinRoomTRTCManager: NSObject {
|
class YinRoomTRTCManager: NSObject {
|
||||||
override init() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
initRTRC()
|
||||||
}
|
}
|
||||||
private func initRTRC(){
|
private func initRTRC(){
|
||||||
let cloud = TRTCCloud.sharedInstance()
|
let cloud = TRTCCloud.sharedInstance()
|
||||||
@@ -19,8 +23,64 @@ class YinRoomTRTCManager: NSObject {
|
|||||||
TRTCCloud.setConsoleEnabled(false)
|
TRTCCloud.setConsoleEnabled(false)
|
||||||
TRTCCloud.sharedInstance().addDelegate(self)
|
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{
|
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"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
|||||||
self.roomUid = roomUid
|
self.roomUid = roomUid
|
||||||
}
|
}
|
||||||
deinit {
|
deinit {
|
||||||
TRTCCloud.destroySharedIntance()
|
YinRoomAudMioanager.share.destroySharedIntance()
|
||||||
}
|
}
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
@@ -43,18 +43,14 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
|||||||
topView.didClickTypeBlcok = {[weak self] (type,uid) in
|
topView.didClickTypeBlcok = {[weak self] (type,uid) in
|
||||||
guard let self = self else { return}
|
guard let self = self else { return}
|
||||||
if type == 0{
|
if type == 0{
|
||||||
TRTCCloud.sharedInstance().exitRoom()
|
YinRoomAudMioanager.share.exitRoom()
|
||||||
TRTCCloud.sharedInstance().muteAllRemoteAudio(false)
|
|
||||||
TRTCCloud.sharedInstance().muteLocalAudio(false)
|
|
||||||
RoomVCViewModel.roomVM.isMute = true
|
RoomVCViewModel.roomVM.isMute = true
|
||||||
NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "")
|
NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "")
|
||||||
self.dismiss(animated: true, completion: nil)
|
self.dismiss(animated: true, completion: nil)
|
||||||
|
|
||||||
}else if type == 1 {
|
}else if type == 1 {
|
||||||
|
|
||||||
TRTCCloud.sharedInstance().exitRoom()
|
YinRoomAudMioanager.share.exitRoom()
|
||||||
TRTCCloud.sharedInstance().muteAllRemoteAudio(false)
|
|
||||||
TRTCCloud.sharedInstance().muteLocalAudio(false)
|
|
||||||
RoomVCViewModel.roomVM.isMute = true
|
RoomVCViewModel.roomVM.isMute = true
|
||||||
NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "")
|
NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "")
|
||||||
self.dismiss(animated: true, completion: nil)
|
self.dismiss(animated: true, completion: nil)
|
||||||
@@ -161,11 +157,13 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
|||||||
|
|
||||||
}
|
}
|
||||||
private func dealWithChatData(chatData:NIMChatroom){
|
private func dealWithChatData(chatData:NIMChatroom){
|
||||||
self.topView.roomData = self.roomInfo
|
topView.roomData = self.roomInfo
|
||||||
self.micSeatView.roomData = self.roomInfo
|
micSeatView.roomData = self.roomInfo
|
||||||
self.micSeatView.setTRTC()
|
if let roomInfo = self.roomInfo{
|
||||||
self.micSeatView.setMicList()
|
YinRoomAudMioanager.share.dealWithChatData(roomData:roomInfo)
|
||||||
self.menuView.roomUid = self.roomInfo?.roomId ?? ""
|
}
|
||||||
|
micSeatView.setMicList()
|
||||||
|
menuView.roomUid = self.roomInfo?.roomId ?? ""
|
||||||
}
|
}
|
||||||
private func dealWithRoomData(roomData:RoomDataModel){
|
private func dealWithRoomData(roomData:RoomDataModel){
|
||||||
let uid = AuthManager.userUid
|
let uid = AuthManager.userUid
|
||||||
@@ -231,6 +229,7 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
|||||||
|
|
||||||
return _chatListVC
|
return _chatListVC
|
||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension RoomVC : NIMChatManagerDelegate, NIMChatroomManagerDelegate, NIMLoginManagerDelegate, NIMConversationManagerDelegate{
|
extension RoomVC : NIMChatManagerDelegate, NIMChatroomManagerDelegate, NIMLoginManagerDelegate, NIMConversationManagerDelegate{
|
||||||
|
@@ -14,15 +14,69 @@ typealias ShowUserInfoBlock = (_ user:UserObject)->Void
|
|||||||
|
|
||||||
class NormalMicSeatSuperView: MicSeatSuperView {
|
class NormalMicSeatSuperView: MicSeatSuperView {
|
||||||
var showUserInfoBlock:ShowUserInfoBlock?
|
var showUserInfoBlock:ShowUserInfoBlock?
|
||||||
|
deinit{
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
}
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
setUILayout()
|
setUILayout()
|
||||||
setUserList()
|
setUserList()
|
||||||
registerCell()
|
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) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
@@ -76,15 +130,12 @@ class NormalMicSeatSuperView: MicSeatSuperView {
|
|||||||
popUpView.senderView.setTitle("确定", for: .normal)
|
popUpView.senderView.setTitle("确定", for: .normal)
|
||||||
popUpView.bgPointView.isHidden = true
|
popUpView.bgPointView.isHidden = true
|
||||||
popUpView.pointTextView.isHidden = true
|
popUpView.pointTextView.isHidden = true
|
||||||
popUpView.clickSendBlcok = {[weak self] in
|
popUpView.clickSendBlcok = {
|
||||||
let downRequest = NIMChatroomQueueRemoveRequest()
|
let downRequest = NIMChatroomQueueRemoveRequest()
|
||||||
downRequest.key = "\(-1)"
|
downRequest.key = "\(-1)"
|
||||||
downRequest.roomId = roomid
|
downRequest.roomId = roomid
|
||||||
NIMSDK.shared().chatroomManager.removeChatroomQueueObject(downRequest) {[weak self] (error, info) in
|
NIMSDK.shared().chatroomManager.removeChatroomQueueObject(downRequest) { (error, info) in
|
||||||
guard let self = self else{return}
|
|
||||||
if error == nil{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,40 +166,8 @@ class NormalMicSeatSuperView: MicSeatSuperView {
|
|||||||
collectionView.delegate = self
|
collectionView.delegate = self
|
||||||
collectionView.dataSource = 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(){
|
func setMicList(){
|
||||||
if let roomid = self.roomData?.roomId{
|
if let roomid = self.roomData?.roomId{
|
||||||
NIMSDK.shared().chatroomManager.fetchChatroomQueue(roomid) { error, data in
|
NIMSDK.shared().chatroomManager.fetchChatroomQueue(roomid) { error, data in
|
||||||
@@ -293,7 +312,7 @@ extension NormalMicSeatSuperView:UICollectionViewDelegate,UICollectionViewDataSo
|
|||||||
roomOwnerView.user = userData
|
roomOwnerView.user = userData
|
||||||
}else if changeType == 2{
|
}else if changeType == 2{
|
||||||
roomOwnerView.user = nil
|
roomOwnerView.user = nil
|
||||||
roomOwnerView.speakView.isHidden = true
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if changeType == 1,let i = Int(pos){
|
if changeType == 1,let i = Int(pos){
|
||||||
@@ -302,7 +321,7 @@ extension NormalMicSeatSuperView:UICollectionViewDelegate,UICollectionViewDataSo
|
|||||||
}else if changeType == 2,let i = Int(pos){
|
}else if changeType == 2,let i = Int(pos){
|
||||||
let user = roomUserList[i]
|
let user = roomUserList[i]
|
||||||
if let cell = collectionView.cellForItem(at: IndexPath(row: i, section: 0)) as? NormalMicSeatCell{
|
if let cell = collectionView.cellForItem(at: IndexPath(row: i, section: 0)) as? NormalMicSeatCell{
|
||||||
cell.micSeatView.speakView.isHidden = true
|
|
||||||
user.user = nil
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ class NormalMicSeatView: UIView {
|
|||||||
}
|
}
|
||||||
var user:UserObject? = nil{
|
var user:UserObject? = nil{
|
||||||
didSet{
|
didSet{
|
||||||
speakView.isHidden = true
|
|
||||||
guard let _user = user else {
|
guard let _user = user else {
|
||||||
|
|
||||||
if isOwner {
|
if isOwner {
|
||||||
@@ -82,15 +82,6 @@ class NormalMicSeatView: UIView {
|
|||||||
genderView.isHidden = true
|
genderView.isHidden = true
|
||||||
postionView.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(){
|
private func setUILayout(){
|
||||||
addSubview(speakView)
|
addSubview(speakView)
|
||||||
@@ -128,11 +119,16 @@ class NormalMicSeatView: UIView {
|
|||||||
avatarView.layer.cornerRadius = UIDevice.scaleWidth(width: 50) / 2
|
avatarView.layer.cornerRadius = UIDevice.scaleWidth(width: 50) / 2
|
||||||
genderView.isHidden = true
|
genderView.isHidden = true
|
||||||
postionView.isHidden = false
|
postionView.isHidden = false
|
||||||
|
|
||||||
|
}
|
||||||
|
func startPlay(){
|
||||||
|
if isPlay {return}
|
||||||
speakParser.parse(withNamed: "YinSpeak", in: Bundle.main) {[weak self] videoItem in
|
speakParser.parse(withNamed: "YinSpeak", in: Bundle.main) {[weak self] videoItem in
|
||||||
|
|
||||||
self?.speakView.videoItem = videoItem
|
self?.speakView.videoItem = videoItem
|
||||||
self?.speakView.loops = 100000;
|
self?.speakView.loops = 1;
|
||||||
self?.speakView.clearsAfterStop = false
|
self?.speakView.clearsAfterStop = true
|
||||||
|
self?.isPlay = true
|
||||||
self?.speakView.startAnimation()
|
self?.speakView.startAnimation()
|
||||||
} failureBlock: { error in
|
} failureBlock: { error in
|
||||||
|
|
||||||
@@ -183,12 +179,17 @@ class NormalMicSeatView: UIView {
|
|||||||
let _speakView = SVGAImageView()
|
let _speakView = SVGAImageView()
|
||||||
_speakView.contentMode = .scaleAspectFill
|
_speakView.contentMode = .scaleAspectFill
|
||||||
_speakView.isUserInteractionEnabled = true
|
_speakView.isUserInteractionEnabled = true
|
||||||
_speakView.isHidden = true
|
_speakView.delegate = self
|
||||||
return _speakView
|
return _speakView
|
||||||
}()
|
}()
|
||||||
private lazy var speakParser:SVGAParser = {
|
private lazy var speakParser:SVGAParser = {
|
||||||
let _speakParser = SVGAParser()
|
let _speakParser = SVGAParser()
|
||||||
return _speakParser
|
return _speakParser
|
||||||
}()
|
}()
|
||||||
|
var isPlay = false
|
||||||
|
}
|
||||||
|
extension NormalMicSeatView:SVGAPlayerDelegate{
|
||||||
|
func svgaPlayerDidFinishedAnimation(_ player: SVGAPlayer!) {
|
||||||
|
self.isPlay = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,11 +66,11 @@ class RoomMenuView: UIView {
|
|||||||
@objc func clickMicBtnAction(){
|
@objc func clickMicBtnAction(){
|
||||||
micBtn.isSelected = !micBtn.isSelected
|
micBtn.isSelected = !micBtn.isSelected
|
||||||
if micBtn.isSelected {
|
if micBtn.isSelected {
|
||||||
TRTCCloud.sharedInstance().muteLocalAudio(true)
|
YinRoomAudMioanager.share.muteLocalAudio(mute: true)
|
||||||
RoomVCViewModel.roomVM.isMute = true
|
RoomVCViewModel.roomVM.isMute = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
TRTCCloud.sharedInstance().muteLocalAudio(false)
|
YinRoomAudMioanager.share.muteLocalAudio(mute: false)
|
||||||
RoomVCViewModel.roomVM.isMute = false
|
RoomVCViewModel.roomVM.isMute = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,14 +91,14 @@ class RoomMenuView: UIView {
|
|||||||
micBtn.isHidden = false
|
micBtn.isHidden = false
|
||||||
micBtn.isSelected = true
|
micBtn.isSelected = true
|
||||||
isHaveChange = true
|
isHaveChange = true
|
||||||
TRTCCloud.sharedInstance().muteLocalAudio(true)
|
YinRoomAudMioanager.share.muteLocalAudio(mute: true)
|
||||||
RoomVCViewModel.roomVM.isMute = true
|
RoomVCViewModel.roomVM.isMute = true
|
||||||
}
|
}
|
||||||
}else if changeType == 2{
|
}else if changeType == 2{
|
||||||
|
|
||||||
if AuthManager.userUid == userData.uid{
|
if AuthManager.userUid == userData.uid{
|
||||||
micBtn.isHidden = true
|
micBtn.isHidden = true
|
||||||
TRTCCloud.sharedInstance().muteLocalAudio(true)
|
YinRoomAudMioanager.share.muteLocalAudio(mute: true)
|
||||||
RoomVCViewModel.roomVM.isMute = true
|
RoomVCViewModel.roomVM.isMute = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,8 @@ class RoomMenuView: UIView {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if isHaveChange{
|
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 = {
|
var sendTextView:RoomSendTextView = {
|
||||||
let bottom = ScreenHeight + 40
|
let bottom = ScreenHeight + 40
|
||||||
let _sendTextView = RoomSendTextView(frame: CGRect(x: 0, y: bottom, width: ScreenWidth, height: UIDevice.scaleWidth(width: 40)))
|
let _sendTextView = RoomSendTextView(frame: CGRect(x: 0, y: bottom, width: ScreenWidth, height: UIDevice.scaleWidth(width: 40)))
|
||||||
|
Reference in New Issue
Block a user