two-way connection | multi-way connection |
| |
Click Co-Host Button | Select Host for Co-Host | Co-Host successful | Disconnect |
| | | |
Receives the invitation | Accepts the invitation |
| |
getRecommendedList
to retrieve the live stream list. If you need to use a custom recommended list, you can refer to the example code below to replace the corresponding recommended list data.// File Path: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()}
// File Path:iOS/TUILiveKit/Source/View/LiveRoom/View/Anchor/LivingView/Connection├── ConnectionManagerPanel.swift // Co-host panel view├── ConnectionUserCell.swift // Recommendation list and connection list reuse Cell view style└── ConnectionUserTableHeaderView.swift // Co-host panel header view style
//
File Path:iOS/TUILiveKit/Source/View/LiveRoom/View/Common/Video/Component/RenderView.swift
class RenderView: UIView {...func constructViewHierarchy() {// View hierarchy construction}func activateConstraints() {//View layout}}
ConnectionService
. You can get the connection management class through store.serviceCenter.connectionService
, and then call the connection-related APIs. Taking the co-host between anchors A and B as an example, the specific interaction sequence can be found in the figure below.requestConnection
and passing in the room id of anchor B to be connected in the parameter roomIdList.// File Path: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
.// File Path: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
.// File Path: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
callback and are notified of changes to the co-host list.// File Path: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
to exit the co-host.// File Path: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
callback and are notified of changes to the co-host list. // File Path: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))}
Was this page helpful?