• 製品
  • 価格
  • リソース
  • サポート
このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

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:
iOS
Android
import RTCRoomEngine

let roomIdList = ["live_100002"] //Replace it with the room ID where the anchor you want to invite for connection resides
let 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 resides
int 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() {
@Override
public void onSuccess(Map<String, TUILiveConnectionManager.ConnectionCode> resultMap) {
// Connection request successful
}
@Override
public 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.
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
}

// Deny the request
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
}
});


// Deny the request
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
}
});
}

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:
iOS
Android
let roomIdList = ["live_100002"] //Replace it with the room ID where the anchor you want to abandon the connection invitation resides
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 where the anchor you want to abandon the connection invitation resides

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
}
});

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.
iOS
Android
import RTCRoomEngine

let 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() {
@Override
public void onSuccess() {
// Successfully interrupted the connection
}

@Override
public void onError(TUICommonDefine.Error error, String message) {
// Failed to interrupt the connection
}
});

Listening Callback

iOS
Android
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 RTCRoomEngine

class CoHostController: NSObject, TUILiveConnectionObserver {
override init() {
super.init()
TUIRoomEngine.sharedInstance().getLiveConnectionManager().addObserver(self)
}
deinit {
TUIRoomEngine.sharedInstance().getLiveConnectionManager().removeObserver(self)
}
// Trigger when the connected user list changes
func 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 received
func onConnectionRequestReceived(inviter: TUIConnectionUser,
inviteeList: [TUIConnectionUser],
extensionInfo: String) {
// A connection invitation has been received from inviter.userName
}
// Triggered when a connection invitation is canceled
func onConnectionRequestCancelled(inviter: TUIConnectionUser) {
// The connection invitation from inviter.userName has been cancelled.
}
// Triggered when a connection invitation is accepted
func onConnectionRequestAccept(invitee: TUIConnectionUser) {
// Your connection invitation to invitee.userName has been accepted.
}
// Triggered when a connection invitation is rejected
func onConnectionRequestReject(invitee: TUIConnectionUser) {
// Your connection invitation to invitee.userName has been rejected.
}
// Triggered when a connection invitation times out
func 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
@Override
public 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
@Override
public 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
@Override
public void onConnectionRequestCancelled(TUILiveConnectionManager.ConnectionUser inviter) {
// The connection invitation from inviter.userName has been cancelled.
}
// Triggered when a connection invitation is accepted
@Override
public void onConnectionRequestAccept(TUILiveConnectionManager.ConnectionUser invitee) {
// Your connection invitation to invitee.userName has been accepted.
}
// Triggered when a connection invitation is rejected
@Override
public void onConnectionRequestReject(TUILiveConnectionManager.ConnectionUser invitee) {
// Your connection invitation to invitee.userName has been rejected.
}
// Triggered when a connection invitation times out
@Override
public void onConnectionRequestTimeout(TUILiveConnectionManager.ConnectionUser inviter,
TUILiveConnectionManager.ConnectionUser invitee) {
// The connection invitation from inviter.userName has timed out.
}
}