tencent cloud

Feedback

Anchor Connection

Last updated: 2025-01-09 16:01:44
    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:
    iOS
    Android
    import RTCRoomEngine
    
    let 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 callbacks
    String extensionInfo = "";
    TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();
    connectionManager.requestConnection(roomIdList, timeout, extensionInfo, new TUILiveConnectionManager.ConnectionRequestCallback() {
    @Override
    public void onSuccess(Map<String, TUILiveConnectionManager.ConnectionCode> resultMap) {
    // Successfully initiated connection request
    }
    @Override
    public 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.
    iOS
    Android
    func onConnectionRequestReceived(inviter: TUIConnectionUser,
    inviteeList: [TUIConnectionUser],
    extensionInfo: String) {
    // Accept the request
    connectionManager.acceptConnection(inviter.roomId) {
    // Connection request accepted successfully
    } onError: { code, message in
    // Connection request acceptance failed
    }
    
    // Request rejected
    connectionManager.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 request
    connectionManager.acceptConnection(inviter.roomId, new TUIRoomDefine.ActionCallback() {
    @Override
    public void onSuccess() {
    // Connection request accepted successfully
    }
    @Override
    public void onError(TUICommonDefine.Error error, String message) {
    // Connection request acceptance failed
    }
    });
    
    
    // Request rejected
    connectionManager.rejectConnection(inviter.roomId, new TUIRoomDefine.ActionCallback() {
    @Override
    public void onSuccess() {
    // Connection request rejected successfully
    }
    @Override
    public 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:
    iOS
    Android
    let roomIdList = ["live_100002"] // Please replace it with the room ID of the host whose connection invitation you want to cancel
    let 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() {
    @Override
    public void onSuccess() {
    // Connection invitation abandoned successfully
    }
    @Override
    public 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.
    iOS
    Android
    import RTCRoomEngine
    
    let 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() {
    @Override
    public void onSuccess() {
    // Connection terminated successfully
    }
    
    @Override
    public void onError(TUICommonDefine.Error error, String message) {
    // Connection termination failed
    }
    });

    Listening to Callbacks

    iOS
    Android
    You can become an observer of TUILiveConnectionManager by calling addObserver to listen for connection-related callbacks.
    Using CoHostController as an observer example:
    import RTCRoomEngine
    
    class CoHostController: NSObject, TUILiveConnectionObserver {
    override init() {
    super.init()
    TUIRoomEngine.sharedInstance().getLiveConnectionManager().addObserver(self)
    }
    deinit {
    TUIRoomEngine.sharedInstance().getLiveConnectionManager().removeObserver(self)
    }
    // Triggered when the connection user list changes
    func 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 received
    func onConnectionRequestReceived(inviter: TUIConnectionUser,
    inviteeList: [TUIConnectionUser],
    extensionInfo: String) {
    // Received a connection invitation from inviter.userName
    }
    // Triggered when the connection invitation is canceled
    func onConnectionRequestCancelled(inviter: TUIConnectionUser) {
    // The connection invitation from inviter.userName was canceled
    }
    // Triggered when the connection invitation is accepted
    func onConnectionRequestAccept(invitee: TUIConnectionUser) {
    // Your connection invitation to invitee.userName was accepted
    }
    // Triggered when the connection invitation is rejected
    func onConnectionRequestReject(invitee: TUIConnectionUser) {
    // Your connection invitation to invitee.userName was rejected
    }
    // Triggered when the connection invitation times out
    func 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
    @Override
    public 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
    @Override
    public 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
    @Override
    public void onConnectionRequestCancelled(TUILiveConnectionManager.ConnectionUser inviter) {
    // The connection invitation from inviter.userName was canceled
    }
    // Triggered when the connection invitation is accepted
    @Override
    public void onConnectionRequestAccept(TUILiveConnectionManager.ConnectionUser invitee) {
    // Your connection invitation to invitee.userName was accepted
    }
    // Triggered when the connection invitation is rejected
    @Override
    public void onConnectionRequestReject(TUILiveConnectionManager.ConnectionUser invitee) {
    // Your connection invitation to invitee.userName was rejected
    }
    // Triggered when the connection invitation times out
    @Override
    public void onConnectionRequestTimeout(TUILiveConnectionManager.ConnectionUser inviter,
    TUILiveConnectionManager.ConnectionUser invitee) {
    // The connection invitation from inviter.userName timed out
    }
    }
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support