Anchor Connection
this document primarily introduces how to use
RTC Room Engine
SDK to implement anchor connection functionality.Prerequisites
Before using the
RTC RoomEngine
SDK, you need to call the Log In SDK first so that subsequent features can be used normally.User Guide
Note:
When using the connection feature, ensure you have started broadcasting.
Initiating a Connection Request
First, you need to obtain the
TUILiveConnectionManager
plug-in through the getLiveConnectionManager
API.Then, use the
requestConnection
API of the TUILiveConnectionManager
plug-in to implement the feature, inputting three parameters: room Id of the host to be invited for connection, timeout duration, and extended information.Take inviting the anchor in live streaming room with Id live_100002 for connection as an example:
import RTCRoomEnginelet roomIdList = ["live_100002"] //Replace it with the room ID where the anchor you want to invite for connection resideslet timeout = 30 // Replace this with the timeout period for your request to speak, in seconds. If set to 0, the SDK will not perform timeout detection or avoid triggering a timeout callback.let extensionInfo = ""let connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()connectionManager.requestConnection(roomIdList: roomIdList,timeout: TimeInterval(timeout),extensionInfo: extensionInfo) { connectionResults in// Connection request successful} onError: { code, message in// Connection request failed}
List<String> roomIdList = Collections.singletonList("live_100002"); // Replace it with the room ID where the anchor you want to invite for connection residesint timeout = 30; // Replace this with the timeout period for your request to speak, in seconds. If set to 0, the SDK will not perform timeout detection or trigger a timeout callback.String extensionInfo = "";TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();connectionManager.requestConnection(roomIdList, timeout, extensionInfo, new TUILiveConnectionManager.ConnectionRequestCallback() {@Overridepublic void onSuccess(Map<String, TUILiveConnectionManager.ConnectionCode> resultMap) {// Connection request successful}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Connection request failed}});
If you become an observer of the
TUILiveConnectionManager
SDK through the addObserver
API, you will receive the onConnectionRequestReceived
callback when someone applies to connect with you. You can accept or reject the request via the acceptConnection
/ rejectConnection
APIs.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}// Deny the requestconnectionManager.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}});// Deny the requestconnectionManager.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}});}
Abandon Connection Request
First, you need to obtain the
TUILiveConnectionManager
plug-in through the getLiveConnectionManager
API.Then, use the
cancelConnectionRequest
API of the TUILiveConnectionManager
plug-in to implement the feature, inputting the room Id of the host who abandons the connection invitation.Take abandoning the connection request with the host in live streaming room with Id live_100002 as an example:
let roomIdList = ["live_100002"] //Replace it with the room ID where the anchor you want to abandon the connection invitation resideslet 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 where the anchor you want to abandon the connection invitation residesTUILiveConnectionManager 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}});
Interrupt Connection
First, you need to obtain the
TUILiveConnectionManager
plug-in through the getLiveConnectionManager
API.Then use the
disconnect
API of the TUILiveConnectionManager
plug-in to interrupt the ongoing connection.import RTCRoomEnginelet connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()connectionManager.disconnect {// Successfully interrupted the connection} onError: { code, message in// Failed to interrupt the connection}
TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();connectionManager.disconnect(new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Successfully interrupted the connection}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to interrupt the connection}});
Listening Callback
You can become an observer of
TUILiveConnectionManager
by calling addObserver
to listen to callbacks related to the connection.Take
CoHostController
becoming an observer as an example:import RTCRoomEngineclass CoHostController: NSObject, TUILiveConnectionObserver {override init() {super.init()TUIRoomEngine.sharedInstance().getLiveConnectionManager().addObserver(self)}deinit {TUIRoomEngine.sharedInstance().getLiveConnectionManager().removeObserver(self)}// Trigger when the connected user list changesfunc onConnectionUserListChanged(connectedList: [TUIConnectionUser],joinedList: [TUIConnectionUser],leavedList: [TUIConnectionUser]) {// The connection list has changed. The latest connection list: connectedList, the list of users in new connections: joinedList, the list of users in interrupted connections: leavedList}// Triggered when a connection invitation is receivedfunc onConnectionRequestReceived(inviter: TUIConnectionUser,inviteeList: [TUIConnectionUser],extensionInfo: String) {// A connection invitation has been received from inviter.userName}// Triggered when a connection invitation is canceledfunc onConnectionRequestCancelled(inviter: TUIConnectionUser) {// The connection invitation from inviter.userName has been cancelled.}// Triggered when a connection invitation is acceptedfunc onConnectionRequestAccept(invitee: TUIConnectionUser) {// Your connection invitation to invitee.userName has been accepted.}// Triggered when a connection invitation is rejectedfunc onConnectionRequestReject(invitee: TUIConnectionUser) {// Your connection invitation to invitee.userName has been rejected.}// Triggered when a connection invitation times outfunc onConnectionRequestTimeout(inviter: TUIConnectionUser, invitee: TUIConnectionUser) {// The connection invitation from inviter.userName has timed out.}}
You can become an observer of
TUILiveConnectionManager
by calling addObserver
to listen to callbacks related to the connection.Take
CoHostObserver
becoming an observer as an example:class CoHostObserver extends TUILiveConnectionManager.Observer {CoHostObserver() {TUIRoomEngine.sharedInstance().getLiveConnectionManager().addObserver(this);}// Trigger when the connected user list changes@Overridepublic void onConnectionUserListChanged(List<TUILiveConnectionManager.ConnectionUser> connectedList,List<TUILiveConnectionManager.ConnectionUser> joinedList,List<TUILiveConnectionManager.ConnectionUser> leavedList) {// The connection list has changed. The latest connection list: connectedList, the list of users in new connections: joinedList, the list of users in interrupted connections: leavedList}// Triggered when a connection invitation is received@Overridepublic void onConnectionRequestReceived(TUILiveConnectionManager.ConnectionUser inviter,List<TUILiveConnectionManager.ConnectionUser> inviteeList,String extensionInfo) {// A connection invitation has been received from inviter.userName}// Triggered when a connection invitation is canceled@Overridepublic void onConnectionRequestCancelled(TUILiveConnectionManager.ConnectionUser inviter) {// The connection invitation from inviter.userName has been cancelled.}// Triggered when a connection invitation is accepted@Overridepublic void onConnectionRequestAccept(TUILiveConnectionManager.ConnectionUser invitee) {// Your connection invitation to invitee.userName has been accepted.}// Triggered when a connection invitation is rejected@Overridepublic void onConnectionRequestReject(TUILiveConnectionManager.ConnectionUser invitee) {// Your connection invitation to invitee.userName has been rejected.}// Triggered when a connection invitation times out@Overridepublic void onConnectionRequestTimeout(TUILiveConnectionManager.ConnectionUser inviter,TUILiveConnectionManager.ConnectionUser invitee) {// The connection invitation from inviter.userName has timed out.}}