This document mainly introduces how to use the LiveStreamCore
module's LiveCoreView
to achieve anchor connection.
Prerequisites
Before using LiveStreamCore
, you need to integrate and log in to LiveStreamCore to ensure the subsequent features work properly. Usage guide
Step 1: Adding LiveCoreView to the View
You need to first import the LiveStreamCore
module, then create a LiveCoreView
view object and add it to your view.
import LiveStreamCore
import
RTCRoomEngine
class AnchorConnectionController: UIViewController {
private let liveCoreView: LiveCoreView = {
let view = LiveCoreView()
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.liveCoreView.registerConnectionObserver(observer: self)
}
deinit {
self.liveCoreView.unregisterConnectionObserver(observer: self)
}
}
import com.trtc.uikit.livekit.livestreamcore.LiveCoreView;
import com.trtc.uikit.livekit.livestreamcore.LiveCoreViewDefine;
public class AnchorConnectionActivity extends AppCompatActivity implements LiveCoreViewDefine.ConnectionObserver {
private LiveCoreView liveCoreView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
liveCoreView = new LiveCoreView(this);
addContentView(liveCoreView,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
liveCoreView.registerConnectionObserver(this);
}
}
Step 2: Anchor Connection
Initiating Connection
When you want to initiate a connection with an anchor in another room, you can call the requestCrossRoomConnection
API, passing in two parameters: the room ID of the anchor's room and the timeout duration.
let targetRoomId = "live_100011"
let timeout = 30
self.liveCoreView.requestCrossRoomConnection(roomId: targetRoomId, timeOut: timeout) {
} onError: { code, message
}
String targetRoomId = "live_100011";
int timeout = 30;
liveCoreView.requestCrossRoomConnection(targetRoomId, timeout, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
When you receive a connection invitation, you will get the onCrossRoomConnectionRequest
callback. You can accept or reject the connection request via the respondToCrossRoomConnection
API.
func onCrossRoomConnectionRequest(hostUser: TUIConnectionUser) {
self.liveCoreView.respondToCrossRoomConnection
(
roomId: hostUser.roomId, isAccepted: true)
{
}
onError
:
{
code
,
message
in
}
}
@Override
public void onCrossRoomConnectionRequest(TUILiveConnectionManager.ConnectionUser connectionUser) {
boolean isAccepted = true;
liveCoreView.respondToCrossRoomConnection(connectionUser.userId, isAccepted, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
}
Terminating the Connection
When you want to terminate the current connection, you can call the terminateCrossRoomConnection
API.
self.liveCoreView.terminateCrossRoomConnection()
liveCoreView.terminateCrossRoomConnection();
Was this page helpful?