音萌商店包房间
This commit is contained in:
@@ -13,12 +13,16 @@ class AuthViewModel: NSObject {
|
||||
static let authVM = AuthViewModel.init()
|
||||
let data = PublishSubject<Bool>()
|
||||
let token = PublishSubject<UserTokenObject?>()
|
||||
var appId = ""
|
||||
let loginSuccess = BehaviorSubject(value: false)
|
||||
let resetPwd = PublishSubject<Bool>()
|
||||
|
||||
|
||||
|
||||
func appClientConfig() {
|
||||
RequestGet(path: "client/init", parma: [:]) { data in
|
||||
|
||||
if let _data = data as? [String:Any],let appId = _data["trtcAppId"] {
|
||||
AuthViewModel.authVM.appId = "\(appId)"
|
||||
}
|
||||
} fail: { code, message in
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class ChatNavView: BaseView {
|
||||
|
||||
private lazy var backBtn: UIButton = {
|
||||
let button = UIButton(type: .custom)
|
||||
button.setBtnClickRadius = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
||||
button.setImage(UIImage(named: "chat_back"), for: .normal)
|
||||
button.setImage(UIImage(named: "chat_back"), for: .selected)
|
||||
button.addTarget(self, action: #selector(backClick), for: .touchUpInside)
|
||||
|
||||
@@ -206,35 +206,38 @@ class HomeVoiceRecordView: UIView,UITextViewDelegate {
|
||||
let desc = self.signatureView.text.count == 0 ? "这个人很懒还没有签名" : self.signatureView.text
|
||||
|
||||
let dura = "\(self.time)"
|
||||
let url = self.recorder.path
|
||||
RequestPost(path: "voiceShow/publish", parma: ["gender":gender,"desc":desc ?? "","dura":dura,"url":url]) { data in
|
||||
if Thread.current.isMainThread {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: "发布成功")
|
||||
self.removeFromSuperview()
|
||||
} else {
|
||||
// 切换到 main 线程,处理
|
||||
DispatchQueue.main.async {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: "发布成功")
|
||||
self.removeFromSuperview()
|
||||
if let url = res?["path"]{
|
||||
RequestPost(path: "voiceShow/publish", parma: ["gender":gender,"desc":desc ?? "","dura":dura,"url":url]) { data in
|
||||
if Thread.current.isMainThread {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: "发布成功")
|
||||
self.removeFromSuperview()
|
||||
} else {
|
||||
// 切换到 main 线程,处理
|
||||
DispatchQueue.main.async {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: "发布成功")
|
||||
self.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} fail: { code, data in
|
||||
if Thread.current.isMainThread {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: data)
|
||||
} else {
|
||||
// 切换到 main 线程,处理
|
||||
DispatchQueue.main.async {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: data)
|
||||
|
||||
|
||||
} fail: { code, data in
|
||||
if Thread.current.isMainThread {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: data)
|
||||
} else {
|
||||
// 切换到 main 线程,处理
|
||||
DispatchQueue.main.async {
|
||||
self.activityView.removeFromSuperview()
|
||||
HUDTool.show(with: data)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, option: nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@ class HomeVoiceVC: BaseViewController,HiddenNavigationBarProtocol {
|
||||
publishView.playBtnAction()
|
||||
}
|
||||
}
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
requestData()
|
||||
requsetFansListData()
|
||||
}
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setUILayout()
|
||||
|
||||
27
yinmeng-ios/Modules/Room/Model/RoomChatData.swift
Normal file
27
yinmeng-ios/Modules/Room/Model/RoomChatData.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// RoomChatData.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import HandyJSON
|
||||
|
||||
struct RoomChatData : HandyJSON {
|
||||
var charmUrl = ""{
|
||||
didSet{
|
||||
charmNewUrl = MAIDESEncryptTool.getCharmImageUrl(charmUrl)
|
||||
}
|
||||
}
|
||||
var experUrl = ""{
|
||||
didSet{
|
||||
experNewUrl = MAIDESEncryptTool.getWealthImageUrl(experUrl)
|
||||
}
|
||||
}
|
||||
var experNewUrl = ""
|
||||
var charmNewUrl = ""
|
||||
var erbanNo = 0
|
||||
var fromUid = ""
|
||||
var gender:UserSexType = .Boy
|
||||
}
|
||||
26
yinmeng-ios/Modules/Room/Model/RoomDataModel.swift
Normal file
26
yinmeng-ios/Modules/Room/Model/RoomDataModel.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// RoomDataModel.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import HandyJSON
|
||||
|
||||
struct RoomDataModel : HandyJSON {
|
||||
var nick = ""
|
||||
var uid = ""
|
||||
var roomId = ""
|
||||
var trtcSig = ""
|
||||
var valid:Bool = false
|
||||
var erbanNo:Int = 0
|
||||
var title = ""
|
||||
var isRoomFans:Bool = false
|
||||
var roomPwd = ""
|
||||
var hasAnimationEffect = false
|
||||
var avatar = ""
|
||||
var onlineNum:Int = 0
|
||||
var defUser = ""
|
||||
|
||||
}
|
||||
@@ -4,20 +4,80 @@
|
||||
//
|
||||
// Created by duoban on 2024/3/6.
|
||||
//
|
||||
|
||||
import NIMSDK
|
||||
import UIKit
|
||||
|
||||
import NSObject_Rx
|
||||
class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
||||
|
||||
init(roomUid: String) {
|
||||
super.init(nibName:nil, bundle:nil)
|
||||
self.roomUid = roomUid
|
||||
}
|
||||
deinit {
|
||||
TRTCCloud.destroySharedIntance()
|
||||
}
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setUILayout()
|
||||
requestData()
|
||||
addNIMSDKManager()
|
||||
addChild(chatListVC)
|
||||
menuView.clickMenuViewBlcok = {[weak self] in
|
||||
guard let self = self else { return}
|
||||
self.view.addSubview(self.bgChatView)
|
||||
self.bgChatView.snp.makeConstraints { make in
|
||||
make.edges.equalTo(self.view)
|
||||
}
|
||||
let height = ScreenHeight * 2 / 3
|
||||
self.view.addSubview(self.chatListVC.view)
|
||||
self.chatListVC.view.layer.cornerRadius = 20
|
||||
self.chatListVC.view.layer.masksToBounds = true
|
||||
self.chatListVC.view.frame = CGRect(x: 0, y: ScreenHeight, width: ScreenWidth, height: height)
|
||||
UIView.animate(withDuration: 0.1) {
|
||||
self.chatListVC.view.frame = CGRect(x: 0, y:ScreenHeight - height, width: ScreenWidth, height: height)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
RoomVCViewModel.roomVM.isMute = true
|
||||
NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "")
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
return
|
||||
}
|
||||
TRTCCloud.sharedInstance().exitRoom()
|
||||
TRTCCloud.sharedInstance().muteAllRemoteAudio(false)
|
||||
TRTCCloud.sharedInstance().muteLocalAudio(false)
|
||||
RoomVCViewModel.roomVM.isMute = true
|
||||
NIMSDK.shared().chatroomManager.exitChatroom(self.roomInfo?.roomId ?? "")
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
let vc = RoomVC(roomUid: uid)
|
||||
let nav = BaseNavigationViewController.init(rootViewController: vc)
|
||||
nav.modalPresentationStyle = .fullScreen
|
||||
keyWindow.rootViewController?.present(nav, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private func addNIMSDKManager(){
|
||||
NIMSDK.shared().chatManager.add(self)
|
||||
NIMSDK.shared().chatroomManager.add(self)
|
||||
NIMSDK.shared().loginManager.add(self)
|
||||
NIMSDK.shared().conversationManager.add(self)
|
||||
}
|
||||
private func setUILayout(){
|
||||
view.addSubview(backgroundView)
|
||||
view.addSubview(topView)
|
||||
view.addSubview(micSeatView)
|
||||
view.addSubview(chatScreenView)
|
||||
view.addSubview(menuView)
|
||||
backgroundView.snp.makeConstraints { make in
|
||||
make.edges.equalTo(self.view)
|
||||
}
|
||||
@@ -34,14 +94,72 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
||||
make.top.equalTo(micSeatView.snp.bottom).offset(UIDevice.scaleWidth(width: 5))
|
||||
make.leading.equalTo(UIDevice.scaleWidth(width: 0))
|
||||
make.trailing.equalTo(-UIDevice.scaleWidth(width: 90))
|
||||
make.bottom.equalTo(-UIDevice.scaleWidth(width: 0))
|
||||
make.bottom.equalTo(menuView.snp.top).offset(-UIDevice.scaleWidth(width: 5))
|
||||
}
|
||||
let bottom = SafeAraeBottomHeight + UIDevice.scaleWidth(width: 8)
|
||||
menuView.snp.makeConstraints { make in
|
||||
make.leading.trailing.equalTo(view).inset(UIDevice.scaleWidth(width: 0))
|
||||
make.bottom.equalTo(-bottom)
|
||||
make.height.equalTo(UIDevice.scaleWidth(width: 40))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private func requestData(){
|
||||
let uid = AuthManager.userUid
|
||||
|
||||
RoomVCViewModel.roomVM.getRoomUserInfo(roomUid: roomUid, uid: "\(uid)")
|
||||
|
||||
|
||||
UserViewModel.userVM.selfInfo.subscribe(onNext: {[weak self] result in
|
||||
if let roomid = self?.roomInfo?.roomId{
|
||||
self?.chatScreenView.roomId = roomid
|
||||
RoomVCViewModel.roomVM.NIMSDKEnterRoom(roomId:roomid , user: result)
|
||||
self?.micSeatView.userData = result
|
||||
self?.menuView.user = result
|
||||
}
|
||||
|
||||
}).disposed(by: rx.disposeBag)
|
||||
|
||||
RoomVCViewModel.roomVM.roomData.subscribe {[weak self] result in
|
||||
self?.dealWithRoomData(roomData: result)
|
||||
}.disposed(by: rx.disposeBag)
|
||||
|
||||
RoomVCViewModel.roomVM.chatRoomData.subscribe {[weak self] room in
|
||||
self?.dealWithChatData(chatData: room)
|
||||
}.disposed(by: rx.disposeBag)
|
||||
|
||||
}
|
||||
private func dealWithChatData(chatData:NIMChatroom){
|
||||
// self.roomInfo?.onlineNum = chatData.onlineUserCount
|
||||
self.topView.roomData = self.roomInfo
|
||||
self.micSeatView.roomData = self.roomInfo
|
||||
self.micSeatView.setTRTC()
|
||||
self.micSeatView.setMicList()
|
||||
self.menuView.roomUid = self.roomInfo?.roomId ?? ""
|
||||
}
|
||||
private func dealWithRoomData(roomData:RoomDataModel){
|
||||
let uid = AuthManager.userUid
|
||||
self.roomInfo = roomData
|
||||
self.topView.roomData = roomData
|
||||
if roomData.valid{
|
||||
UserViewModel.userVM.getUserInfo(uid: uid)
|
||||
}else{
|
||||
RoomVCViewModel.roomVM.openRoom(title: self.roomInfo?.title ?? "", type: 3, roomPwd: "", roomDesc: "", backPic: "")
|
||||
}
|
||||
}
|
||||
@objc func dissChatViewAction(){
|
||||
let height = ScreenHeight * 2 / 3
|
||||
UIView.animate(withDuration: 0.1) {
|
||||
self.chatListVC.view.frame = CGRect(x: 0, y: ScreenHeight, width: ScreenWidth, height: height)
|
||||
}completion: { isCompletion in
|
||||
self.bgChatView.removeFromSuperview()
|
||||
self.chatListVC.view.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
var roomUid:String = ""
|
||||
var roomInfo:RoomDataModel?
|
||||
//MARK: - 懒加载
|
||||
private lazy var backgroundView:RoomBackgroundView = {
|
||||
let _backgroundView = RoomBackgroundView(frame: .zero)
|
||||
@@ -52,7 +170,7 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
||||
|
||||
return _topView
|
||||
}()
|
||||
private lazy var micSeatView:MicSeatSuperView = {
|
||||
private lazy var micSeatView:NormalMicSeatSuperView = {
|
||||
let _micSeatView = NormalMicSeatSuperView(frame: .zero)
|
||||
|
||||
return _micSeatView
|
||||
@@ -62,4 +180,77 @@ class RoomVC: BaseViewController, HiddenNavigationBarProtocol {
|
||||
|
||||
return _chatScreenView
|
||||
}()
|
||||
|
||||
private lazy var menuView:RoomMenuView = {
|
||||
let _menuView = RoomMenuView(frame: .zero)
|
||||
|
||||
return _menuView
|
||||
}()
|
||||
private lazy var bgChatView:UIButton = {
|
||||
let _bgChatView = UIButton()
|
||||
_bgChatView.addTarget(self, action: #selector(dissChatViewAction), for: .touchUpInside)
|
||||
|
||||
return _bgChatView
|
||||
}()
|
||||
private lazy var chatListVC:ChatListVC = {
|
||||
let _chatListVC = ChatListVC()
|
||||
|
||||
return _chatListVC
|
||||
}()
|
||||
}
|
||||
|
||||
extension RoomVC : NIMChatManagerDelegate, NIMChatroomManagerDelegate, NIMLoginManagerDelegate, NIMConversationManagerDelegate{
|
||||
func onRecvMessages(_ messages: [NIMMessage]) {
|
||||
for msg in messages {
|
||||
guard let session = msg.session else { continue}
|
||||
if session.sessionType != .chatroom{
|
||||
continue
|
||||
}
|
||||
if session.sessionId != self.roomInfo?.roomId{continue}
|
||||
|
||||
if msg.messageType == .notification{
|
||||
if let notMsg = msg.messageObject as? NIMNotificationObject,let content = notMsg.content as? NIMChatroomNotificationContent{
|
||||
switch content.eventType {
|
||||
case .enter:
|
||||
updateOnlineNum(num: 1)
|
||||
chatScreenView.getMsgListWithHistory()
|
||||
break
|
||||
case .addBlack:
|
||||
updateOnlineNum(num: -1)
|
||||
break
|
||||
case .kicked:
|
||||
updateOnlineNum(num: -1)
|
||||
break
|
||||
case .exit:
|
||||
updateOnlineNum(num: -1)
|
||||
break
|
||||
|
||||
default:
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
self.topView.roomData = self.roomInfo
|
||||
}else if msg.messageType == .text{
|
||||
chatScreenView.getTextMsg(msg: msg)
|
||||
}
|
||||
micSeatView.dealWithNotMessage(msg: msg)
|
||||
menuView.dealWithNotMessage(msg: msg)
|
||||
|
||||
}
|
||||
}
|
||||
func send(_ message: NIMMessage, didCompleteWithError error: Error?) {
|
||||
if let sessionId = message.session?.sessionId,let roomUid = self.roomInfo?.roomId,sessionId != roomUid{
|
||||
return
|
||||
}
|
||||
if message.messageType == .text{
|
||||
chatScreenView.getTextMsg(msg: message)
|
||||
}
|
||||
}
|
||||
func updateOnlineNum(num:Int){
|
||||
guard var roomInfo = self.roomInfo else { return }
|
||||
let onlineNum = roomInfo.onlineNum + num
|
||||
roomInfo.onlineNum = onlineNum
|
||||
self.roomInfo = roomInfo
|
||||
}
|
||||
}
|
||||
|
||||
87
yinmeng-ios/Modules/Room/VM/RoomVCViewModel.swift
Normal file
87
yinmeng-ios/Modules/Room/VM/RoomVCViewModel.swift
Normal file
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// RoomVCViewModel.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/11.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import RxSwift
|
||||
import RxCocoa
|
||||
import NIMSDK
|
||||
import MBProgressHUD
|
||||
class RoomVCViewModel: NSObject {
|
||||
static let roomVM = RoomVCViewModel.init()
|
||||
var isMute = true
|
||||
let roomData = PublishSubject<RoomDataModel>()
|
||||
let chatRoomData = PublishSubject<NIMChatroom>()
|
||||
|
||||
func getRoomUserInfo(roomUid:String,uid:String){
|
||||
let params = ["uid":roomUid,"intoUid":uid]
|
||||
RequestGet(path: "room/get", parma: params) { data in
|
||||
if let info = Deserialized<RoomDataModel>.toModel(with: data) {
|
||||
self.roomData.onNext(info)
|
||||
}
|
||||
} fail: { code, message in
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func collectRoom(roomUid:String,type:String){
|
||||
|
||||
let uid = "\(AuthManager.userUid)"
|
||||
|
||||
let params = ["uid":uid,"roomUid":roomUid,"type":type] as [String : Any]
|
||||
RequestPost(path: "fans/fansRoom", parma: params) { data in
|
||||
|
||||
HUDTool.show(with: type == "1" ? "收藏成功" : "取消收藏成功")
|
||||
} fail: { code, message in
|
||||
|
||||
}
|
||||
}
|
||||
func openRoom(title:String,type:Int,roomPwd:String,roomDesc:String,backPic:String){
|
||||
let uid = "\(AuthManager.userUid)"
|
||||
let ticket = AuthManager.ticket
|
||||
let params = ["uid":uid,"ticket":ticket,"title":title,"type":type,"roomPwd":roomPwd,"roomDesc":roomDesc,"backPic":backPic,"mgId":0] as [String : Any]
|
||||
RequestPost(path: "room/open", parma: params) { data in
|
||||
if let info = Deserialized<RoomDataModel>.toModel(with: data) {
|
||||
self.roomData.onNext(info)
|
||||
}
|
||||
} fail: { code, message in
|
||||
print(code,message)
|
||||
print(code,message)
|
||||
}
|
||||
}
|
||||
|
||||
func NIMSDKEnterRoom(roomId:String,user:UserObject){
|
||||
let enterRequest = NIMChatroomEnterRequest()
|
||||
enterRequest.roomId = roomId
|
||||
var extData = RoomChatData()
|
||||
extData.erbanNo = user.erbanNo ?? 0
|
||||
extData.experUrl = user.userLevelVo?.experUrl ?? ""
|
||||
extData.charmUrl = user.userLevelVo?.charmUrl ?? ""
|
||||
if let uid = user.uid{
|
||||
let data = ["\(uid)":extData.toJSON()]
|
||||
enterRequest.roomExt = toJSONString(dict: data as NSDictionary)
|
||||
NIMSDK.shared().chatroomManager.enterChatroom(enterRequest) { error, room, roomMember in
|
||||
if error == nil,let getRoom = room {
|
||||
self.chatRoomData.onNext(getRoom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
func toJSONString(dict:NSDictionary?)->String{
|
||||
|
||||
let data = try? JSONSerialization.data(withJSONObject: dict!, options: JSONSerialization.WritingOptions.prettyPrinted)
|
||||
|
||||
let strJson = NSString(data: data!, encoding: NSUTF8StringEncoding)
|
||||
|
||||
return strJson! as String
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// File.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/12.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import HandyJSON
|
||||
|
||||
struct MicSeatGiftValueModel:HandyJSON{
|
||||
var currentTime = ""
|
||||
var giftValueVos:[MicSeatGiftValueItemModel] = []
|
||||
}
|
||||
|
||||
|
||||
struct MicSeatGiftValueItemModel:HandyJSON{
|
||||
var uid = ""
|
||||
var giftValue:Int64 = 0
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// MicSeatModel.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/11.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
enum MicSeatType {
|
||||
case free,lock
|
||||
}
|
||||
enum MicType {
|
||||
case open,close
|
||||
}
|
||||
|
||||
class MicSeatModel: NSObject {
|
||||
var position = -1
|
||||
var posState:MicSeatType = .free
|
||||
var micState:MicType = .open
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// MicSequenceModel.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/11.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class MicSequenceModel: NSObject {
|
||||
var microState:MicSeatModel?
|
||||
var user:UserObject?
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
import Nuke
|
||||
class NormalMicSeatCell: UICollectionViewCell {
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
@@ -26,12 +26,18 @@ class NormalMicSeatCell: UICollectionViewCell {
|
||||
}
|
||||
var text:String = ""{
|
||||
didSet{
|
||||
micSeatView.nameView.text = "号麦位"
|
||||
|
||||
micSeatView.postionView.text = "\(text)"
|
||||
|
||||
}
|
||||
}
|
||||
var user:UserObject? = nil{
|
||||
didSet{
|
||||
micSeatView.user = user
|
||||
}
|
||||
}
|
||||
//MARK: - 懒加载
|
||||
private lazy var micSeatView:NormalMicSeatView = {
|
||||
lazy var micSeatView:NormalMicSeatView = {
|
||||
let _micSeatView = NormalMicSeatView(frame: .zero, isOwner: false)
|
||||
|
||||
return _micSeatView
|
||||
|
||||
@@ -6,18 +6,34 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import NIMSDK
|
||||
import MJExtension
|
||||
|
||||
class NormalMicSeatSuperView: MicSeatSuperView {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setUILayout()
|
||||
setUserList()
|
||||
registerCell()
|
||||
initRTRC()
|
||||
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private func setUserList(){
|
||||
for i in 0..<8 {
|
||||
let pos = i
|
||||
let roomUserData = MicSequenceModel()
|
||||
roomUserData.user = nil
|
||||
roomUserData.microState = MicSeatModel()
|
||||
roomUserData.microState?.position = pos
|
||||
roomUserList.append(roomUserData)
|
||||
}
|
||||
}
|
||||
private func setUILayout(){
|
||||
addSubview(roomOwnerView)
|
||||
addSubview(collectionView)
|
||||
@@ -32,15 +48,140 @@ class NormalMicSeatSuperView: MicSeatSuperView {
|
||||
make.leading.bottom.trailing.equalTo(self).inset(UIDevice.scaleWidth(width: 0))
|
||||
|
||||
}
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(clickOwnerAction))
|
||||
roomOwnerView.addGestureRecognizer(tap)
|
||||
}
|
||||
@objc private func clickOwnerAction(){
|
||||
guard let roomid = self.roomData?.roomId else{return}
|
||||
var index:Int = -2
|
||||
for (i,item) in roomUserList.enumerated(){
|
||||
if item.user?.uid == AuthManager.userUid{
|
||||
index = i
|
||||
}
|
||||
}
|
||||
if index == -2{
|
||||
if self.roomOwnerView.user?.uid == AuthManager.userUid{
|
||||
index = -1
|
||||
}
|
||||
}
|
||||
|
||||
if roomOwnerView.user != nil{
|
||||
if roomOwnerView.user!.uid == AuthManager.userUid{
|
||||
let popUpView = PlanetStarPopUpView.init(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight))
|
||||
keyWindow.addSubview(popUpView)
|
||||
popUpView.textView.text = "确定下麦旁听吗?"
|
||||
popUpView.senderView.setTitle("确定", for: .normal)
|
||||
popUpView.bgPointView.isHidden = true
|
||||
popUpView.pointTextView.isHidden = true
|
||||
popUpView.clickSendBlcok = {[weak self] in
|
||||
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{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
HUDTool.show(with: "该麦位已经有人了哦~")
|
||||
return
|
||||
}
|
||||
|
||||
if (index == -2){
|
||||
upMicAction(index: "\(-1)")
|
||||
return
|
||||
}
|
||||
let downRequest = NIMChatroomQueueRemoveRequest()
|
||||
downRequest.key = "\(index)"
|
||||
downRequest.roomId = roomid
|
||||
NIMSDK.shared().chatroomManager.removeChatroomQueueObject(downRequest) {[weak self] (error, info) in
|
||||
guard let self = self else{return}
|
||||
if error == nil{
|
||||
self.upMicAction(index: "\(-1)")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private func registerCell(){
|
||||
collectionView.register(NormalMicSeatCell.self, forCellWithReuseIdentifier: "NormalMicSeatCell")
|
||||
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 mewParams = TRTCParams()
|
||||
if AuthViewModel.authVM.appId.isEmpty{
|
||||
|
||||
mewParams.sdkAppId = UInt32("1400798783") ?? 0
|
||||
}else{
|
||||
mewParams.sdkAppId = UInt32(AuthViewModel.authVM.appId) ?? 0
|
||||
}
|
||||
mewParams.roomId = UInt32(curRoomId) ?? 0
|
||||
let uid = "\(AuthManager.userUid)"
|
||||
mewParams.userId = uid
|
||||
let sign = self.roomData?.trtcSig ?? ""
|
||||
mewParams.userSig = sign
|
||||
mewParams.role = TRTCRoleType.audience
|
||||
TRTCCloud.sharedInstance().enterRoom(mewParams, 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
|
||||
if error == nil,let _data = data{
|
||||
for item in _data {
|
||||
|
||||
if !item.keys.isEmpty,let first = item.keys.first{
|
||||
let value = item[first]
|
||||
if let userData = Deserialized<UserObject>.toModel(with: value) {
|
||||
let getPost = Int(first) ?? 0
|
||||
if getPost == -1{
|
||||
self.roomOwnerView.user = userData
|
||||
}else{
|
||||
let user = self.roomUserList[getPost]
|
||||
user.user = userData
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
self.collectionView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//MARK: - 懒加载
|
||||
|
||||
var roomUserList:[MicSequenceModel] = []
|
||||
var roomData:RoomDataModel?
|
||||
var userData:UserObject?
|
||||
private lazy var roomOwnerView:NormalMicSeatView = {
|
||||
let _roomOwnerView = NormalMicSeatView(frame: .zero, isOwner: true)
|
||||
return _roomOwnerView
|
||||
@@ -67,7 +208,214 @@ extension NormalMicSeatSuperView:UICollectionViewDelegate,UICollectionViewDataSo
|
||||
}
|
||||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NormalMicSeatCell", for: indexPath) as! NormalMicSeatCell
|
||||
cell.text = "\(indexPath.row)"
|
||||
let user = roomUserList[indexPath.row ]
|
||||
cell.text = "\(indexPath.row + 1)"
|
||||
if user.user != nil{
|
||||
|
||||
cell.user = user.user
|
||||
}else{
|
||||
|
||||
cell.user = nil
|
||||
}
|
||||
return cell
|
||||
}
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard let roomUid = self.roomData?.roomId else { return }
|
||||
let user = roomUserList[indexPath.row]
|
||||
var index:Int = -2
|
||||
for (i,item) in roomUserList.enumerated(){
|
||||
if item.user?.uid == AuthManager.userUid{
|
||||
index = i
|
||||
}
|
||||
}
|
||||
if index == -2{
|
||||
if self.roomOwnerView.user?.uid == AuthManager.userUid{
|
||||
index = -1
|
||||
}
|
||||
}
|
||||
if user.user != nil{
|
||||
if user.user?.uid == AuthManager.userUid{
|
||||
let popUpView = PlanetStarPopUpView.init(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight))
|
||||
keyWindow.addSubview(popUpView)
|
||||
popUpView.textView.text = "确定下麦旁听吗?"
|
||||
popUpView.senderView.setTitle("确定", for: .normal)
|
||||
popUpView.bgPointView.isHidden = true
|
||||
popUpView.pointTextView.isHidden = true
|
||||
popUpView.clickSendBlcok = {[weak self] in
|
||||
let downRequest = NIMChatroomQueueRemoveRequest()
|
||||
downRequest.key = "\(indexPath.row)"
|
||||
downRequest.roomId = roomUid
|
||||
NIMSDK.shared().chatroomManager.removeChatroomQueueObject(downRequest) {[weak self] (error, info) in
|
||||
guard let self = self else{return}
|
||||
if error == nil{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
HUDTool.show(with: "该麦位已经有人了哦~")
|
||||
}else{
|
||||
if (index == -2){
|
||||
upMicAction(index: "\(indexPath.row)")
|
||||
return
|
||||
}
|
||||
let downRequest = NIMChatroomQueueRemoveRequest()
|
||||
downRequest.key = "\(index)"
|
||||
downRequest.roomId = roomUid
|
||||
NIMSDK.shared().chatroomManager.removeChatroomQueueObject(downRequest) {[weak self] (error, info) in
|
||||
guard let self = self else{return}
|
||||
if error == nil{
|
||||
self.upMicAction(index: "\(indexPath.row)")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func dealWithNotMessage(msg:NIMMessage){
|
||||
if let notMsg = msg.messageObject as? NIMNotificationObject,let content = notMsg.content as? NIMChatroomNotificationContent{
|
||||
switch content.eventType {
|
||||
case .infoUpdated:
|
||||
|
||||
break
|
||||
case .queueChange:
|
||||
|
||||
if let data = content.ext as? [String : Any]{
|
||||
|
||||
if let pos = data[NIMChatroomEventInfoQueueChangeItemKey] as? String,let value = data[NIMChatroomEventInfoQueueChangeItemValueKey],let userData = Deserialized<UserObject>.toModel(with: value) ,let changeType = data[NIMChatroomEventInfoQueueChangeTypeKey] as? Int{
|
||||
if pos == "-1"{
|
||||
if changeType == 1{
|
||||
roomOwnerView.user = userData
|
||||
}else if changeType == 2{
|
||||
roomOwnerView.user = nil
|
||||
roomOwnerView.speakView.isHidden = true
|
||||
}
|
||||
}else{
|
||||
if changeType == 1,let i = Int(pos){
|
||||
let user = roomUserList[i]
|
||||
user.user = userData
|
||||
}else if changeType == 2,let i = Int(pos){
|
||||
let user = roomUserList[i]
|
||||
let cell = collectionView.cellForItem(at: IndexPath(row: i, section: 0)) as! NormalMicSeatCell
|
||||
cell.micSeatView.speakView.isHidden = true
|
||||
user.user = nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
break
|
||||
case .exit:
|
||||
for member in content.targets ?? []{
|
||||
for item in roomUserList {
|
||||
if let uid = item.user?.uid, "\(uid)" == member.userId{
|
||||
item.user = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
updateGiftNumber()
|
||||
}
|
||||
}
|
||||
func updateGiftNumber(){
|
||||
guard let roomUid = roomData?.uid else {
|
||||
self.collectionView.reloadData()
|
||||
return
|
||||
}
|
||||
let params = ["uid":"\(AuthManager.userUid)","roomUid":roomUid] as [String : Any]
|
||||
RequestGet(path: "room/gift/value/get", parma: params) { data in
|
||||
if let info = Deserialized<MicSeatGiftValueModel>.toModel(with: data) {
|
||||
for model in info.giftValueVos{
|
||||
if var ownerUser = self.roomOwnerView.user{
|
||||
if let uid = ownerUser.uid,"\(uid)" == model.uid{
|
||||
ownerUser.giftValue = model.giftValue
|
||||
self.roomOwnerView.user = ownerUser
|
||||
}
|
||||
}else{
|
||||
for item in self.roomUserList{
|
||||
if let uid = item.user?.uid,"\(uid)" == model.uid{
|
||||
item.user?.giftValue = model.giftValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
self.collectionView.reloadData()
|
||||
}
|
||||
|
||||
} fail: { code, message in
|
||||
self.collectionView.reloadData()
|
||||
}
|
||||
}
|
||||
func upMicAction(index:String){
|
||||
|
||||
guard let roomUid = self.roomData?.roomId,let user = self.userData else { return }
|
||||
let model = ["gender":user.gender == .Boy ? "1":"2","avatar":user.avatar ?? "","uid":user.uid ?? "","nick":user.nick ?? ""] as NSDictionary
|
||||
let updateRequest = NIMChatroomQueueUpdateRequest()
|
||||
updateRequest.value = model.mj_JSONString()
|
||||
updateRequest.key = index
|
||||
updateRequest.roomId = roomUid
|
||||
updateRequest.transient = true
|
||||
NIMSDK.shared().chatroomManager.updateChatroomQueueObject(updateRequest) { error in
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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 {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class MicSeatGiftValueView: UIView {
|
||||
|
||||
return _giftIconView
|
||||
}()
|
||||
private lazy var numView:UILabel = {
|
||||
lazy var numView:UILabel = {
|
||||
let _numView = UILabel.getCustomLabel(text: "0",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white)
|
||||
|
||||
return _numView
|
||||
|
||||
@@ -6,24 +6,48 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
import Nuke
|
||||
class NormalMicSeatView: UIView {
|
||||
|
||||
init(frame: CGRect,isOwner:Bool) {
|
||||
super.init(frame: frame)
|
||||
self.isOwner = isOwner
|
||||
|
||||
if isOwner{
|
||||
setOwnerUILayout()
|
||||
|
||||
return
|
||||
}
|
||||
setUILayout()
|
||||
|
||||
}
|
||||
|
||||
var user:UserObject? = nil{
|
||||
didSet{
|
||||
speakView.isHidden = true
|
||||
guard let _user = user else {
|
||||
|
||||
if isOwner {
|
||||
nameView.text = ""
|
||||
avatarView.image = UIImage(named: "yin_room_mic_position_normal")
|
||||
}else{
|
||||
nameView.text = "号麦位"
|
||||
avatarView.image = UIImage(named: "yin_room_mic_position_normal")
|
||||
postionView.backgroundColor = ThemeColor(hexStr: "#FFFFFF", alpha: 0.2)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
postionView.backgroundColor = _user.gender == .Boy ? ThemeColor(hexStr: "#3EBBFE") : ThemeColor(hexStr: "#FF5E83")
|
||||
nameView.text = _user.nick
|
||||
Nuke.loadImage(with: _user.avatar,options: ImageLoadingOptions(placeholder: UIImage(named: "yin_room_mic_position_normal")), into: avatarView, completion: nil)
|
||||
giftValueView.numView.text = "\(_user.giftValue)"
|
||||
}
|
||||
}
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
private func setOwnerUILayout(){
|
||||
addSubview(speakView)
|
||||
addSubview(avatarView)
|
||||
addSubview(nameStackView)
|
||||
|
||||
@@ -32,9 +56,14 @@ class NormalMicSeatView: UIView {
|
||||
nameStackView.addArrangedSubview(nameView)
|
||||
nameStackView.addArrangedSubview(genderView)
|
||||
nameStackView.addArrangedSubview(giftValueView)
|
||||
|
||||
|
||||
speakView.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 78))
|
||||
make.center.equalTo(self.avatarView)
|
||||
}
|
||||
avatarView.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 58))
|
||||
make.top.equalTo(UIDevice.scaleWidth(width: 5))
|
||||
make.centerX.equalTo(self)
|
||||
}
|
||||
nameStackView.snp.makeConstraints { make in
|
||||
@@ -50,10 +79,21 @@ class NormalMicSeatView: UIView {
|
||||
}
|
||||
|
||||
avatarView.layer.cornerRadius = UIDevice.scaleWidth(width: 58) / 2
|
||||
genderView.isHidden = false
|
||||
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)
|
||||
addSubview(avatarView)
|
||||
addSubview(nameStackView)
|
||||
addSubview(giftValueView)
|
||||
@@ -61,13 +101,17 @@ class NormalMicSeatView: UIView {
|
||||
nameStackView.addArrangedSubview(postionView)
|
||||
nameStackView.addArrangedSubview(nameView)
|
||||
nameStackView.addArrangedSubview(genderView)
|
||||
|
||||
speakView.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 75))
|
||||
make.center.equalTo(self.avatarView)
|
||||
}
|
||||
avatarView.snp.makeConstraints { make in
|
||||
make.top.equalTo(UIDevice.scaleWidth(width: 5))
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 55))
|
||||
make.centerX.equalTo(self)
|
||||
}
|
||||
nameStackView.snp.makeConstraints { make in
|
||||
make.top.equalTo(avatarView.snp.bottom).offset(UIDevice.scaleWidth(width: 10))
|
||||
make.top.equalTo(avatarView.snp.bottom).offset(UIDevice.scaleWidth(width: 5))
|
||||
make.width.lessThanOrEqualTo(self)
|
||||
make.centerX.equalTo(self)
|
||||
}
|
||||
@@ -84,10 +128,19 @@ class NormalMicSeatView: UIView {
|
||||
avatarView.layer.cornerRadius = UIDevice.scaleWidth(width: 55) / 2
|
||||
genderView.isHidden = true
|
||||
postionView.isHidden = false
|
||||
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 var isOwner:Bool = false
|
||||
//MARK: - 懒加载
|
||||
private lazy var avatarView:UIImageView = {
|
||||
lazy var avatarView:UIImageView = {
|
||||
let _avatarView = UIImageView()
|
||||
_avatarView.isUserInteractionEnabled = true
|
||||
_avatarView.layer.masksToBounds = true
|
||||
@@ -112,7 +165,7 @@ class NormalMicSeatView: UIView {
|
||||
}()
|
||||
|
||||
lazy var nameView:UILabel = {
|
||||
let _nameView = UILabel.getCustomLabel(text:"小灰类",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white,textAlignment: .center)
|
||||
let _nameView = UILabel.getCustomLabel(text:"",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white,textAlignment: .center)
|
||||
return _nameView
|
||||
}()
|
||||
private lazy var genderView:UIImageView = {
|
||||
@@ -120,11 +173,22 @@ class NormalMicSeatView: UIView {
|
||||
_genderView.image = UIImage(named: "yin_plane_star__woman")
|
||||
return _genderView
|
||||
}()
|
||||
private lazy var giftValueView:MicSeatGiftValueView = {
|
||||
lazy var giftValueView:MicSeatGiftValueView = {
|
||||
let _giftValueView = MicSeatGiftValueView(frame: .zero)
|
||||
_giftValueView.isUserInteractionEnabled = true
|
||||
return _giftValueView
|
||||
}()
|
||||
|
||||
|
||||
lazy var speakView:SVGAImageView = {
|
||||
let _speakView = SVGAImageView()
|
||||
_speakView.contentMode = .scaleAspectFill
|
||||
_speakView.isUserInteractionEnabled = true
|
||||
_speakView.isHidden = true
|
||||
return _speakView
|
||||
}()
|
||||
private lazy var speakParser:SVGAParser = {
|
||||
let _speakParser = SVGAParser()
|
||||
return _speakParser
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// RoomMsgListModel.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/12.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import HandyJSON
|
||||
struct RoomMsgListModel: HandyJSON {
|
||||
var roomNickname = ""
|
||||
var charmUrl = ""{
|
||||
didSet{
|
||||
charmNewUrl = MAIDESEncryptTool.getCharmImageUrl(charmUrl)
|
||||
}
|
||||
}
|
||||
var experUrl = ""{
|
||||
didSet{
|
||||
experNewUrl = MAIDESEncryptTool.getWealthImageUrl(experUrl)
|
||||
}
|
||||
}
|
||||
var experNewUrl = "new_exper_01"
|
||||
var charmNewUrl = "new_charm_01"
|
||||
var text = ""
|
||||
var avatar = ""
|
||||
var height:CGFloat = 0
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Nuke
|
||||
|
||||
|
||||
class RoomChatScreenUserChatCell: UITableViewCell {
|
||||
|
||||
@@ -25,26 +27,26 @@ class RoomChatScreenUserChatCell: UITableViewCell {
|
||||
contentView.addSubview(nameStackView)
|
||||
contentView.addSubview(tagStackView)
|
||||
contentView.addSubview(bgTextView)
|
||||
contentView.addSubview(textView)
|
||||
|
||||
|
||||
|
||||
nameStackView.addArrangedSubview(vipImageView)
|
||||
// nameStackView.addArrangedSubview(vipImageView)
|
||||
nameStackView.addArrangedSubview(nameView)
|
||||
|
||||
tagStackView.addArrangedSubview(experIconView)
|
||||
tagStackView.addArrangedSubview(charmIconView)
|
||||
|
||||
bgTextView.addSubview(textView)
|
||||
|
||||
|
||||
|
||||
nameStackView.snp.makeConstraints { make in
|
||||
make.leading.equalTo(UIDevice.scaleWidth(width: 38))
|
||||
make.leading.equalTo(UIDevice.scaleWidth(width: 45))
|
||||
make.height.equalTo(UIDevice.scaleWidth(width: 26))
|
||||
make.top.equalTo(UIDevice.scaleWidth(width: 0))
|
||||
}
|
||||
vipImageView.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 26))
|
||||
}
|
||||
// vipImageView.snp.makeConstraints { make in
|
||||
// make.width.height.equalTo(UIDevice.scaleWidth(width: 26))
|
||||
// }
|
||||
avatarVeiw.snp.makeConstraints { make in
|
||||
make.top.equalTo(nameStackView.snp.top).offset(UIDevice.scaleWidth(width: 5))
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 36))
|
||||
@@ -55,7 +57,7 @@ class RoomChatScreenUserChatCell: UITableViewCell {
|
||||
tagStackView.snp.makeConstraints { make in
|
||||
make.height.equalTo(UIDevice.scaleWidth(width: 18))
|
||||
make.top.equalTo(nameStackView.snp.bottom).offset(UIDevice.scaleWidth(width: 0))
|
||||
make.leading.equalTo(avatarVeiw.snp.trailing).offset((UIDevice.scaleWidth(width: 8)))
|
||||
make.leading.equalTo(UIDevice.scaleWidth(width: 45))
|
||||
}
|
||||
|
||||
experIconView.snp.makeConstraints { make in
|
||||
@@ -78,10 +80,25 @@ class RoomChatScreenUserChatCell: UITableViewCell {
|
||||
make.top.bottom.equalTo(bgTextView).inset(UIDevice.scaleWidth(width: 8))
|
||||
make.leading.trailing.equalTo(bgTextView).inset(UIDevice.scaleWidth(width: 12))
|
||||
}
|
||||
bgTextView.superview?.layoutIfNeeded()
|
||||
|
||||
}
|
||||
override func layoutSubviews() {
|
||||
// bgTextView.addCorner(cornerRadii: CornerRadii(topLeft: 6,topRight: 12,bottomLeft: 12,bottomRight: 12), frame: bgTextView.frame)
|
||||
var model:RoomMsgListModel? = nil{
|
||||
didSet{
|
||||
guard let _model = model else { return }
|
||||
Nuke.loadImage(with: _model.avatar, into: avatarVeiw, completion: nil)
|
||||
nameView.text = _model.roomNickname
|
||||
charmIconView.image = UIImage(named: _model.charmNewUrl)
|
||||
experIconView.image = UIImage(named: _model.experNewUrl)
|
||||
textView.text = _model.text
|
||||
let charmWidth = (charmIconView.image?.size.width ?? 0) * UIDevice.scaleWidth(width: 18) / (charmIconView.image?.size.height ?? 1)
|
||||
let experWidth = (experIconView.image?.size.width ?? 0) * UIDevice.scaleWidth(width: 18) / (experIconView.image?.size.height ?? 1)
|
||||
charmIconView.snp.updateConstraints { make in
|
||||
make.width.equalTo(charmWidth)
|
||||
}
|
||||
experIconView.snp.updateConstraints { make in
|
||||
make.width.equalTo(experWidth)
|
||||
}
|
||||
}
|
||||
}
|
||||
//MARK: - 懒加载
|
||||
private lazy var avatarVeiw:UIImageView = {
|
||||
@@ -89,7 +106,7 @@ class RoomChatScreenUserChatCell: UITableViewCell {
|
||||
_avatarVeiw.layer.cornerRadius = UIDevice.scaleWidth(width: 36)/2
|
||||
_avatarVeiw.layer.masksToBounds = true
|
||||
_avatarVeiw.layer.borderColor = ThemeColor(hexStr: "#FFE710").cgColor
|
||||
_avatarVeiw.backgroundColor = .red
|
||||
|
||||
_avatarVeiw.isUserInteractionEnabled = true
|
||||
return _avatarVeiw
|
||||
}()
|
||||
@@ -101,25 +118,27 @@ class RoomChatScreenUserChatCell: UITableViewCell {
|
||||
_nameStackView.spacing = UIDevice.scaleWidth(width: 2)
|
||||
return _nameStackView
|
||||
}()
|
||||
private lazy var vipImageView:UIImageView = {
|
||||
let _vipImageView = UIImageView()
|
||||
_vipImageView.image = UIImage(named: "1")
|
||||
return _vipImageView
|
||||
}()
|
||||
// private lazy var vipImageView:UIImageView = {
|
||||
// let _vipImageView = UIImageView()
|
||||
//
|
||||
// return _vipImageView
|
||||
// }()
|
||||
private lazy var nameView:UILabel = {
|
||||
let _nameView = UILabel.getCustomLabel(text: "我:", font: UIFont.getScaleFont(ofSize: 12, weight: .regular), color: ThemeColor(hexStr: "#FFFFFF", alpha: 0.5))
|
||||
let _nameView = UILabel.getCustomLabel(text: "", font: UIFont.getScaleFont(ofSize: 12, weight: .regular), color: ThemeColor(hexStr: "#FFFFFF", alpha: 0.5))
|
||||
|
||||
return _nameView
|
||||
}()
|
||||
private lazy var bgTextView:UIView = {
|
||||
private lazy var bgTextView:UIImageView = {
|
||||
let _bgTextView = UIImageView()
|
||||
_bgTextView.backgroundColor = ThemeColor(hexStr: "#FFFFFF", alpha: 0.2)
|
||||
|
||||
_bgTextView.contentMode = .scaleToFill
|
||||
let image = UIImage(named: "room_message_text_bg")!
|
||||
_bgTextView.image = image.resizableImage(withCapInsets: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20), resizingMode: .stretch)
|
||||
_bgTextView.alpha = 0.2
|
||||
return _bgTextView
|
||||
}()
|
||||
|
||||
private lazy var textView:UILabel = {
|
||||
let _textView = UILabel.getCustomLabel(text:"或呃呃或呃呃或呃呃或呃呃",font: UIFont.getScaleFont(ofSize: 12, weight: .regular),numberOfLines: 0)
|
||||
let _textView = UILabel.getCustomLabel(text:"",font: UIFont.getScaleFont(ofSize: 12, weight: .regular),numberOfLines: 0)
|
||||
_textView.isUserInteractionEnabled = true
|
||||
return _textView
|
||||
}()
|
||||
@@ -135,12 +154,10 @@ class RoomChatScreenUserChatCell: UITableViewCell {
|
||||
|
||||
private lazy var experIconView:UIImageView = {
|
||||
let _experView = UIImageView()
|
||||
_experView.image = UIImage(named: "2")
|
||||
return _experView
|
||||
}()
|
||||
private lazy var charmIconView:UIImageView = {
|
||||
let _charmView = UIImageView()
|
||||
_charmView.image = UIImage(named: "2")
|
||||
return _charmView
|
||||
}()
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import NIMSDK
|
||||
|
||||
|
||||
|
||||
class RoomChatScreenView: UIView {
|
||||
|
||||
@@ -18,6 +21,66 @@ class RoomChatScreenView: UIView {
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func getMsgListWithHistory(){
|
||||
let option = NIMHistoryMessageSearchOption()
|
||||
option.limit = 100
|
||||
option.messageTypes = [NSNumber(value: NIMMessageType.text.rawValue)]
|
||||
option.order = .asc
|
||||
NIMSDK.shared().chatroomManager.fetchMessageHistory(roomId, option: option) { error, list in
|
||||
guard let msgList = list else{return}
|
||||
for msg in msgList{
|
||||
self.dealWithMsg(msg: msg )
|
||||
}
|
||||
self.chatTableView.reloadData()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
self.chatTableView.scrollToRow(at: IndexPath(row:self.msgList.count - 1 , section:0 ), at: .bottom, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
func getTextMsg(msg:NIMMessage){
|
||||
dealWithMsg(msg: msg)
|
||||
chatTableView.reloadData()
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
self.chatTableView.scrollToRow(at: IndexPath.init(row:self.msgList.count - 1 , section:0 ), at: .bottom, animated: true)
|
||||
}
|
||||
}
|
||||
func dealWithMsg(msg:NIMMessage){
|
||||
|
||||
var model = RoomMsgListModel()
|
||||
if let obj = msg.messageExt as? NIMMessageChatroomExtension{
|
||||
model.roomNickname = obj.roomNickname ?? ""
|
||||
}
|
||||
if let from = msg.from,let user = NIMSDK.shared().userManager.userInfo(from){
|
||||
|
||||
if "\(AuthManager.userUid)" == from{
|
||||
model.roomNickname = "我:"
|
||||
}
|
||||
if let userInfo = user.userInfo,let avatarUrl = userInfo.avatarUrl {
|
||||
model.avatar = avatarUrl
|
||||
}
|
||||
if model.avatar.isEmpty,let msgExt = msg.messageExt as? NIMMessageChatroomExtension {
|
||||
model.avatar = msgExt.roomAvatar ?? "" + ":"
|
||||
}
|
||||
if let remoteExt = msg.remoteExt,let extDic = remoteExt[from] as? [NSString:Any]{
|
||||
model.charmUrl = extDic["charmUrl"] as! String
|
||||
model.experUrl = extDic["experUrl"] as! String
|
||||
|
||||
}
|
||||
}
|
||||
model.text = msg.text ?? ""
|
||||
|
||||
let width = ScreenWidth - UIDevice.scaleWidth(width: 158)
|
||||
let heigth = UILabel.getLabelHeigth(text: msg.text ?? "", width: width, font: UIFont.systemFont(ofSize: 12, weight: .regular))
|
||||
|
||||
|
||||
model.height = heigth + UIDevice.scaleWidth(width: 70)
|
||||
self.msgList.append(model)
|
||||
|
||||
}
|
||||
var roomId = ""
|
||||
private func setUILayout(){
|
||||
addSubview(chatTableView)
|
||||
chatTableView.snp.makeConstraints { make in
|
||||
@@ -32,9 +95,9 @@ class RoomChatScreenView: UIView {
|
||||
chatTableView.tableHeaderView = tableHeaderView
|
||||
chatTableView.register(RoomChatScreenUserChatCell.self, forCellReuseIdentifier: "RoomChatScreenUserChatCell")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var msgList:[RoomMsgListModel] = []
|
||||
//MARK: - 懒加载
|
||||
private lazy var chatTableView:UITableView = {
|
||||
let _chatTableView = UITableView(frame: .zero, style: .plain)
|
||||
@@ -55,14 +118,16 @@ class RoomChatScreenView: UIView {
|
||||
}
|
||||
extension RoomChatScreenView:UITableViewDelegate,UITableViewDataSource{
|
||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return 1
|
||||
return msgList.count
|
||||
}
|
||||
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
return 90
|
||||
let model = msgList[indexPath.row]
|
||||
return model.height
|
||||
}
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "RoomChatScreenUserChatCell", for: indexPath) as! RoomChatScreenUserChatCell
|
||||
|
||||
let model = msgList[indexPath.row]
|
||||
cell.model = model
|
||||
return cell
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
//
|
||||
// RoomMenuView.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/11.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import NIMSDK
|
||||
typealias ClickMenuViewBlcok = () -> Void
|
||||
|
||||
|
||||
class RoomMenuView: UIView {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setUILayout()
|
||||
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
private func setUILayout(){
|
||||
addSubview(sendBtn)
|
||||
addSubview(chatBtn)
|
||||
addSubview(micBtn)
|
||||
sendBtn.snp.makeConstraints { make in
|
||||
make.leading.equalTo(UIDevice.scaleWidth(width: 15))
|
||||
make.top.equalTo(self)
|
||||
make.width.equalTo(UIDevice.scaleWidth(width: 102))
|
||||
make.height.equalTo(UIDevice.scaleWidth(width: 30))
|
||||
}
|
||||
chatBtn.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 30))
|
||||
make.centerY.equalTo(sendBtn)
|
||||
make.leading.equalTo(sendBtn.snp.trailing).offset((UIDevice.scaleWidth(width: 8)))
|
||||
}
|
||||
|
||||
micBtn.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 30))
|
||||
make.centerY.equalTo(chatBtn)
|
||||
make.leading.equalTo(chatBtn.snp.trailing).offset((UIDevice.scaleWidth(width: 8)))
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@objc func sendTextAction(){
|
||||
self.superview?.superview?.addSubview(sendTextView)
|
||||
sendTextView.user = user
|
||||
sendTextView.roomUid = roomUid
|
||||
sendTextView.textFiled.becomeFirstResponder()
|
||||
}
|
||||
@objc func clickChatViewAction(){
|
||||
if let _clickMenuViewBlcok = clickMenuViewBlcok{
|
||||
_clickMenuViewBlcok()
|
||||
}
|
||||
|
||||
}
|
||||
@objc func clickMicBtnAction(){
|
||||
micBtn.isSelected = !micBtn.isSelected
|
||||
if micBtn.isSelected {
|
||||
TRTCCloud.sharedInstance().muteLocalAudio(true)
|
||||
RoomVCViewModel.roomVM.isMute = true
|
||||
return
|
||||
}
|
||||
TRTCCloud.sharedInstance().muteLocalAudio(false)
|
||||
RoomVCViewModel.roomVM.isMute = false
|
||||
}
|
||||
|
||||
func dealWithNotMessage(msg:NIMMessage){
|
||||
if let notMsg = msg.messageObject as? NIMNotificationObject,let content = notMsg.content as? NIMChatroomNotificationContent{
|
||||
switch content.eventType {
|
||||
case .infoUpdated:
|
||||
|
||||
break
|
||||
case .queueChange:
|
||||
|
||||
if let data = content.ext as? [String : Any]{
|
||||
var isHaveChange = false
|
||||
if let value = data[NIMChatroomEventInfoQueueChangeItemValueKey],let userData = Deserialized<UserObject>.toModel(with: value) ,let changeType = data[NIMChatroomEventInfoQueueChangeTypeKey] as? Int{
|
||||
|
||||
if changeType == 1{
|
||||
if AuthManager.userUid == userData.uid{
|
||||
micBtn.isHidden = false
|
||||
micBtn.isSelected = true
|
||||
isHaveChange = true
|
||||
TRTCCloud.sharedInstance().muteLocalAudio(true)
|
||||
RoomVCViewModel.roomVM.isMute = true
|
||||
}
|
||||
}else if changeType == 2{
|
||||
|
||||
if AuthManager.userUid == userData.uid{
|
||||
micBtn.isHidden = true
|
||||
TRTCCloud.sharedInstance().muteLocalAudio(true)
|
||||
RoomVCViewModel.roomVM.isMute = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
setBroadcast(isChange: isHaveChange)
|
||||
}
|
||||
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
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)))
|
||||
|
||||
return _sendTextView
|
||||
}()
|
||||
|
||||
//MARK: - 懒加载
|
||||
var clickMenuViewBlcok:ClickMenuViewBlcok?
|
||||
var user:UserObject?
|
||||
var roomUid = ""
|
||||
private lazy var sendBtn:UIButton = {
|
||||
let _sendBtn = UIButton()
|
||||
_sendBtn.setTitle("聊一聊~", for: .normal)
|
||||
_sendBtn.setTitleColor(.white, for: .normal)
|
||||
_sendBtn.titleLabel?.font = UIFont.getScaleFont(ofSize: 12, weight: .regular)
|
||||
_sendBtn.layer.cornerRadius = UIDevice.scaleWidth(width: 30)/2
|
||||
_sendBtn.backgroundColor = ThemeColor(hexStr: "#FFFFFF", alpha: 0.3)
|
||||
_sendBtn.layer.masksToBounds = true
|
||||
_sendBtn.addTarget(self, action: #selector(sendTextAction), for: .touchUpInside)
|
||||
return _sendBtn
|
||||
}()
|
||||
private lazy var chatBtn:UIButton = {
|
||||
|
||||
let _chatBtn = UIButton(type: .custom)
|
||||
_chatBtn.setImage(UIImage(named: "room_menu_chat_btn"), for: .normal)
|
||||
_chatBtn.addTarget(self, action: #selector(clickChatViewAction), for: .touchUpInside)
|
||||
return _chatBtn
|
||||
}()
|
||||
|
||||
private lazy var micBtn:UIButton = {
|
||||
let _micBtn = UIButton()
|
||||
_micBtn.setImage(UIImage(named: "menu_mic_open_icon"), for: .normal)
|
||||
_micBtn.setImage(UIImage(named: "menu_mic_close_icon"), for: .selected)
|
||||
_micBtn.addTarget(self, action: #selector(clickMicBtnAction), for: .touchUpInside)
|
||||
_micBtn.isSelected = true
|
||||
_micBtn.isHidden = true
|
||||
return _micBtn
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// RoomSendTextView.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/3/11.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import NIMSDK
|
||||
|
||||
class RoomSendTextView: UIView {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setUILayout()
|
||||
// 添加键盘显示的观察者
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||
// 添加键盘隐藏的观察者
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||
}
|
||||
|
||||
|
||||
// 键盘将要显示时的处理函数
|
||||
@objc func keyboardWillShow(notification: NSNotification) {
|
||||
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? CGFloat {
|
||||
print(keyboardSize.height)
|
||||
UIView.animate(withDuration: duration) {
|
||||
self.frame.origin.y = ScreenHeight - keyboardSize.height - 40
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 键盘将要隐藏时的处理函数
|
||||
@objc func keyboardWillHide(notification: NSNotification) {
|
||||
if let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? CGFloat {
|
||||
UIView.animate(withDuration: duration) {
|
||||
self.frame.origin.y = (ScreenHeight + 40)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 视图控制器被销毁前,移除所有观察者
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
private func setUILayout(){
|
||||
backgroundColor = ThemeColor(hexStr: "#F8F8FB")
|
||||
addSubview(textFiled)
|
||||
addSubview(sendTextBtn)
|
||||
|
||||
sendTextBtn.snp.makeConstraints { make in
|
||||
make.top.bottom.equalTo(self).inset(UIDevice.scaleWidth(width: 5))
|
||||
make.width.equalTo(UIDevice.scaleWidth(width: 50))
|
||||
make.trailing.equalTo(-UIDevice.scaleWidth(width: 5))
|
||||
}
|
||||
textFiled.snp.makeConstraints { make in
|
||||
make.leading.equalTo(UIDevice.scaleWidth(width: 8))
|
||||
make.top.bottom.equalTo(self)
|
||||
make.trailing.equalTo(sendTextBtn.snp.leading).offset(-UIDevice.scaleWidth(width: 10))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@objc func sendTextAction(){
|
||||
guard let user = self.user else { return }
|
||||
let msg = NIMMessage()
|
||||
msg.text = textFiled.text
|
||||
let ext = ["\(AuthManager.userUid)":["erbanNo":"\(user.erbanNo ?? 0)","charmUrl":user.userLevelVo?.charmUrl,"experUrl":user.userLevelVo?.experUrl]]
|
||||
msg.remoteExt = ext
|
||||
let session = NIMSession.init(roomUid, type: .chatroom)
|
||||
|
||||
NIMSDK.shared().chatManager.send(msg, to: session,completion: { error in
|
||||
self.textFiled.text = ""
|
||||
self.sendTextBtn.isEnabled = false
|
||||
self.textFiled.resignFirstResponder()
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
@objc func textFieldEditChanged(textField:UITextField){
|
||||
guard let text = textField.text else {
|
||||
sendTextBtn.isEnabled = false
|
||||
return
|
||||
}
|
||||
sendTextBtn.isEnabled = text.count > 0
|
||||
}
|
||||
//MARK: - 懒加载
|
||||
var user:UserObject?
|
||||
var roomUid = ""
|
||||
lazy var textFiled:UITextField = {
|
||||
let _textFiled = UITextField()
|
||||
let textAtt = NSAttributedString(string: "请输入消息...", attributes: [.font:UIFont.getScaleFont(ofSize: 15, weight: .regular),.foregroundColor:ThemeColor(hexStr: "#878B9C")])
|
||||
_textFiled.attributedPlaceholder = textAtt
|
||||
_textFiled.borderStyle = .none
|
||||
_textFiled.textColor = ThemeColor(hexStr: "#333333")
|
||||
_textFiled.font = UIFont.getScaleFont(ofSize: 15, weight: .regular)
|
||||
_textFiled.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||
_textFiled.addTarget(self, action: #selector(textFieldEditChanged(textField:)), for: .editingChanged)
|
||||
_textFiled.delegate = self
|
||||
_textFiled.returnKeyType = .done
|
||||
return _textFiled
|
||||
}()
|
||||
private lazy var sendTextBtn:UIButton = {
|
||||
let _sendTextBtn = UIButton()
|
||||
_sendTextBtn.setTitle("发送", for: .normal)
|
||||
_sendTextBtn.setTitleColor(ThemeColor(hexStr: "0x282828"), for: .normal)
|
||||
_sendTextBtn.titleLabel?.font = UIFont.getScaleFont(ofSize: 15, weight: .regular)
|
||||
let disabledImage = UIImage.image(color: ThemeColor(hexStr: "#F2F3F6"),size: CGSize(width: UIDevice.scaleWidth(width: 50), height: UIDevice.scaleWidth(width: 30)))
|
||||
_sendTextBtn.setBackgroundImage(disabledImage, for: .disabled)
|
||||
let normalImage = UIImage.image(color: ThemeColor(hexStr: "#FFE710"),size: CGSize(width: UIDevice.scaleWidth(width: 50), height: UIDevice.scaleWidth(width: 30)))
|
||||
_sendTextBtn.setBackgroundImage(normalImage, for: .normal)
|
||||
_sendTextBtn.isEnabled = false
|
||||
_sendTextBtn.layer.cornerRadius = UIDevice.scaleWidth(width: 5)
|
||||
_sendTextBtn.layer.masksToBounds = true
|
||||
_sendTextBtn.addTarget(self, action: #selector(sendTextAction), for: .touchUpInside)
|
||||
return _sendTextBtn
|
||||
}()
|
||||
}
|
||||
extension RoomSendTextView:UITextFieldDelegate{
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
textField.resignFirstResponder()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -22,4 +22,5 @@ struct RoomQuitModel: HandyJSON {
|
||||
var infoUid = ""
|
||||
var nick = ""
|
||||
var roomPwd = ""
|
||||
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ class RoomQuitUserInfoCell: UITableViewCell {
|
||||
make.width.height.equalTo(UIDevice.scaleWidth(width: 72))
|
||||
}
|
||||
roomNameView.snp.makeConstraints { make in
|
||||
make.top.equalTo(avatarView.snp.bottom).offset(UIDevice.scaleWidth(width: 12))
|
||||
make.top.equalTo(avatarView.snp.top).offset(UIDevice.scaleWidth(width: 12))
|
||||
make.leading.equalTo(avatarView.snp.trailing).offset((UIDevice.scaleWidth(width: 7)))
|
||||
make.height.equalTo(UIDevice.scaleWidth(width: 14))
|
||||
make.trailing.equalTo(-UIDevice.scaleWidth(width: 0))
|
||||
}
|
||||
typeIconView.snp.makeConstraints { make in
|
||||
make.width.equalTo(UIDevice.scaleWidth(width: 34))
|
||||
make.width.equalTo(UIDevice.scaleWidth(width: 43))
|
||||
make.height.equalTo(UIDevice.scaleWidth(width: 18))
|
||||
make.top.equalTo(roomNameView.snp.bottom).offset(UIDevice.scaleWidth(width: 12))
|
||||
make.leading.equalTo(roomNameView)
|
||||
|
||||
@@ -78,7 +78,12 @@ class RoomQuitView: UIView {
|
||||
reportModel.image = "yin_room_report_icon"
|
||||
return [quitModel,reportModel]
|
||||
}
|
||||
var roomModelList:[RoomQuitModel] = []
|
||||
var roomModelList:[RoomQuitModel] = []{
|
||||
didSet{
|
||||
print(roomModelList.count)
|
||||
tableView.reloadData()
|
||||
}
|
||||
}
|
||||
private lazy var bgMaskView:UIVisualEffectView = {
|
||||
var _bgMaskView = UIVisualEffectView()
|
||||
let blurEffect = UIBlurEffect(style: .dark)
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
import UIKit
|
||||
import MarqueeLabel
|
||||
import FFPopup
|
||||
import Nuke
|
||||
|
||||
|
||||
typealias DidClickTypeBlcok = (_ type:Int,_ uid:String)->Void
|
||||
|
||||
class RoomTopView: UIView {
|
||||
|
||||
@@ -23,7 +27,7 @@ class RoomTopView: UIView {
|
||||
private func setUILayout(){
|
||||
addSubview(superStackView)
|
||||
addSubview(settingBnt)
|
||||
|
||||
quitView.delegate = self
|
||||
superStackView.addSubview(avatarView)
|
||||
superStackView.addSubview(nameStackView)
|
||||
superStackView.addSubview(colectRoomBtn)
|
||||
@@ -95,20 +99,65 @@ class RoomTopView: UIView {
|
||||
}
|
||||
|
||||
//MARK: - bntTarget
|
||||
@objc func colectRoomAction(){
|
||||
colectRoomBtn.isSelected = !colectRoomBtn.isSelected
|
||||
let width:CGFloat = !colectRoomBtn.isSelected ? 40 : 50
|
||||
colectRoomBtn.snp.updateConstraints { make in
|
||||
make.width.equalTo(UIDevice.scaleWidth(width: width))
|
||||
var roomData:RoomDataModel? = nil{
|
||||
didSet{
|
||||
guard let _roomData = roomData else { return }
|
||||
userIdView.text = "ID:\(_roomData.erbanNo)"
|
||||
textView.text = _roomData.title
|
||||
|
||||
colectRoomBtn.isSelected = _roomData.isRoomFans
|
||||
lockIconView.isHidden = _roomData.roomPwd.isEmpty
|
||||
giftIconView.isHidden = _roomData.hasAnimationEffect
|
||||
onlineNumView.text = "\(_roomData.onlineNum)"
|
||||
Nuke.loadImage(with: _roomData.avatar, into: avatarView, completion: nil)
|
||||
colectRoomBtn.isHidden = true
|
||||
if !_roomData.isRoomFans,_roomData.uid != "\(AuthManager.userUid)"{
|
||||
colectRoomBtn.isHidden = false
|
||||
}
|
||||
|
||||
if colectRoomBtn.isHidden{
|
||||
colectRoomBtn.snp.updateConstraints { make in
|
||||
make.width.equalTo(UIDevice.scaleWidth(width: 0))
|
||||
}
|
||||
}else{
|
||||
colectRoomBtn.snp.updateConstraints { make in
|
||||
make.width.equalTo(UIDevice.scaleWidth(width: 40))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@objc func colectRoomAction(){
|
||||
colectRoomBtn.isHidden = true
|
||||
|
||||
colectRoomBtn.snp.updateConstraints { make in
|
||||
make.width.equalTo(0)
|
||||
}
|
||||
guard let roomUid = roomData?.uid else { return }
|
||||
RoomVCViewModel.roomVM.collectRoom(roomUid: roomUid, type:"1" )
|
||||
}
|
||||
@objc func settingBntAction(){
|
||||
|
||||
let pop = FFPopup.init(contentView: quitView, showType: .slideInFromRight, dismissType: .slideOutToRight, maskType: FFPopup.MaskType.dimmed, dismissOnBackgroundTouch: true, dismissOnContentTouch: false)
|
||||
pop.show(layout: FFPopupLayout(horizontal: FFPopup.HorizontalLayout.right, vertical: FFPopup.VerticalLayout.center), duration:0)
|
||||
|
||||
let params = ["uid":"\(AuthManager.userUid)"] as [String : Any]
|
||||
RequestGet(path: "home/hotRoom", parma: params) { data in
|
||||
if let list = Deserialized<RoomQuitModel>.toArray(with: data) {
|
||||
var getList:[RoomQuitModel] = []
|
||||
for item in list {
|
||||
if !item.tagPict.isEmpty{
|
||||
getList.append(item)
|
||||
}
|
||||
}
|
||||
self.quitView.roomModelList = getList
|
||||
}
|
||||
} fail: { code, message in
|
||||
print(code)
|
||||
}
|
||||
|
||||
}
|
||||
//MARK: - 懒加载
|
||||
var didClickTypeBlcok:DidClickTypeBlcok?
|
||||
private lazy var quitView:RoomQuitView = {
|
||||
let _quitView = RoomQuitView(frame: CGRect(x: ScreenWidth, y: 0, width: UIDevice.scaleWidth(width: 250), height: ScreenHeight))
|
||||
|
||||
@@ -127,7 +176,7 @@ class RoomTopView: UIView {
|
||||
_colectRoomBtn.layer.masksToBounds = true
|
||||
_colectRoomBtn.contentEdgeInsets = UIEdgeInsets(top: 0, left: UIDevice.scaleWidth(width: 7), bottom: 0, right: UIDevice.scaleWidth(width: 7))
|
||||
_colectRoomBtn.addTarget(self, action: #selector(colectRoomAction), for: .touchUpInside)
|
||||
// _colectRoomBtn.isHidden = true
|
||||
_colectRoomBtn.isHidden = true
|
||||
return _colectRoomBtn
|
||||
}()
|
||||
private lazy var nameStackView:UIStackView = {
|
||||
@@ -147,12 +196,12 @@ class RoomTopView: UIView {
|
||||
}()
|
||||
private lazy var textView:MarqueeLabel = {
|
||||
let _textView = MarqueeLabel()
|
||||
_textView.text = "我是一个小萌新"
|
||||
_textView.text = ""
|
||||
_textView.speed = .duration(8)
|
||||
_textView.fadeLength = UIDevice.scaleWidth(width: 6)
|
||||
_textView.font = UIFont.getScaleFont(ofSize: 12, weight: .medium)
|
||||
_textView.textColor = .white
|
||||
// _textView.isUserInteractionEnabled = true
|
||||
_textView.isUserInteractionEnabled = true
|
||||
return _textView
|
||||
}()
|
||||
private lazy var giftIconView:UIImageView = {
|
||||
@@ -165,7 +214,7 @@ class RoomTopView: UIView {
|
||||
let _lockIconView = UIImageView()
|
||||
_lockIconView.image = UIImage(named: "yin_room_top_lock_icon")
|
||||
_lockIconView.isUserInteractionEnabled = true
|
||||
// _lockIconView.isHidden = true
|
||||
_lockIconView.isHidden = true
|
||||
return _lockIconView
|
||||
}()
|
||||
|
||||
@@ -181,16 +230,16 @@ class RoomTopView: UIView {
|
||||
let _greenPointView = UIView()
|
||||
_greenPointView.backgroundColor = ThemeColor(hexStr: "#3EFED7")
|
||||
_greenPointView.layer.cornerRadius = UIDevice.scaleWidth(width: 3)/2
|
||||
// _greenPointView.layer.masksToBounds = true
|
||||
_greenPointView.layer.masksToBounds = true
|
||||
|
||||
return _greenPointView
|
||||
}()
|
||||
private lazy var userIdView:UILabel = {
|
||||
let _userIdView = UILabel.getCustomLabel(text:"ID:837283",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white)
|
||||
let _userIdView = UILabel.getCustomLabel(text:"",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white)
|
||||
return _userIdView
|
||||
}()
|
||||
private lazy var onlineNumView:UILabel = {
|
||||
let _onlineNumView = UILabel.getCustomLabel(text:"100",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white)
|
||||
let _onlineNumView = UILabel.getCustomLabel(text:"0",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white)
|
||||
|
||||
return _onlineNumView
|
||||
}()
|
||||
@@ -200,7 +249,6 @@ class RoomTopView: UIView {
|
||||
_avatarView.layer.masksToBounds = true
|
||||
_avatarView.layer.cornerRadius = UIDevice.scaleWidth(width: 17)
|
||||
_avatarView.contentMode = .scaleAspectFill
|
||||
_avatarView.backgroundColor = .yellow
|
||||
return _avatarView
|
||||
}()
|
||||
private lazy var superStackView:UIView = {
|
||||
@@ -216,9 +264,20 @@ class RoomTopView: UIView {
|
||||
|
||||
extension RoomTopView:RoomQuitViewProtocol{
|
||||
func didChooseRoomWithModel(roomModel: RoomQuitModel?) {
|
||||
|
||||
guard let uid = roomModel?.uid else { return }
|
||||
FFPopup.dismiss(contentView: quitView, animated: false)
|
||||
if let _didClickTypeBlcok = didClickTypeBlcok{
|
||||
_didClickTypeBlcok(1,"\(uid)")
|
||||
}
|
||||
}
|
||||
func didClickTypeWithModel(clickModel: RoomQuitItemModel) {
|
||||
|
||||
FFPopup.dismiss(contentView: quitView, animated: false)
|
||||
if clickModel.type == .report{
|
||||
HUDTool.show(with: "我们已经收到举报, 将尽快处理")
|
||||
}else{
|
||||
if let _didClickTypeBlcok = didClickTypeBlcok{
|
||||
_didClickTypeBlcok(0,"")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,9 +181,11 @@ extension UserInfoVC: UserFunctionViewProtocol{
|
||||
self.navigationController?.pushViewController(vc, animated: true)
|
||||
print("aaa")
|
||||
case .myRoom:
|
||||
let vc = RoomVC()
|
||||
vc.modalPresentationStyle = .fullScreen
|
||||
self.present(vc, animated: true, completion: nil)
|
||||
|
||||
let vc = RoomVC(roomUid: "\(AuthManager.userUid)")
|
||||
let nav = BaseNavigationViewController.init(rootViewController: vc)
|
||||
nav.modalPresentationStyle = .fullScreen
|
||||
self.present(nav, animated: true, completion: nil)
|
||||
case .mobile:
|
||||
if self.info?.isBindPhone == true {
|
||||
HUDTool.show(with: "您已绑定手机号")
|
||||
|
||||
@@ -23,17 +23,31 @@ struct UserFunctionItem {
|
||||
}
|
||||
|
||||
struct UserObject: HandyJSON {
|
||||
|
||||
|
||||
var uid:Int? = 0
|
||||
var erbanNo:Int? = 0
|
||||
var avatar:String? = ""
|
||||
var nick:String? = ""
|
||||
var gender:GenderEnum? = .male
|
||||
var gender:UserSexType? = .Boy
|
||||
var isBindPhone:Bool? = false
|
||||
var isBindPasswd:Bool? = false
|
||||
var phone:String? = ""
|
||||
var giftValue:Int64 = 0
|
||||
var userLevelVo:userLevelModel?
|
||||
}
|
||||
|
||||
enum GenderEnum:Int,HandyJSONEnum {
|
||||
case male = 1
|
||||
case female = 2
|
||||
struct userLevelModel:HandyJSON{
|
||||
var charmUrl = ""{
|
||||
didSet{
|
||||
charmNewUrl = MAIDESEncryptTool.getCharmImageUrl(charmUrl)
|
||||
}
|
||||
}
|
||||
var experUrl = ""{
|
||||
didSet{
|
||||
experNewUrl = MAIDESEncryptTool.getWealthImageUrl(experUrl)
|
||||
}
|
||||
}
|
||||
var experNewUrl = ""
|
||||
var charmNewUrl = ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user