Audience Connection
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.importLiveStreamCore
import
RTCRoomEngine
class AudienceConnectionController: UIViewController {private let liveCoreView: LiveCoreView = {let view = LiveCoreView()return view}()override func viewDidLoad() {super.viewDidLoad()self.liveCoreView.registerConnectionObserver(observer: self)// Add liveCoreView to the view and set layout constraints}deinit {self.liveCoreView.unregisterConnectionObserver(observer: self)}}
public class AudienceConnectionActivity extends AppCompatActivity implements LiveCoreViewDefine.ConnectionObserver {private LiveCoreView liveCoreView;@Overrideprotected 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);}@Overrideprotected 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" // Please replace this with the userId of the user you want to initiate Mic Connect with. If you pass an empty string, it will default to connecting with the host.let 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 callbackslet openCamera = true // When you want to initiate a video call, set openCamera to true. For an audio call, set it to false.self.liveCoreView.requestIntraRoomConnection(userId: userId, timeOut: timeout, openCamera: true) {// Successfully sent request to connect via mic} onError: { code, message in// Failed to send request to connect via mic}
String userId = "anchorUserId"; // Replace this with the userId of the person you want to connect with via micint 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 callbacksboolean openCamera = true; // When you want to initiate a video call, set openCamera to true. For an audio call, set it to false.liveCoreView.requestIntraRoomConnection(userId, timeout, true, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Successfully sent request to connect via mic}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to send request to connect via mic}});
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 // true: accept connection, false: reject connectionself.liveCoreView.respondIntraRoomConnection
(
userId
:
inviterUser
.
userId
,
isAccepted
:
isAccepted
)
{
// Response succeeded
}
onError
:
{
code
,
message
in
// Response failed
}
}
@Overridepublic void onUserConnectionRequest(TUIRoomDefine.UserInfo userInfo) {boolean isAccepted = true; // true: accept connection, false: reject connectionliveCoreView.respondIntraRoomConnection(userInfo.userId, isAccepted, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Response succeeded
}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Response failed
}});}
Audience terminate connection
If you do not want to connect with the host, call the
terminateIntraRoomConnection
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" // Replace this with the userId of the audience member you want to disconnecself.liveCoreView.disconnectUser(userId: targetUserId) {// Successfully disconnected} onError: { code, message in// Failed to disconnect}
String targetUserId = "100010"; // Replace this with the userId of the audience member you want to disconnect fromliveCoreView.disconnectUser(targetUserId, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Successfully disconnected}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to disconnect}});