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 RTCRoomEngine
let roomIdList = ["live_100002"]
let timeout = 30
let extensionInfo = ""
let connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()
connectionManager.requestConnection(roomIdList: roomIdList,
timeout: TimeInterval(timeout),
extensionInfo: extensionInfo) { connectionResults in
} onError: { code, message in
}
List<String> roomIdList = Collections.singletonList("live_100002");
int timeout = 30;
String extensionInfo = "";
TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();
connectionManager.requestConnection(roomIdList, timeout, extensionInfo, new TUILiveConnectionManager.ConnectionRequestCallback() {
@Override
public void onSuccess(Map<String, TUILiveConnectionManager.ConnectionCode> resultMap) {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
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) {
connectionManager.acceptConnection(inviter.roomId) {
} onError: { code, message in
}
connectionManager.rejectConnection(inviter.roomId) {
} onError: { code, message in
}
}
public void onConnectionRequestReceived(TUILiveConnectionManager.ConnectionUser inviter,
List<TUILiveConnectionManager.ConnectionUser> inviteeList,
String extensionInfo) {
connectionManager.acceptConnection(inviter.roomId, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
connectionManager.rejectConnection(inviter.roomId, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
}
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"]
let connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()
connectionManager.cancelConnectionRequest(roomIdList: roomIdList) {
} onError: { code, message in
}
List<String> roomIdList = Collections.singletonList("live_100002");
TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();
connectionManager.cancelConnectionRequest(roomIdList, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
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 RTCRoomEngine
let connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager()
connectionManager.disconnect {
} onError: { code, message in
}
TUILiveConnectionManager connectionManager = TUIRoomEngine.sharedInstance().getLiveConnectionManager();
connectionManager.disconnect(new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
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 RTCRoomEngine
class CoHostController: NSObject, TUILiveConnectionObserver {
override init() {
super.init()
TUIRoomEngine.sharedInstance().getLiveConnectionManager().addObserver(self)
}
deinit {
TUIRoomEngine.sharedInstance().getLiveConnectionManager().removeObserver(self)
}
func onConnectionUserListChanged(connectedList: [TUIConnectionUser],
joinedList: [TUIConnectionUser],
leavedList: [TUIConnectionUser]) {
}
func onConnectionRequestReceived(inviter: TUIConnectionUser,
inviteeList: [TUIConnectionUser],
extensionInfo: String) {
}
func onConnectionRequestCancelled(inviter: TUIConnectionUser) {
}
func onConnectionRequestAccept(invitee: TUIConnectionUser) {
}
func onConnectionRequestReject(invitee: TUIConnectionUser) {
}
func onConnectionRequestTimeout(inviter: TUIConnectionUser, invitee: TUIConnectionUser) {
}
}
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);
}
@Override
public void onConnectionUserListChanged(List<TUILiveConnectionManager.ConnectionUser> connectedList,
List<TUILiveConnectionManager.ConnectionUser> joinedList,
List<TUILiveConnectionManager.ConnectionUser> leavedList) {
}
@Override
public void onConnectionRequestReceived(TUILiveConnectionManager.ConnectionUser inviter,
List<TUILiveConnectionManager.ConnectionUser> inviteeList,
String extensionInfo) {
}
@Override
public void onConnectionRequestCancelled(TUILiveConnectionManager.ConnectionUser inviter) {
}
@Override
public void onConnectionRequestAccept(TUILiveConnectionManager.ConnectionUser invitee) {
}
@Override
public void onConnectionRequestReject(TUILiveConnectionManager.ConnectionUser invitee) {
}
@Override
public void onConnectionRequestTimeout(TUILiveConnectionManager.ConnectionUser inviter,
TUILiveConnectionManager.ConnectionUser invitee) {
}
}
Was this page helpful?