Commit a11671e2 authored by DavidHuang's avatar DavidHuang

用户进入 直播间提醒

parent ed038d84
...@@ -305,6 +305,13 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -305,6 +305,13 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
} }
private func setupLiveNotifications() { private func setupLiveNotifications() {
NotificationCenter.default.addObserver(
self,
selector: #selector(didUserEnterRoomMessages(_:)),
name: YHIMHelper.didUserEnterRoomMessages,
object: nil
)
NotificationCenter.default.addObserver( NotificationCenter.default.addObserver(
self, self,
selector: #selector(didChatManagerReceiveMessages(_:)), selector: #selector(didChatManagerReceiveMessages(_:)),
...@@ -328,7 +335,6 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -328,7 +335,6 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
NotificationCenter.default.addObserver(self, selector: #selector(didLoginYH), name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(didLoginYH), name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didLogOutYH), name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(didLogOutYH), name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didJoinedOfUid), name: Notification.Name("com.YHPlayerManager.didJoinedOfUid"), object: nil)
} }
// MARK: - Public Methods // MARK: - Public Methods
...@@ -594,7 +600,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -594,7 +600,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
} }
} }
} }
private func checkLogin() -> Bool { private func checkLogin() -> Bool {
if !YHLoginManager.shared.isLogin() { if !YHLoginManager.shared.isLogin() {
YHOneKeyLoginManager.shared.oneKeyLogin() YHOneKeyLoginManager.shared.oneKeyLogin()
...@@ -604,17 +610,6 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -604,17 +610,6 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
} }
// MARK: - Notification Handlers // MARK: - Notification Handlers
@objc private func didJoinedOfUid() {
let videoCanvas = AgoraRtcVideoCanvas()
videoCanvas.uid = playbackInfo?.uid ?? 0
videoCanvas.view = playerView
videoCanvas.renderMode = .fit
videoCanvas.backgroundColor = 0x000000
let ret = YHPlayerManager.shared.agoraKit.setupRemoteVideo(videoCanvas)
printLog(ret)
}
@objc private func didChatManagerReceiveMessages(_ note: Notification) { @objc private func didChatManagerReceiveMessages(_ note: Notification) {
guard let messages = note.object as? [EMChatMessage], guard let messages = note.object as? [EMChatMessage],
let message = messages.first, let message = messages.first,
...@@ -630,6 +625,29 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -630,6 +625,29 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
} }
} }
} }
//用户进入直播间通知
@objc private func didUserEnterRoomMessages(_ note: Notification) {
guard let messages = note.object as? String else {
return
}
appendUserEnterRoomMessage(messages)
}
private func appendUserEnterRoomMessage(_ userName: String) {
messageQueue.async {
let body = EMCustomMessageBody(event: YHChatRoomCustomLocal.userEnterRoomEvent, customExt: [YHChatRoomCustomLocal.userEnterRoomEvent: userName])
let message = EMChatMessage(conversationID: self.roomId ?? "", body: body, ext: nil)
message.chatType = .chatRoom
DispatchQueue.main.async {
self.messageListView.addMessages([message])
}
}
}
private func updateLiveDetailWith(event: YHChatRoomCustomEvent) { private func updateLiveDetailWith(event: YHChatRoomCustomEvent) {
viewModel.getLiveDetail(id: liveId) { [weak self] liveDetail, error in viewModel.getLiveDetail(id: liveId) { [weak self] liveDetail, error in
......
...@@ -25,12 +25,14 @@ enum YHChatRoomCustomEvent: String { ...@@ -25,12 +25,14 @@ enum YHChatRoomCustomEvent: String {
struct YHChatRoomCustomLocal { struct YHChatRoomCustomLocal {
static let tipsEvent = "YHLiveRoomTips" static let tipsEvent = "YHLiveRoomTips"
static let tipsKey = "tips" static let tipsKey = "tips"
static let userEnterRoomEvent = "userEnterRoomEvent" //用户进入聊天室 事件
} }
class YHIMHelper: NSObject { class YHIMHelper: NSObject {
static let didLoginEaseIMSuccess = Notification.Name("com.YHIMHelper.didLoginEaseIMSuccess") static let didLoginEaseIMSuccess = Notification.Name("com.YHIMHelper.didLoginEaseIMSuccess")
static let didLogOutEaseIM = Notification.Name("com.YHIMHelper.didLogOutEaseIM") static let didLogOutEaseIM = Notification.Name("com.YHIMHelper.didLogOutEaseIM")
static let didChatManagerReceiveMessages = Notification.Name("com.YHIMHelper.didChatManagerReceiveMessages") static let didChatManagerReceiveMessages = Notification.Name("com.YHIMHelper.didChatManagerReceiveMessages")
static let didUserEnterRoomMessages = Notification.Name("com.YHIMHelper.didUserEnterRoomMessages")//用户进入直播间
private let viewModel = YHLiveSalesViewModel() private let viewModel = YHLiveSalesViewModel()
var isCurrentUserLogin: Bool { var isCurrentUserLogin: Bool {
...@@ -222,7 +224,8 @@ extension YHIMHelper { ...@@ -222,7 +224,8 @@ extension YHIMHelper {
/// 加入聊天室 /// 加入聊天室
func joinChatRoom(roomID: String, leaveOtherRooms: Bool, completion: @escaping (EMError?) -> Void) { func joinChatRoom(roomID: String, leaveOtherRooms: Bool, completion: @escaping (EMError?) -> Void) {
printLog("joinChatRoom: \(currentNickname)") printLog("joinChatRoom: \(currentNickname)")
EMClient.shared().roomManager?.joinChatroom(roomID, ext: "fromNickName=\(currentNickname)", leaveOtherRooms: leaveOtherRooms, completion: { _, err in let jsonString = ["fromNickName":currentNickname].jsonString()
EMClient.shared().roomManager?.joinChatroom(roomID, ext: jsonString, leaveOtherRooms: leaveOtherRooms, completion: { _, err in
DispatchQueue.main.async { DispatchQueue.main.async {
if let err = err { if let err = err {
printLog(err.errorDescription) printLog(err.errorDescription)
...@@ -274,19 +277,28 @@ extension YHIMHelper { ...@@ -274,19 +277,28 @@ extension YHIMHelper {
extension YHIMHelper: EMChatroomManagerDelegate { extension YHIMHelper: EMChatroomManagerDelegate {
func userDidJoin(_ aChatroom: EMChatroom, user aUsername: String, ext: String?) { func userDidJoin(_ aChatroom: EMChatroom, user aUsername: String, ext: String?) {
printLog("\(aChatroom) 加入聊天室了1") printLog("\(aChatroom) 加入聊天室了1 ext = \(ext ?? "")")
if let jsonString = ext {
let dic = jsonString.toDictionary()
if let fromNickName = dic["fromNickName"] {
print(fromNickName)
NotificationCenter.default.post(name: YHIMHelper.didUserEnterRoomMessages, object: fromNickName)
return
}
}
} }
func userDidJoin(_ aChatroom: EMChatroom, user aUsername: String) { func userDidLeave(_ aChatroom: EMChatroom, user aUsername: String) {
let memberCount = aChatroom.occupantsCount let memberCount = aChatroom.occupantsCount
printLog(memberCount) printLog(memberCount)
printLog("\(aUsername) 加入 聊天室了2") printLog("\(aUsername) 离开 聊天室了1111")
} }
func userDidLeave(_ aChatroom: EMChatroom, user aUsername: String) { func userDidLeave(_ aChatroom: EMChatroom, user aUsername: String,ext: String?) {
let memberCount = aChatroom.occupantsCount let memberCount = aChatroom.occupantsCount
printLog(memberCount) printLog(memberCount)
printLog("\(aUsername) 离开 聊天室了") printLog("\(aUsername) 离开 聊天室了2222")
} }
} }
......
...@@ -92,4 +92,10 @@ class YHLiveMessageCell: UITableViewCell { ...@@ -92,4 +92,10 @@ class YHLiveMessageCell: UITableViewCell {
let contentAtt = (tipsIcon + ASAttributedString(string: " \(tips)", .foreground(UIColor.white), .font(UIFont.PFSC_R(ofSize: 13)))) let contentAtt = (tipsIcon + ASAttributedString(string: " \(tips)", .foreground(UIColor.white), .font(UIFont.PFSC_R(ofSize: 13))))
contentLabel.attributed.text = contentAtt contentLabel.attributed.text = contentAtt
} }
func configureUserEnterRoomMessage(_ usename: String) {
let contentAtt = (ASAttributedString(string: " \(usename)", .foreground(UIColor.brandMainColor), .font(UIFont.PFSC_R(ofSize: 13))))
contentLabel.attributed.text = contentAtt
}
} }
...@@ -116,13 +116,18 @@ extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource { ...@@ -116,13 +116,18 @@ extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource {
highlight = ext["replyTo"] as? String ?? "" highlight = ext["replyTo"] as? String ?? ""
} }
if let body = message.body as? EMTextMessageBody, body.type == .text { if let body = message.body as? EMTextMessageBody, body.type == .text {
//IM 文本消息
printLog(body.text) printLog(body.text)
printLog("\(nickName) : \(body.text)") printLog("\(nickName) : \(body.text)")
content = body.text content = body.text
let isAnchor = nickName == anchorName let isAnchor = nickName == anchorName
cell.configureNormalMessage(nickName, content,highlightTxt: highlight, isAnchor: isAnchor) cell.configureNormalMessage(nickName, content,highlightTxt: highlight, isAnchor: isAnchor)
} else if let body = message.body as? EMCustomMessageBody, body.event == YHChatRoomCustomLocal.tipsEvent, let customExt = body.customExt, let tips = customExt[YHChatRoomCustomLocal.tipsKey] { } else if let body = message.body as? EMCustomMessageBody, body.event == YHChatRoomCustomLocal.tipsEvent, let customExt = body.customExt, let tips = customExt[YHChatRoomCustomLocal.tipsKey] {
//直播间提示消息
cell.configureTipsMessage(tips) cell.configureTipsMessage(tips)
} else if let body = message.body as? EMCustomMessageBody, body.event == YHChatRoomCustomLocal.userEnterRoomEvent, let customExt = body.customExt, let userName = customExt[YHChatRoomCustomLocal.userEnterRoomEvent] {
//用户加入直播间消息
cell.configureUserEnterRoomMessage(userName)
} }
return cell return cell
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment