Commit 1f739415 authored by pete谢兆麟's avatar pete谢兆麟

Merge branch 'yinhe-live-1212' of...

Merge branch 'yinhe-live-1212' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS into yinhe-live-1212
parents 98659a25 5f1b5fc7
......@@ -294,7 +294,10 @@
04564D4F2CF38E20004456E4 /* YHLiveMessageListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D4E2CF38E20004456E4 /* YHLiveMessageListView.swift */; };
04564D512CF38EA4004456E4 /* YHMessageInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D502CF38EA4004456E4 /* YHMessageInputView.swift */; };
04564D532CF38FE2004456E4 /* YHVODPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D522CF38FE2004456E4 /* YHVODPlayerViewController.swift */; };
04564D562CF4467B004456E4 /* YHPlayerTopBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D552CF4467B004456E4 /* YHPlayerTopBarView.swift */; };
04564D592CF470B2004456E4 /* YHIncomeRecordCompanyTipsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D582CF470B2004456E4 /* YHIncomeRecordCompanyTipsCell.swift */; };
04564D5D2CF49F0A004456E4 /* live_room_test_bg.png in Resources */ = {isa = PBXBuildFile; fileRef = 04564D5C2CF49F0A004456E4 /* live_room_test_bg.png */; };
04564D5F2CF565C7004456E4 /* YHInputBottomBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D5E2CF565C7004456E4 /* YHInputBottomBar.swift */; };
0457920B2CBCE7B200EBD99B /* YHResignUploadTravelCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0457920A2CBCE7B200EBD99B /* YHResignUploadTravelCardViewModel.swift */; };
0457920D2CBCE8A800EBD99B /* YHResignUploadTravelCardListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0457920C2CBCE8A800EBD99B /* YHResignUploadTravelCardListModel.swift */; };
0457920F2CBCE9D000EBD99B /* YHResignUploadTravelCardListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0457920E2CBCE9D000EBD99B /* YHResignUploadTravelCardListTableViewCell.swift */; };
......@@ -1341,7 +1344,10 @@
04564D4E2CF38E20004456E4 /* YHLiveMessageListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHLiveMessageListView.swift; sourceTree = "<group>"; };
04564D502CF38EA4004456E4 /* YHMessageInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMessageInputView.swift; sourceTree = "<group>"; };
04564D522CF38FE2004456E4 /* YHVODPlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHVODPlayerViewController.swift; sourceTree = "<group>"; };
04564D552CF4467B004456E4 /* YHPlayerTopBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHPlayerTopBarView.swift; sourceTree = "<group>"; };
04564D582CF470B2004456E4 /* YHIncomeRecordCompanyTipsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHIncomeRecordCompanyTipsCell.swift; sourceTree = "<group>"; };
04564D5C2CF49F0A004456E4 /* live_room_test_bg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = live_room_test_bg.png; sourceTree = "<group>"; };
04564D5E2CF565C7004456E4 /* YHInputBottomBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHInputBottomBar.swift; sourceTree = "<group>"; };
0457920A2CBCE7B200EBD99B /* YHResignUploadTravelCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResignUploadTravelCardViewModel.swift; sourceTree = "<group>"; };
0457920C2CBCE8A800EBD99B /* YHResignUploadTravelCardListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResignUploadTravelCardListModel.swift; sourceTree = "<group>"; };
0457920E2CBCE9D000EBD99B /* YHResignUploadTravelCardListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResignUploadTravelCardListTableViewCell.swift; sourceTree = "<group>"; };
......@@ -2931,10 +2937,13 @@
04564D412CF1BEA2004456E4 /* V */ = {
isa = PBXGroup;
children = (
04564D5C2CF49F0A004456E4 /* live_room_test_bg.png */,
04564D462CF3851D004456E4 /* YHPlayerControlView.swift */,
04564D4C2CF38D16004456E4 /* YHLiveMessageCell.swift */,
04564D4E2CF38E20004456E4 /* YHLiveMessageListView.swift */,
04564D502CF38EA4004456E4 /* YHMessageInputView.swift */,
04564D552CF4467B004456E4 /* YHPlayerTopBarView.swift */,
04564D5E2CF565C7004456E4 /* YHInputBottomBar.swift */,
);
path = V;
sourceTree = "<group>";
......@@ -5678,6 +5687,7 @@
A51044182B493675006B60BB /* README.md in Resources */,
A5EE42012C216C78005BBA5D /* img_0.png in Resources */,
04F0ABF32C364F9400518C30 /* home.json in Resources */,
04564D5D2CF49F0A004456E4 /* live_room_test_bg.png in Resources */,
04943BE82CF0A0B500BF2255 /* submit_page_scroll.gif in Resources */,
A5573EDB2B317C0000D98EC0 /* Assets.xcassets in Resources */,
04F0ABF52C364F9400518C30 /* community.json in Resources */,
......@@ -5791,6 +5801,7 @@
04FD85722C21786900BEF9C5 /* YHNameCardInfoView.swift in Sources */,
044D0C182C22AB7300C5CF5E /* YHEditBaseInfoFootView.swift in Sources */,
047AA3F42C50E5C7009C4554 /* YHInvitationWithGiftsViewModel.swift in Sources */,
04564D562CF4467B004456E4 /* YHPlayerTopBarView.swift in Sources */,
04CE1AD52C2AD91F001CB80A /* YHActivityTravelViewController.swift in Sources */,
044EE2482C93E49C00A2FE3A /* YHResignCertificateHKTableViewCell.swift in Sources */,
A5EF21372BA6E2D1005027E6 /* YHQuestionAndAnswerModel.swift in Sources */,
......@@ -6113,6 +6124,7 @@
0449EEF02C902A4100A397FD /* YHResignMaterialUploadVC.swift in Sources */,
04129E862CD0C8490072F87B /* YHAliYunLogManager.swift in Sources */,
04174D642BCD52BD000BA46D /* YHDeviceInfoViewController.swift in Sources */,
04564D5F2CF565C7004456E4 /* YHInputBottomBar.swift in Sources */,
0472E25E2C534723008EAB6E /* YHLifeDetailViewController.swift in Sources */,
0457920D2CBCE8A800EBD99B /* YHResignUploadTravelCardListModel.swift in Sources */,
A5ACE92E2B4564F7002C94D2 /* YHValidateCodeInputView.swift in Sources */,
......
......@@ -9,7 +9,7 @@
import AgoraRtcKit
import UIKit
class YHBasePlayerViewController: UIViewController {
class YHBasePlayerViewController: YHBaseViewController {
// MARK: - Properties
var playerKit: AgoraRtcMediaPlayerProtocol!
......@@ -17,15 +17,23 @@ class YHBasePlayerViewController: UIViewController {
// MARK: - UI Components
private lazy var containerView: UIView = {
lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = .black
return view
}()
lazy var bgIcon: UIImageView = {
let imageView = UIImageView()
if let path = Bundle.main.path(forResource: "live_room_test_bg", ofType: "png") {
imageView.image = UIImage(contentsOfFile: path)
}
return imageView
}()
lazy var playerView: UIView = {
let view = UIView()
view.backgroundColor = .black
view.backgroundColor = .clear
return view
}()
......@@ -34,6 +42,11 @@ class YHBasePlayerViewController: UIViewController {
view.delegate = self
return view
}()
private lazy var topBarView: YHPlayerTopBarView = {
let view = YHPlayerTopBarView(frame: CGRect.init(x: 0, y: 0, width: KScreenWidth, height: k_Height_NavigationtBarAndStatuBar))
return view
}()
// MARK: - Lifecycle
......@@ -46,11 +59,14 @@ class YHBasePlayerViewController: UIViewController {
// MARK: - Setup
private func setupUI() {
gk_navBarAlpha = 0
gk_navigationBar.isHidden = true
view.backgroundColor = .black
view.addSubview(containerView)
containerView.addSubview(bgIcon)
containerView.addSubview(playerView)
containerView.addSubview(controlView)
containerView.addSubview(topBarView)
setupConstraints()
}
......@@ -59,19 +75,30 @@ class YHBasePlayerViewController: UIViewController {
containerView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
playerView.snp.makeConstraints { make in
bgIcon.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
controlView.snp.makeConstraints { make in
playerView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
topBarView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.height.equalTo(k_Height_NavigationtBarAndStatuBar)
}
// controlView.snp.makeConstraints { make in
// make.edges.equalToSuperview()
// }
}
private func setupAgoraKit() {
let config = AgoraRtcEngineConfig()
config.appId = YhConstant.AgoraRtcKit.appId
config.areaCode = .global
config.channelProfile = .liveBroadcasting
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
playerKit = agoraKit.createMediaPlayer(with: self)
......@@ -208,7 +235,7 @@ extension YHBasePlayerViewController {
return String(format: "%02d:%02d", minutes, seconds)
}
private func showAlert(message: String) {
func showAlert(message: String) {
let alert = UIAlertController(title: "提示",
message: message,
preferredStyle: .alert)
......
......@@ -12,7 +12,12 @@ import UIKit
class YHLivePlayerViewController: YHBasePlayerViewController {
// MARK: - Properties
private var roomInfo: YHLiveRoomInfo
private var messageListView: YHLiveMessageListView!
private lazy var messageListView: YHLiveMessageListView = YHLiveMessageListView()
private lazy var bottomInputBar: YHInputBottomBar = {
let view = YHInputBottomBar()
return view
}()
// MARK: - Initialization
init(roomInfo: YHLiveRoomInfo) {
......@@ -27,20 +32,26 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupMessageList()
setupUI()
startLive()
}
// MARK: - Setup
private func setupMessageList() {
messageListView = YHLiveMessageListView()
view.addSubview(messageListView)
private func setupUI() {
containerView.addSubview(bottomInputBar)
// containerView.addSubview(messageListView)
messageListView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.bottom.equalTo(view.safeAreaLayoutGuide)
make.height.equalTo(view.snp.height).multipliedBy(0.3)
bottomInputBar.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.top.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-YHInputBottomBar.inputActionHeight)
}
// messageListView.snp.makeConstraints { make in
// make.left.right.equalToSuperview()
// make.bottom.equalTo(bottomInputBar.snp.top)
// make.height.equalTo(view.snp.height).multipliedBy(0.3)
// }
}
private func startLive() {
......@@ -55,7 +66,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
let result = playerKit.open(with: mediaSource)
if result != 0 {
//showAlert(message: "播放失败,错误码:\(result)")
showAlert(message: "播放失败,错误码:\(result)")
}
}
}
......
......@@ -82,7 +82,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
let result = playerKit.open(with: mediaSource)
if result != 0 {
//showAlert(message: "播放失败,错误码:\(result)")
showAlert(message: "播放失败,错误码:\(result)")
}
}
......
......@@ -11,9 +11,11 @@ import HyphenateChat
class YHIMTestViewController: YHBaseViewController {
private let roomID : String = "265231954673700"
private let roomID : String = "265239166779417"
private let yHID : String = "1040217809134595"
private var myTextField : UITextField?
override func viewDidLoad() {
super.viewDidLoad()
......@@ -21,182 +23,338 @@ class YHIMTestViewController: YHBaseViewController {
//1.
gk_navTitle = "IM 测试"
let addBtn = UIButton()
addBtn.setTitle("发送", for: .normal)
view.addSubview(addBtn)
addBtn.snp.makeConstraints { make in
make.centerX.centerY.equalToSuperview()
make.height.width.equalTo(200)
if EMClient.shared().isLoggedIn {
YHHUD.flash(message: "已 登录IM服务器")
} else {
YHHUD.flash(message: "未 登录IM服务器")
}
addBtn.backgroundColor = UIColor.red//for test hjl
addBtn.addTarget(self, action: #selector(sendMessage), for: .touchUpInside)
setupUI()
//2、处理代理回调
EMClient.shared().roomManager?.add(self, delegateQueue: nil)
EMClient.shared().chatManager?.add(self, delegateQueue: nil)
}
deinit {
EMClient.shared().roomManager?.remove(self)
EMClient.shared().chatManager?.remove(self)
}
}
private extension YHIMTestViewController {
func setupUI() {
var tagView : UIView?
//2
//注册用户
//1.登录
do {
let addBtn = UIButton()
addBtn.setTitle("1、登录IM 服务器", for: .normal)
view.addSubview(addBtn)
addBtn.snp.makeConstraints { make in
make.top.equalToSuperview().offset(80)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
addBtn.backgroundColor = UIColor.red//for test hjl
addBtn.addTarget(self, action: #selector(userLoginOp), for: .touchUpInside)
tagView = addBtn
}
// 异步方法
// [[EMClient sharedClient] registerWithUsername:@"username"
// password:@"your password"
// completion:^(NSString *aUsername, EMError *aError) {
// }];
//2.加入聊天室
do {
let addBtn = UIButton()
addBtn.setTitle("2、加入聊天室", for: .normal)
view.addSubview(addBtn)
if let tagView = tagView {
addBtn.snp.makeConstraints { make in
make.top.equalTo(tagView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
}
addBtn.backgroundColor = UIColor.red
addBtn.addTarget(self, action: #selector(joinChatRoom), for: .touchUpInside)
tagView = addBtn
}
// EMClient.shared().register(withUsername: "davidTest", password: "galaxy-666") { aUsername, error in
// if let err = error {
// print("注册失败")
// print(err.description)
// } else {
// print("注册成功")
//
//
// //登录账号
//// [[EMClient sharedClient] loginWithUsername:@"username"
//// password:@"your password"
//// completion:^(NSString *aUsername, EMError *aError) {
////
//// }];
//
// EMClient.shared().login(withUsername: "davidTest", password: "galaxy-666") { aUsername, error in
// if let err = error {
// print("登录失败")
// print(err.description)
// } else {
// print("登录成功")
//
//
//
// }
// }
// }
// }
//3.发送消息
do {
let textField : UITextField = UITextField()
textField.placeholder = "请输入发送内容"
textField.borderStyle = .line
view.addSubview(textField)
if let tagView = tagView {
textField.snp.makeConstraints { make in
make.top.equalTo(tagView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
}
tagView = textField
myTextField = textField
let addBtn = UIButton()
addBtn.setTitle("3、发送信息", for: .normal)
view.addSubview(addBtn)
if let tagView = tagView {
addBtn.snp.makeConstraints { make in
make.top.equalTo(tagView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
}
addBtn.backgroundColor = UIColor.red
addBtn.addTarget(self, action: #selector(sendMessage), for: .touchUpInside)
tagView = addBtn
}
EMClient.shared().roomManager?.add(self, delegateQueue: nil)
EMClient.shared().chatManager?.add(self, delegateQueue: nil)
//4.获取历史消息
do {
let addBtn = UIButton()
addBtn.setTitle("4、获取历史消息-需付费", for: .normal)
view.addSubview(addBtn)
if let tagView = tagView {
addBtn.snp.makeConstraints { make in
make.top.equalTo(tagView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
}
addBtn.backgroundColor = UIColor.red
addBtn.addTarget(self, action: #selector(fetchHistoryMessage), for: .touchUpInside)
tagView = addBtn
}
EMClient.shared().login(withUsername: yHID, token: "YWMtqUTnNKsxEe-ZVA-eCJXgmszPhuTA1UDqp8xrPJoVisk1wDGwqzER74uZ-bqVfmOVAwMAAAGTY4WtWgABUYBw0BfZJnoSM_kNt49EM81gKznPICMuPw-M2Fhj96-G7Q") { name, err in
//5、退出聊天室
do {
let addBtn = UIButton()
addBtn.setTitle("5、退出聊天室", for: .normal)
view.addSubview(addBtn)
if let tagView = tagView {
addBtn.snp.makeConstraints { make in
make.top.equalTo(tagView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
}
addBtn.backgroundColor = UIColor.red
addBtn.addTarget(self, action: #selector(quitChatRoom), for: .touchUpInside)
tagView = addBtn
}
//6.聊天室成员列表
do {
let addBtn = UIButton()
addBtn.setTitle("6、聊天室成员列表", for: .normal)
view.addSubview(addBtn)
if let tagView = tagView {
addBtn.snp.makeConstraints { make in
make.top.equalTo(tagView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
}
addBtn.backgroundColor = UIColor.red
addBtn.addTarget(self, action: #selector(fetchRoomMemberList), for: .touchUpInside)
tagView = addBtn
}
//7、退出IM服务器
do {
let addBtn = UIButton()
addBtn.setTitle("7、退出IM服务器", for: .normal)
view.addSubview(addBtn)
if let tagView = tagView {
addBtn.snp.makeConstraints { make in
make.top.equalTo(tagView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(44)
}
}
addBtn.backgroundColor = UIColor.red
addBtn.addTarget(self, action: #selector(quitIM), for: .touchUpInside)
tagView = addBtn
}
}
//7.聊天室成员列表
@objc func quitIM(){
EMClient.shared().logout(true) { err in
if let err = err {
print(err)
if err.code.rawValue == 200 {
EMClient.shared().roomManager?.joinChatroom("265249570750475", ext: "nickname=DavidTest", leaveOtherRooms: true, completion: { room, err in
if let err = err {
print("加入聊天室 - 失败")
print(err)
} else {
print("加入聊天室 - 成功")
}
})
} else {
print("登录 - 失败")
YHHUD.flash(message: err.errorDescription)
} else {
YHHUD.flash(message: "退出IM服务器-成功")
}
}
}
//6.聊天室成员列表
@objc func fetchRoomMemberList(){
EMClient.shared().roomManager?.getChatroomMemberListFromServer(withId: roomID, cursor: nil, pageSize: 20, completion: { result, error in
if let err = error {
YHHUD.flash(message: err.errorDescription)
} else {
if let ret = result {
let count = (ret.list?.count ?? 0) + 1
YHHUD.flash(message: "聊天室人数 \(count)")
}
}
})
}
//5.退出聊天室
@objc func quitChatRoom(){
EMClient.shared().roomManager?.leaveChatroom(roomID, completion: { err in
if let error = err {
YHHUD.flash(message: error.errorDescription)
} else {
print("登录 - 成功")
YHHUD.flash(message: "退出聊天室-成功")
}
})
}
//4.获取历史消息
@objc func fetchHistoryMessage(){
let option = EMFetchServerMessagesOption()
EMClient.shared().chatManager?.fetchMessagesFromServer(by: self.roomID, conversationType: .chatRoom, cursor: nil, pageSize: 50, option: option, completion: { result, err in
DispatchQueue.main.async {
//发送消息
EMClient.shared().roomManager?.joinChatroom("265249570750475", ext: "nickname=DavidTest", leaveOtherRooms: true, completion: { room, err in
if let err = err {
// 获取失败
printLog("获取历史消息--失败")
printLog(err)
YHHUD.flash(message: "获取历史消息-失败")
} else {
// 获取成功
printLog(result)
YHHUD.flash(message: "获取历史消息-成功")
if let err = err {
print("加入聊天室 - 失败")
print(err)
if let ret = result,let arr = ret.list,arr.count > 0 {
YHHUD.flash(message: "获取历史消息 \(arr.count) 条")
for (index,item) in arr.enumerated() {
printLog(item)
}
} else {
print("加入聊天室 - 成功")
YHHUD.flash(message: "获取历史消息 (0) 条")
}
})
}
}
}
DispatchQueue.main.async {
}
})
}
deinit {
EMClient.shared().chatManager?.remove(self)
EMClient.shared().roomManager?.remove(self)
}
}
private extension YHIMTestViewController {
//3.发送消息
@objc func sendMessage() {
var sendText : String = ""
if let tf = myTextField {
sendText = tf.text ?? ""
} else {
return
}
if sendText.isEmpty {
YHHUD.flash(message: "请输入内容")
return
}
getRoomInfo()
// 调用 initWithText 创建文本消息。`content` 为文本消息的内容。
let textMessageBody = EMTextMessageBody(text: "金龙发送的信息")
let textMessageBody = EMTextMessageBody(text: sendText)
// 消息接收方,单聊为对端用户的 ID,群聊为群组 ID,聊天室为聊天室 ID。
let conversationId = "265249570750475"
let message = EMChatMessage(conversationID: conversationId, body: textMessageBody, ext:nil)
let conversationId = roomID
let message = EMChatMessage(conversationID: conversationId, body: textMessageBody, ext:["fromNickName":"YinHe3775"])
// 会话类型,单聊为 `EMChatTypeChat`,群聊为 `EMChatTypeGroupChat`,聊天室为 `EMChatTypeChatRoom`,默认为单聊。
message.chatType = .chatRoom
// 发送消息。
// EMClient.shared().chatManager?.sendMessage(message, progress: nil) { result in
// switch result {
// case .success:
// print("消息发送成功")
// case .failure(let error):
// print("消息发送失败: \(error.localizedDescription)")
// }
// }
EMClient.shared().chatManager?.send(message, progress: nil, completion: { message, error in
if let err = error {
printLog("消息发送 --- 失败")
YHHUD.flash(message: err.errorDescription)
} else {
printLog("消息发送 --- 成功")
//获取历史消息
let option = EMFetchServerMessagesOption();
EMClient.shared().chatManager?.fetchMessagesFromServer(by: "265249570750475", conversationType: .chatRoom, cursor: "", pageSize: 50, option: option, completion: { result, err in
if let err = err {
// 获取失败
printLog("获取历史消息 --- 失败")
printLog(err)
} else {
// 获取成功
printLog("获取历史消息 --- 成功")
printLog(result)
}
})
YHHUD.flash(message: "消息发送-成功")
}
})
}
func getRoomInfo() {
EMClient.shared().roomManager?.getChatroomSpecificationFromServer(withId: roomID, fetchMembers: true, completion: { emChatRoom, err in
printLog(emChatRoom)
//2.加入聊天室
@objc func joinChatRoom() {
EMClient.shared().roomManager?.joinChatroom(self.roomID, ext: "nickname=DavidTest", leaveOtherRooms: true, completion: { room, err in
if let err = err {
YHHUD.flash(message: err.errorDescription)
} else {
YHHUD.flash(message: "加入聊天室-成功")
}
})
EMClient.shared().roomManager?.getChatroomSpecificationFromServer(withId: roomID, completion: { emChatRoom, err in
printLog(emChatRoom)
}
//1.登录 IM服务器
@objc func userLoginOp() {
EMClient.shared().login(withUsername: yHID, token: "YWMtqUTnNKsxEe-ZVA-eCJXgmszPhuTA1UDqp8xrPJoVisk1wDGwqzER74uZ-bqVfmOVAwMAAAGTY4WtWgABUYBw0BfZJnoSM_kNt49EM81gKznPICMuPw-M2Fhj96-G7Q") { name, err in
if let err = err {
} else {
if let roomInfo = emChatRoom {
printLog(roomInfo.adminList)
printLog(roomInfo.chatroomId)
printLog(roomInfo.blacklist)
printLog(roomInfo.memberList)
if err.code.rawValue == 200 {
YHHUD.flash(message: err.errorDescription)
} else {
YHHUD.flash(message: "登录-失败")
}
} else {
YHHUD.flash(message: "登录-成功")
}
})
}
}
// func getRoomInfo() {
// EMClient.shared().roomManager?.getChatroomSpecificationFromServer(withId: roomID, fetchMembers: true, completion: { emChatRoom, err in
// printLog(emChatRoom)
// if let err = err {
//
// } else {
//
// }
// })
//
//
// EMClient.shared().roomManager?.getChatroomSpecificationFromServer(withId: roomID, completion: { emChatRoom, err in
// printLog(emChatRoom)
//
// if let err = err {
// print(err)
// } else {
//
// if let roomInfo = emChatRoom {
// printLog(roomInfo.adminList)
// printLog(roomInfo.chatroomId)
// printLog(roomInfo.blacklist)
// printLog(roomInfo.memberList)
// }
//
// }
// })
//
// }
}
// 收到其他人加入聊天室的回调
......@@ -205,28 +363,38 @@ extension YHIMTestViewController: EMChatroomManagerDelegate {
printLog(aChatroom)
printLog(aUsername)
printLog(ext)
YHHUD.flash(message: "\(aChatroom) 加入聊天室了")
}
func userDidJoin(_ aChatroom: EMChatroom, user aUsername: String) {
let memberCount = aChatroom.occupantsCount
printLog(memberCount)
YHHUD.flash(message: "\(aUsername) 加入 聊天室了")
}
func userDidLeave(_ aChatroom: EMChatroom, user aUsername: String) {
let memberCount = aChatroom.occupantsCount
printLog(memberCount)
YHHUD.flash(message: "\(aUsername) 离开 聊天室了")
}
}
extension YHIMTestViewController: EMChatManagerDelegate {
//收到消息
func messagesDidReceive(_ aMessages: [EMChatMessage]) {
for(i,t) in aMessages.enumerated() {
printLog(t)
printLog(t.ext)
var nickName : String = ""
if let ext = t.ext {
nickName = ext["fromNickName"] as? String ?? "YinHe"
}
if let body = t.body as? EMTextMessageBody,body.type == .text {
printLog(body.text)
YHHUD.flash(message: "\(nickName) : \(body.text)")
}
}
}
}
......
//
// YHInputBottomBar.swift
// galaxy
//
// Created by alexzzw on 2024/11/26.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHInputBottomBar: UIView {
static let inputActionHeight: CGFloat = 54
private let inputViewHeight: CGFloat = 38
var giftButtonClickEvent: (() -> Void)?
var textViewTappedEvent: (() -> Void)?
private lazy var inputBarView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.black.withAlphaComponent(0.3)
view.layer.cornerRadius = inputViewHeight / 2.0
view.clipsToBounds = true
let tap = UITapGestureRecognizer(target: self, action: #selector(didTappedTextView))
view.addGestureRecognizer(tap)
return view
}()
private lazy var editTipsLabel: UILabel = {
let label = UILabel()
label.text = "说点什么..."
label.font = .PFSC_R(ofSize: 13)
label.textColor = UIColor.white.withAlphaComponent(0.6)
return label
}()
private lazy var giftButton: UIButton = {
let button = UIButton(type: .custom)
button.setBackgroundImage(UIImage(named: "live_room_msg_gift"), for: .normal)
button.setTitle("99+", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.titleLabel?.font = .PFSC_M(ofSize: 10)
button.addTarget(self, action: #selector(giftButtonTapped), for: .touchUpInside)
button.titleEdgeInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
addSubview(inputBarView)
addSubview(editTipsLabel)
addSubview(giftButton)
inputBarView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(8)
make.left.equalToSuperview().offset(16)
make.height.equalTo(inputViewHeight)
}
giftButton.snp.makeConstraints { make in
make.left.equalTo(inputBarView.snp.right).offset(16)
make.right.equalToSuperview().offset(-16)
make.centerY.equalTo(inputBarView)
make.width.height.equalTo(38)
}
editTipsLabel.snp.makeConstraints { make in
make.left.equalTo(inputBarView.snp.left).offset(16)
make.centerY.equalTo(inputBarView)
}
}
func updateGiftCount(_ count: Int) {
guard count > 0 else {
inputBarView.snp.remakeConstraints { make in
make.top.equalToSuperview().offset(8)
make.left.equalToSuperview().offset(16)
make.height.equalTo(inputViewHeight)
make.right.equalToSuperview().offset(-16)
}
giftButton.snp.remakeConstraints { make in
make.right.equalToSuperview().offset(-16)
make.centerY.equalTo(inputBarView)
make.width.height.equalTo(38)
}
giftButton.isHidden = true
return
}
giftButton.isHidden = false
inputBarView.snp.remakeConstraints { make in
make.top.equalToSuperview().offset(8)
make.left.equalToSuperview().offset(16)
make.height.equalTo(inputViewHeight)
}
giftButton.snp.remakeConstraints { make in
make.left.equalTo(inputBarView.snp.right).offset(16)
make.right.equalToSuperview().offset(-16)
make.centerY.equalTo(inputBarView)
make.width.height.equalTo(38)
}
if count > 99 {
giftButton.setTitle("99+", for: .normal)
} else {
giftButton.setTitle("\(count)", for: .normal)
}
}
}
extension YHInputBottomBar {
@objc private func giftButtonTapped() {
giftButtonClickEvent?()
}
@objc private func didTappedTextView() {
textViewTappedEvent?()
}
}
......@@ -12,11 +12,18 @@ protocol YHMessageInputViewDelegate: AnyObject {
func messageInputView(_ inputView: YHMessageInputView, didSendMessage text: String)
}
enum YHMessageInputViewState {
case normalWithGift(_ count: Int)
case inputState
}
class YHMessageInputView: UIView {
// MARK: - Properties
weak var delegate: YHMessageInputViewDelegate?
// MARK: - UI Components
private lazy var textField: UITextField = {
let textField = UITextField()
textField.placeholder = "说点什么..."
......@@ -29,65 +36,95 @@ class YHMessageInputView: UIView {
textField.delegate = self
return textField
}()
private lazy var giftButton: UIButton = {
let button = UIButton(type: .custom)
button.setBackgroundImage(UIImage(named: "live_room_msg_gift"), for: .normal)
button.setTitle("2", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.titleLabel?.font = .PFSC_M(ofSize: 10)
button.addTarget(self, action: #selector(giftButtonTapped), for: .touchUpInside)
return button
}()
private lazy var sendButton: UIButton = {
let button = UIButton(type: .system)
let button = UIButton(type: .custom)
button.setTitle("发送", for: .normal)
button.titleLabel?.font = .PFSC_M(ofSize: 12)
button.setTitleColor(.white, for: .normal)
button.backgroundColor = .brandMainColor
button.layer.cornerRadius = 3
button.clipsToBounds = true
button.addTarget(self, action: #selector(sendButtonTapped), for: .touchUpInside)
return button
}()
var state: YHMessageInputViewState = .normalWithGift(2) {
didSet {
updateState(state)
}
}
// MARK: - Initialization
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
updateState(state)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
backgroundColor = UIColor.black.withAlphaComponent(0.4)
addSubview(textField)
addSubview(sendButton)
setupConstraints()
addSubview(giftButton)
}
private func setupConstraints() {
private func updateState(_ state: YHMessageInputViewState) {
// switch state {
// case let .normalWithGift(count):
// <#code#>
// case .inputState:
// <#code#>
// }
textField.snp.makeConstraints { make in
make.left.equalToSuperview().offset(8)
make.centerY.equalToSuperview()
make.right.equalTo(sendButton.snp.left).offset(-8)
make.height.equalTo(34)
}
sendButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-8)
make.centerY.equalToSuperview()
make.width.equalTo(50)
}
}
@objc private func sendButtonTapped() {
sendMessage()
}
@objc private func giftButtonTapped() {
//
}
private func sendMessage() {
guard let text = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines),
!text.isEmpty else {
return
}
delegate?.messageInputView(self, didSendMessage: text)
textField.text = ""
}
}
// MARK: - UITextFieldDelegate
extension YHMessageInputView: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
sendMessage()
......
//
// YHPlayerTopBarView.swift
// galaxy
//
// Created by alexzzw on 2024/11/25.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHPlayerTopBarView: UIView {
private let headerWidth: CGFloat = 32
private let buttonWidth: CGFloat = 32
var shareButtonClickEvent: (() -> Void)?
var zoomButtonClickEvent: (() -> Void)?
var closeButtonClickEvent: (() -> Void)?
private lazy var bottomVisualEffectView: UIVisualEffectView = {
let effect = UIBlurEffect(style: .dark)
let view = UIVisualEffectView(effect: effect)
view.alpha = 0.9
return view
}()
private lazy var headPortrait: UIImageView = {
let view = UIImageView()
view.layer.cornerRadius = headerWidth / 2.0
view.clipsToBounds = true
view.backgroundColor = .gray
return view
}()
private lazy var infoNameLabel: UILabel = {
let label = UILabel()
label.text = "优才E老师名字太长长况..."
label.textColor = .white
label.font = .PFSC_M(ofSize: 14)
return label
}()
private lazy var infoCountLabel: UILabel = {
let label = UILabel()
label.text = "865人来过"
label.textColor = .white.withAlphaComponent(0.7)
label.font = .PFSC_R(ofSize: 10)
return label
}()
private lazy var shareButton: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "live_room_share"), for: .normal)
button.addTarget(self, action: #selector(shareButtonClicked), for: .touchUpInside)
button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)
return button
}()
private lazy var zoomButton: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "live_room_zoom"), for: .normal)
button.addTarget(self, action: #selector(zoomButtonClicked), for: .touchUpInside)
button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)
return button
}()
private lazy var closeButton: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "live_room_close"), for: .normal)
button.addTarget(self, action: #selector(closeButtonClicked), for: .touchUpInside)
button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension YHPlayerTopBarView {
@objc private func shareButtonClicked() {
shareButtonClickEvent?()
}
@objc private func zoomButtonClicked() {
zoomButtonClickEvent?()
}
@objc private func closeButtonClicked() {
closeButtonClickEvent?()
}
private func setupUI() {
addSubview(bottomVisualEffectView)
addSubview(headPortrait)
addSubview(infoNameLabel)
addSubview(infoCountLabel)
addSubview(shareButton)
addSubview(zoomButton)
addSubview(closeButton)
bottomVisualEffectView.frame = CGRect(x: 0, y: 0, width: bounds.size.width, height: bounds.size.height)
bottomVisualEffectView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.height.equalToSuperview()
}
// 渐变效果
let gradinetLayer = CAGradientLayer()
gradinetLayer.colors = [UIColor.black.withAlphaComponent(0.16).cgColor, UIColor.black.withAlphaComponent(0.16).cgColor, UIColor.black.withAlphaComponent(0).cgColor, UIColor.black.withAlphaComponent(0).cgColor]
gradinetLayer.startPoint = CGPoint(x: 0.5, y: 0)
gradinetLayer.endPoint = CGPoint(x: 0.5, y: 1)
gradinetLayer.frame = bottomVisualEffectView.bounds
bottomVisualEffectView.layer.mask = gradinetLayer
headPortrait.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-6)
make.left.equalToSuperview().offset(16)
make.width.height.equalTo(headerWidth)
}
infoNameLabel.snp.makeConstraints { make in
make.top.equalTo(headPortrait.snp.top)
make.left.equalTo(headPortrait.snp.right).offset(8)
}
infoCountLabel.snp.makeConstraints { make in
make.top.equalTo(infoNameLabel.snp.bottom)
make.left.equalTo(infoNameLabel.snp.left)
}
closeButton.snp.makeConstraints { make in
make.centerY.equalTo(headPortrait)
make.right.equalToSuperview().offset(-12)
make.width.height.equalTo(buttonWidth)
}
zoomButton.snp.makeConstraints { make in
make.centerY.equalTo(headPortrait)
make.right.equalTo(closeButton.snp.left).offset(-8)
make.width.height.equalTo(buttonWidth)
}
shareButton.snp.makeConstraints { make in
make.centerY.equalTo(headPortrait)
make.right.equalTo(zoomButton.snp.left).offset(-8)
make.width.height.equalTo(buttonWidth)
make.left.greaterThanOrEqualTo(infoNameLabel.snp.right).offset(36)
make.left.greaterThanOrEqualTo(infoCountLabel.snp.right).offset(36)
}
}
}
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "live_room_close@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "live_room_close@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "live_room_msg_gift@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "live_room_msg_gift@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "live_room_share@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "live_room_share@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "live_room_zoom@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "live_room_zoom@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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