Commit d771a41c authored by Alex朱枝文's avatar Alex朱枝文

直播相关接口调试

parent 63ab92f3
......@@ -304,6 +304,8 @@
04564D682CF6BFA0004456E4 /* YHLiveSalesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D672CF6BFA0004456E4 /* YHLiveSalesViewModel.swift */; };
04564D6A2CF6C0FC004456E4 /* YHLiveDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D692CF6C0FC004456E4 /* YHLiveDetailModel.swift */; };
04564D6C2CF6C414004456E4 /* YHLivePlayerViewController+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D6B2CF6C414004456E4 /* YHLivePlayerViewController+Api.swift */; };
04564D6E2CF6EB3D004456E4 /* YHHuanXinUserModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D6D2CF6EB3D004456E4 /* YHHuanXinUserModel.swift */; };
04564D702CF6EC8A004456E4 /* YHRecordedDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04564D6F2CF6EC8A004456E4 /* YHRecordedDetailModel.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 */; };
......@@ -1360,6 +1362,8 @@
04564D672CF6BFA0004456E4 /* YHLiveSalesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHLiveSalesViewModel.swift; sourceTree = "<group>"; };
04564D692CF6C0FC004456E4 /* YHLiveDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHLiveDetailModel.swift; sourceTree = "<group>"; };
04564D6B2CF6C414004456E4 /* YHLivePlayerViewController+Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "YHLivePlayerViewController+Api.swift"; sourceTree = "<group>"; };
04564D6D2CF6EB3D004456E4 /* YHHuanXinUserModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHHuanXinUserModel.swift; sourceTree = "<group>"; };
04564D6F2CF6EC8A004456E4 /* YHRecordedDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRecordedDetailModel.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>"; };
......@@ -2970,6 +2974,8 @@
children = (
04564D442CF3812F004456E4 /* YHMediaProtocolUtils.swift */,
04564D692CF6C0FC004456E4 /* YHLiveDetailModel.swift */,
04564D6D2CF6EB3D004456E4 /* YHHuanXinUserModel.swift */,
04564D6F2CF6EC8A004456E4 /* YHRecordedDetailModel.swift */,
);
path = M;
sourceTree = "<group>";
......@@ -6262,6 +6268,7 @@
A5ACE9472B4564F7002C94D2 /* YHHUD.swift in Sources */,
045A08C02C37ABF500BCBABA /* YHSegmentView.swift in Sources */,
04564D532CF38FE2004456E4 /* YHVODPlayerViewController.swift in Sources */,
04564D702CF6EC8A004456E4 /* YHRecordedDetailModel.swift in Sources */,
A5ACE9412B4564F7002C94D2 /* Dictionary+Extension.swift in Sources */,
047AA3EA2C4A6FB7009C4554 /* YHDetailViewController.swift in Sources */,
045EEE8F2B9F171A0022A143 /* YHPreviewInfoProjectItemView.swift in Sources */,
......@@ -6346,6 +6353,7 @@
045EEF1E2B9F171A0022A143 /* YHBottomNextView.swift in Sources */,
A567E59E2BD7643D00D5D5A0 /* YHHomePageViewController.swift in Sources */,
0430E6502C73376A000511E2 /* YHAdopterIncomeTitleTableViewCell.swift in Sources */,
04564D6E2CF6EB3D004456E4 /* YHHuanXinUserModel.swift in Sources */,
044F39222CB50B34007CA277 /* YHResignDocumentUploadFileCell.swift in Sources */,
0485DFD82C66036600B50293 /* YHPrincipleFileRenameView.swift in Sources */,
045EEEBA2B9F171A0022A143 /* YHWorkResponsibilitiesTableViewCell.swift in Sources */,
......
......@@ -43,7 +43,7 @@ class YHBasePlayerViewController: YHBaseViewController {
return view
}()
private lazy var topBarView: YHPlayerTopBarView = {
lazy var topBarView: YHPlayerTopBarView = {
let view = YHPlayerTopBarView(frame: CGRect.init(x: 0, y: 0, width: KScreenWidth, height: k_Height_NavigationtBarAndStatuBar))
return view
}()
......@@ -64,7 +64,7 @@ class YHBasePlayerViewController: YHBaseViewController {
view.backgroundColor = .black
view.addSubview(containerView)
containerView.addSubview(bgIcon)
//containerView.addSubview(bgIcon)
containerView.addSubview(playerView)
containerView.addSubview(topBarView)
......@@ -76,9 +76,9 @@ class YHBasePlayerViewController: YHBaseViewController {
make.edges.equalToSuperview()
}
bgIcon.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
// bgIcon.snp.makeConstraints { make in
// make.edges.equalToSuperview()
// }
playerView.snp.makeConstraints { make in
make.edges.equalToSuperview()
......
......@@ -10,9 +10,9 @@ import Foundation
extension YHLivePlayerViewController {
func requestData(id: Int) {
func requestData(id: Int, callback: @escaping (_ liveDetail: YHLiveDetailModel?, _ error: YHErrorModel?) -> Void) {
viewModel.getLiveDetail(id: id) { liveDetail, error in
//
callback(liveDetail, error)
}
}
}
......@@ -11,7 +11,7 @@ import UIKit
class YHLivePlayerViewController: YHBasePlayerViewController {
// MARK: - Properties
private var roomInfo: YHLiveRoomInfo
//private var roomInfo: YHLiveRoomInfo
private var listMaxWidth: CGFloat {
return KScreenWidth * 248.0 / 375.0
......@@ -47,8 +47,9 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
let viewModel = YHLiveSalesViewModel()
// MARK: - Initialization
init(roomInfo: YHLiveRoomInfo) {
self.roomInfo = roomInfo
private let liveId: Int
init(id: Int) {
self.liveId = id
super.init(nibName: nil, bundle: nil)
}
......@@ -60,8 +61,20 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
startLive()
requestData(id: 23)
requestData(id: liveId) { [weak self] liveDetail, error in
guard let self = self else {
return
}
guard let liveDetail = liveDetail else {
printLog("YHLivePlayerViewController: 请求失败")
if let errorMsg = error?.errorMsg, errorMsg.count > 0 {
YHHUD.flash(message: errorMsg)
}
return
}
self.topBarView.setupTopBarView(headUrl: liveDetail.avatar, nickname: liveDetail.hxNickname, count: liveDetail.access_num)
self.play(with: liveDetail.pullUrl)
}
}
// MARK: - Setup
......@@ -82,10 +95,6 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
}
}
private func startLive() {
play(with: roomInfo.streamUrl)
}
// MARK: - Player Control
private func play(with url: String) {
let mediaSource = AgoraMediaSource()
......
//
// YHHuanXinUserModel.swift
// galaxy
//
// Created by alexzzw on 2024/11/27.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import Foundation
import SmartCodable
class YHHuanXinUserModel: SmartCodable {
var nickname: String = ""
var avatarurl: String = ""
required init() {
}
}
class YHHuanXinTokenModel: SmartCodable {
var accessToken: String = ""
required init() {
}
}
......@@ -22,7 +22,6 @@ class YHLiveDetailModel: SmartCodable {
var goods: [YHLiveGoodsItem] = []
required init() {
}
}
......@@ -37,14 +36,5 @@ class YHLiveGoodsItem: SmartCodable {
var banner: String = ""
required init() {
}
}
class YHXuanXinUserModel: SmartCodable {
var nickname: String = ""
var avatarurl: String = ""
required init() {
}
}
//
// YHRecordedDetailModel.swift
// galaxy
//
// Created by alexzzw on 2024/11/27.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import Foundation
import SmartCodable
class YHRecordedDetailModel: SmartCodable {
var account: String = ""
var avatar: String = ""
var access_num: Int = 0
var tips: String = ""
var subject: String = ""
var recorded_url: String = ""
var recorded_cover: String = ""
var goods: [YHLiveGoodsItem] = []
var recordedVideoCate: [YHRecordedVideoCategoryItem] = []
var recordedVideoSlice: [YHRecordedVideoSliceItem] = []
required init() {
}
}
class YHRecordedVideoCategoryItem: SmartCodable {
var id: Int = 0
var name: String = ""
required init() {
}
}
class YHRecordedVideoSliceItem: SmartCodable {
var startSecond: String = ""
var endSecond: String = ""
var tag: String = ""
var index: Int = 0
required init() {
}
}
......@@ -79,6 +79,20 @@ class YHPlayerTopBarView: UIView {
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupTopBarView(headUrl: String, nickname: String, count: Int) {
if let url = URL(string: headUrl) {
headPortrait.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
headPortrait.image = UIImage(named: "global_default_image")
}
infoNameLabel.text = nickname
updateCountLabel(count)
}
func updateCountLabel(_ count: Int) {
infoCountLabel.text = "\(count)人来过"
}
}
extension YHPlayerTopBarView {
......
......@@ -9,29 +9,30 @@
import UIKit
class YHLiveSalesViewModel: YHBaseViewModel {
//直播间详情
var liveDetailModel : YHLiveDetailModel?
//注册环信用户信息
var huanXinUserInfoModel : YHXuanXinUserModel?
// 直播间详情
var liveDetailModel: YHLiveDetailModel?
// 录播详情
var recordedDetailModel: YHRecordedDetailModel?
// 注册环信用户信息
var huanXinUserInfoModel: YHHuanXinUserModel?
// 获取环信Token信息
var huanXinTokenModel: YHHuanXinTokenModel?
}
extension YHLiveSalesViewModel {
/*
注册环信用户
*/
func registerHuanXinUser(id: Int, callBackBlock: @escaping (_ success: Bool,_ error: YHErrorModel?)->()) {
func registerHuanXinUser(callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.registerHuanXinUserApi
_ = YHNetRequest.postRequest(url: strUrl) { json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
if json.code == 200 {
guard let dic = json.data?.peel as? [String: Any], let resultModel = YHXuanXinUserModel.deserialize(from: dic) else {
guard let dic = json.data?.peel as? [String: Any], let resultModel = YHHuanXinUserModel.deserialize(from: dic) else {
let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
callBackBlock(false, err)
return
......@@ -49,13 +50,40 @@ extension YHLiveSalesViewModel {
}
}
/*
环信Token信息
*/
func getHuanXinToken(callback: @escaping (_ tokenModel: YHHuanXinTokenModel?, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.fetchHuanXinToken
_ = YHNetRequest.getRequest(url: strUrl, params: [:]) { [weak self] json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
if json.code == 200 {
guard let dic = json.data?.peel as? [String: Any], let resultModel = YHHuanXinTokenModel.deserialize(from: dic) else {
let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
callback(nil, err)
return
}
self?.huanXinTokenModel = resultModel
callback(resultModel, nil)
} else {
let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
callback(nil, err)
}
} failBlock: { err in
callback(nil, err)
}
}
/*
直播间详情
*/
func getLiveDetail(id: Int, callback: @escaping (_ liveDetail: YHLiveDetailModel?, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.liveDetail
_ = YHNetRequest.getRequest(url: strUrl, params: ["id": id]) { json, _ in
_ = YHNetRequest.getRequest(url: strUrl, params: ["id": id]) { [weak self] json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
......@@ -65,6 +93,7 @@ extension YHLiveSalesViewModel {
callback(nil, err)
return
}
self?.liveDetailModel = resultModel
callback(resultModel, nil)
} else {
......@@ -77,4 +106,31 @@ extension YHLiveSalesViewModel {
}
}
/*
点播详情
*/
func getRecordedDetail(id: Int, callback: @escaping (_ recordedDetail: YHRecordedDetailModel?, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.recordedDetail
_ = YHNetRequest.getRequest(url: strUrl, params: ["id": id]) { [weak self] json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
if json.code == 200 {
guard let dic = json.data?.peel as? [String: Any], let resultModel = YHRecordedDetailModel.deserialize(from: dic) else {
let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
callback(nil, err)
return
}
self?.recordedDetailModel = resultModel
callback(resultModel, nil)
} else {
let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
callback(nil, err)
}
} failBlock: { err in
callback(nil, err)
}
}
}
......@@ -663,9 +663,11 @@ class YHAllApiName {
struct LiveSales {
// 获取直播详情
static let liveDetail = "super-app/live/app-live-detail"
// 注册环信用户
static let registerHuanXinUserApi = "super-app/live/register-user-to-huanxin"
// APP获得环信的token
static let fetchHuanXinToken = "super-app/live/get-huanxin-token"
// 获取录播详情
static let recordedDetail = "super-app/recorded-video/app-recorded-detail"
}
}
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