Anchor Connection
This document mainly introduces how to use the
RTC Room Engine
SDK to implement the host connection feature.Prerequisites
Before using the
RTC RoomEngine
SDK, you need to call the SDK login to ensure the subsequent features work properly.User Guide
Note:
When using the connection feature, please ensure that you have started broadcasting.
Initiate a connection request
You first need to obtain the
TUILiveConnectionManager
plugin through the getLiveConnectionManager
API.Then use the
TUILiveConnectionManager
plugin's requestConnection
API to implement this feature, passing in three parameters: the room ID of the host to be invited, the timeout duration, and the extended information.For example, to invite the host of the live room with ID live_100002:
import RTCRoomEnginelet roomIdList = ["live_100002"] // Replace it with the room ID of the host you want to invite for connection.let timeout = 30 // Please replace this with the timeout duration for your speaking request, in seconds. If set to 0, the SDK will not perform timeout detection or trigger timeout callbacks.let extensionInfo = ""let connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()connectionManager.requestConnection(roomIdList: roomIdList,timeout: TimeInterval(timeout),extensionInfo: extensionInfo) { connectionResults in// Successfully initiated connection request} onError: { code, message in// Failed to initiate connection request}
List<String> roomIdList = Collections.singletonList("live_100002"); // Replace it with the room ID of the host you want to invite for connection.int timeout = 30; // Replace this with the timeout duration for requesting to speak, in seconds. If set to 0, the SDK will not perform timeout detection or trigger timeout callbacksString extensionInfo = "";TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();connectionManager.requestConnection(roomIdList, timeout, extensionInfo, new TUILiveConnectionManager.ConnectionRequestCallback() {@Overridepublic void onSuccess(Map<String, TUILiveConnectionManager.ConnectionCode> resultMap) {// Successfully initiated connection request}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to initiate connection request}});
If you become an observer of the
addObserver
API in the TUILiveConnectionManager
SDK, you will receive the onConnectionRequestReceived
callback when someone requests to connect with you. You can accept or reject the request through the acceptConnection
/ rejectConnection
API.func onConnectionRequestReceived(inviter: TUIConnectionUser,inviteeList: [TUIConnectionUser],extensionInfo: String) {// Accept the requestconnectionManager.acceptConnection(inviter.roomId) {// Connection request accepted successfully} onError: { code, message in// Connection request acceptance failed}// Request rejectedconnectionManager.rejectConnection(inviter.roomId) {// Connection request rejected successfully} onError: { code, message in// Connection request rejection failed}}
public void onConnectionRequestReceived(TUILiveConnectionManager.ConnectionUser inviter,List<TUILiveConnectionManager.ConnectionUser> inviteeList,String extensionInfo) {// Accept the requestconnectionManager.acceptConnection(inviter.roomId, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Connection request accepted successfully}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Connection request acceptance failed}});// Request rejectedconnectionManager.rejectConnection(inviter.roomId, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Connection request rejected successfully}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Connection request rejection failed}});}
Canceling a Connection Request
You first need to obtain the
TUILiveConnectionManager
plugin through the getLiveConnectionManager
API.Then use the
TUILiveConnectionManager
plugin's cancelConnectionRequest
API to implement this feature, passing in the room ID of the host whose connection invitation is to be canceled.For example, to cancel the connection request to the host of the live room with ID live_100002:
let roomIdList = ["live_100002"] // Please replace it with the room ID of the host whose connection invitation you want to cancellet connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()connectionManager.cancelConnectionRequest(roomIdList: roomIdList) {// Connection invitation abandoned successfully} onError: { code, message in// Connection invitation abandonment failed}
List<String> roomIdList = Collections.singletonList("live_100002"); // Replace it with the room ID of the host you want to abandon the connection invitation.TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();connectionManager.cancelConnectionRequest(roomIdList, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Connection invitation abandoned successfully}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Connection invitation abandonment failed}});
Terminating the Connection
You first need to obtain the
TUILiveConnectionManager
plugin through the getLiveConnectionManager
API.Then use the
TUILiveConnectionManager
plugin's disconnect
API to terminate the ongoing connection.import RTCRoomEnginelet connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()connectionManager.disconnect {// Connection terminated successfully} onError: { code, message in// Connection termination failed}
TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();connectionManager.disconnect(new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Connection terminated successfully}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Connection termination failed}});
Listening to Callbacks
You can become an observer of
TUILiveConnectionManager
by calling addObserver
to listen for connection-related callbacks.Using
CoHostController
as an observer example:import RTCRoomEngineclass CoHostController: NSObject, TUILiveConnectionObserver {override init() {super.init()TUIRoomEngine.sharedInstance().getLiveConnectionManager().addObserver(self)}deinit {TUIRoomEngine.sharedInstance().getLiveConnectionManager().removeObserver(self)}// Triggered when the connection user list changesfunc onConnectionUserListChanged(connectedList: [TUIConnectionUser],joinedList: [TUIConnectionUser],leavedList: [TUIConnectionUser]) {// Connection list changed, latest connection list: connectedList, newly connected users: joinedList, newly disconnected users: leavedList}// Triggered when a connection invitation is receivedfunc onConnectionRequestReceived(inviter: TUIConnectionUser,inviteeList: [TUIConnectionUser],extensionInfo: String) {// Received a connection invitation from inviter.userName}// Triggered when the connection invitation is canceledfunc onConnectionRequestCancelled(inviter: TUIConnectionUser) {// The connection invitation from inviter.userName was canceled}// Triggered when the connection invitation is acceptedfunc onConnectionRequestAccept(invitee: TUIConnectionUser) {// Your connection invitation to invitee.userName was accepted}// Triggered when the connection invitation is rejectedfunc onConnectionRequestReject(invitee: TUIConnectionUser) {// Your connection invitation to invitee.userName was rejected}// Triggered when the connection invitation times outfunc onConnectionRequestTimeout(inviter: TUIConnectionUser, invitee: TUIConnectionUser) {// The connection invitation from inviter.userName timed out}}
You can become an observer of
TUILiveConnectionManager
by calling addObserver
to listen for connection-related callbacks.Using
CoHostObserver
as an observer example:class CoHostObserver extends TUILiveConnectionManager.Observer {CoHostObserver() {TUIRoomEngine.sharedInstance().getLiveConnectionManager().addObserver(this);}// Triggered when the connection user list changes@Overridepublic void onConnectionUserListChanged(List<TUILiveConnectionManager.ConnectionUser> connectedList,List<TUILiveConnectionManager.ConnectionUser> joinedList,List<TUILiveConnectionManager.ConnectionUser> leavedList) {// Connection list changed, latest connection list: connectedList, newly connected users: joinedList, newly disconnected users: leavedList}// Triggered when a connection invitation is received@Overridepublic void onConnectionRequestReceived(TUILiveConnectionManager.ConnectionUser inviter,List<TUILiveConnectionManager.ConnectionUser> inviteeList,String extensionInfo) {// Received a connection invitation from inviter.userName}// Triggered when the connection invitation is canceled@Overridepublic void onConnectionRequestCancelled(TUILiveConnectionManager.ConnectionUser inviter) {// The connection invitation from inviter.userName was canceled}// Triggered when the connection invitation is accepted@Overridepublic void onConnectionRequestAccept(TUILiveConnectionManager.ConnectionUser invitee) {// Your connection invitation to invitee.userName was accepted}// Triggered when the connection invitation is rejected@Overridepublic void onConnectionRequestReject(TUILiveConnectionManager.ConnectionUser invitee) {// Your connection invitation to invitee.userName was rejected}// Triggered when the connection invitation times out@Overridepublic void onConnectionRequestTimeout(TUILiveConnectionManager.ConnectionUser inviter,TUILiveConnectionManager.ConnectionUser invitee) {// The connection invitation from inviter.userName timed out}}