This document mainly introduces how to use the LiveStreamCore
module's LiveCoreView
to implement Mic Connect.
LiveCoreView
supports the following capabilities for Mic Connect:
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 AudienceConnectionController: 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)
}
}
public class AudienceConnectionActivity 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);
}
@Override
protected void onDestroy() {
super.onDestroy();
liveCoreView.unregisterConnectionObserver(this);
}
}
Step 2: Audience Connection
Request to connect
When you want to connect with someone via mic, call the requestIntraRoomConnection
API with three parameters: the userId of the person to connect with, the timeout duration, and whether to turn on the camera.
let userId = "100012"
let timeout = 30
let openCamera = true
self.liveCoreView.requestIntraRoomConnection(userId: userId, timeOut: timeout, openCamera: true) {
} onError: { code, message in
}
String userId = "anchorUserId";
int timeout = 30;
boolean openCamera = true;
liveCoreView.requestIntraRoomConnection(userId, timeout, true, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
When you are the invitee for a connection, you will receive the onUserConnectionRequest
callback. You can call the respondIntraRoomConnection
API to accept or reject the connection.
func onUserConnectionRequest(inviterUser: TUIUserInfo) {
let isAccepted = true
self.liveCoreView.respondIntraRoomConnection
(
userId
:
inviterUser
.
userId
,
isAccepted
:
isAccepted)
{
}
onError
:
{
code
,
message
in
}
}
@Override
public void onUserConnectionRequest(TUIRoomDefine.UserInfo userInfo) {
boolean isAccepted = true;
liveCoreView.respondIntraRoomConnection(userInfo.userId, isAccepted, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
}
Audience terminate connection
If you do not want to connect with the host, call the disconnectUser
API to disconnect.
self.liveCoreView.terminateIntraRoomConnection()
liveCoreView.terminateIntraRoomConnection();
Host terminate connection
If you want to interrupt the connection with an audience member, call the disconnectUser
API and pass in the corresponding user's userId.
let targetUserId = "100010"
self.liveCoreView.disconnectUser(userId: targetUserId) {
} onError: { code, message in
}
String targetUserId = "100010";
liveCoreView.disconnectUser(targetUserId, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
Was this page helpful?