双人连线 | 多人连线 |
![]() | ![]() |
点击连线按钮 | 选择主播发起连线 | 连线成功 | 断开连线 |
![]() | ![]() | ![]() | ![]() |
主播收到邀请 | 主播接受邀请 |
![]() | ![]() |
// 文件位置:iOS/TUILiveKit/Source/Service/ConnectionService.swiftfunc getRecommendedList(cursor: String, count: Int = 20) -> AnyPublisher<(String, [TUILiveInfo]), InternalError> {return Future<(String,[TUILiveInfo]), InternalError> { [weak self] promise inguard let self = self else { return }guard let listManager = roomEngine.getExtension(extensionType: .liveListManager) as? TUILiveListManager else {promise(.failure(InternalError(error:TUIError.failed, message: String.localized("live.error.failed"))))return}listManager.fetchLiveList(cursor: cursor, count: count) { responseCursor, responseLiveList inlet liveList = responseLiveList.filter { info inreturn LiveIdentityGenerator.shared.getIDType(info.roomInfo.roomId) == .live}promise(.success((responseCursor, liveList)))} onError: { error, message inpromise(.failure(InternalError(error: error, message: message)))}}.eraseToAnyPublisher()}
// 文件位置:iOS/TUILiveKit/Source/View/LiveRoom/View/Anchor/LivingView/Connection├── ConnectionManagerPanel.swift // 连线面板视图├── ConnectionUserCell.swift // 推荐列表、连线列表复用Cell视图样式└── ConnectionUserTableHeaderView.swift // 连线面板标题视图样式
//
文件位置:iOS/TUILiveKit/Source/View/LiveRoom/View/Common/Video/Component/RenderView.swift
class RenderView: UIView {...func constructViewHierarchy() {// 视图层级构建}func activateConstraints() {// 视图layout布局}}
ConnectionService
实现的,您可通过 store.serviceCenter.connectionService
获取到连线管理类对象,进而调用连线相关 API函数,实现连线功能。以主播 A,B连线为例,具体交互时序可参考下图。requestConnection
发起连线,在参数 roomIdList 中传入主播 B 房间 id。// 文件位置:iOS/TUILiveKit/Source/Service/ConnectionService.swiftfunc requestConnection(roomIdList:[String], extensionInfo: String) -> AnyPublisher<[String:TUIConnectionCode], InternalError> {return Future<[String:TUIConnectionCode], InternalError> {[weak self] promise inguard let self = self else { return }connectionManager.requestConnection(roomIdList: roomIdList, timeout: 10, extensionInfo: extensionInfo) { result invar connectionResult:[String:TUIConnectionCode] = [:]result.forEach { (key: String, value: NSNumber) inconnectionResult[key] = TUIConnectionCode(rawValue: value.intValue) ?? .unknown}promise(.success(connectionResult))} onError: { err, message inlet error = InternalError(error: err, message: message)promise(.failure(error))}}.eraseToAnyPublisher()}
onConnectionRequestAccept
接收请求同意回调。onConnectionRequestReceived
接收连线请求回调。// 文件位置:iOS/TUILiveKit/Source/Service/EngineServiceCenter.swiftfunc onConnectionRequestReceived(inviter: TUIConnectionUser, inviteeList: [TUIConnectionUser], extensionInfo: String) {guard let store = self.store else { return }store.dispatch(action: ConnectionActions.onConnectionRequestReceived(payload: (inviter, inviteeList, extensionInfo)))}
accept
接受连线请求。// 文件位置:iOS/TUILiveKit/Source/Service/ConnectionService.swiftfunc accept(roomId:String) -> AnyPublisher<Void, InternalError>{return Future<Void, InternalError> {[weak self] promise inguard let self = self else { return }connectionManager.acceptConnection(roomId) {promise(.success(()))} onError: { err, message inlet error = InternalError(error: err, message: message)promise(.failure(error))}}.eraseToAnyPublisher()}
onConnectionUserListChanged
接收连线列表变化。// 文件位置:iOS/TUILiveKit/Source/Service/EngineServiceCenter.swiftfunc onConnectionUserListChanged(connectedList: [TUIConnectionUser], joinedList: [TUIConnectionUser], leavedList: [TUIConnectionUser]) {guard let store = self.store else { return }store.dispatch(action: ConnectionActions.onConnectionUserListChanged(payload: connectedList))}
disconnect
退出连线。// 文件位置:iOS/TUILiveKit/Source/Service/ConnectionService.swiftfunc disconnect() -> AnyPublisher<Void, InternalError>{return Future<Void, InternalError> {[weak self] promise inguard let self = self else { return }connectionManager.disconnect {promise(.success(()))} onError: { err, message inlet error = InternalError(error: err, message: message)promise(.failure(error))}}.eraseToAnyPublisher()}
onConnectionUserListChanged
回调,收到接收连线列表发生变化通知。 // 文件位置:iOS/TUILiveKit/Source/Service/EngineServiceCenter.swiftfunc onConnectionUserListChanged(connectedList: [TUIConnectionUser], joinedList: [TUIConnectionUser], leavedList: [TUIConnectionUser]) {guard let store = self.store else { return }store.dispatch(action: ConnectionActions.onConnectionUserListChanged(payload: connectedList))}
本页内容是否解决了您的问题?