• 서비스
  • 가격
  • 리소스
  • 기술지원
이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

Start a live

This document primarily introduces how to use the RoomEngine SDK to start a live stream.

Prerequisites

Before using the RoomEngine SDK, you need to log in to the SDK so that the feature functions normally.

Live Streaming Preparation

To ensure the live streaming effect meets expectations, it is advisable to complete the following preparations before going live: first, turn on the local camera preview to check if the composition is reasonable and ensure the lens angle is suitable; next, enable mic capture and adjust the proper pickup distance. After making all necessary preparations, start the live broadcast.

Start Camera Preview

1. First, create a local camera video preview control, add it to the interface, and complete the layout settings. Then call setLocalVideoView to set the local video preview control.
2. Then, please call the openLocalCamera API to start camera preview. This API requires the input of both parameters isFront and quality.
isFront Select front or rear camera. It is a boolean value: true opens the front camera, false opens the rear camera.
quality Video quality. This parameter is an enumeration of type TUIVideoQuality. We recommend you select quality720P or quality1080P.
Here is an example of opening the local camera preview with the front camera and 1080P video quality.
Swift
Java
Web
import RTCRoomEngine

// Step 1: Set the local video preview control
let videoView = UIView()
// ...Add videoView to your view and perform layout
TUIRoomEngine.sharedInstance().setLocalVideoView(view: videoView)

// Step 2: Open front camera preview
let isFrontCamera = true
let videoQuality: TUIVideoQuality = .quality1080P
TUIRoomEngine.sharedInstance().openLocalCamera(isFront: isFrontCamera, quality: videoQuality) {
// Open front camera successfully
} onError: { code, message in
// Open front camera failed
}
// Step 1: Set the local video preview control
TUIVideoView videoView = new TUIVideoView(context);
// ...Add videoView to your view and perform layout
TUIRoomEngine.sharedInstance().setLocalVideoView(videoView);

// Step 2: Open front camera preview
boolean isFrontCamera = true;
TUIRoomDefine.VideoQuality videoQuality = TUIRoomDefine.VideoQuality.Q_1080P;
TUIRoomEngine.sharedInstance().openLocalCamera(isFrontCamera, videoQuality, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
// Open front camera successfully
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
// Open front camera failed
}
});
TUIRoomEngine.once('ready', () => {
const roomEngine = TUIRoomEngine.getInstance();
await roomEngine.setLocalVideoView({
streamType: TUIVideoStreamType.kCameraStream,
view: 'preview-camera', // view is the id of the div element for playing local user stream
});
await roomEngine.updateVideoQuality({ quality: TUIVideoQuality.kVideoQuality_1080p });
await roomEngine.openLocalCamera();
});

Turning on Microphone Collection

Please call the openLocalMicrophone API to turn on microphone collection. This API requires the input of audio quality parameter quality. This parameter is an enumeration value of TUIAudioQuality data type. We recommend you select default mode. The following example shows how to start local microphone capture with default audio quality.
Swift
Java
Web
import RTCRoomEngine

// Open local microphone
let audioQuality: TUIAudioQuality = .default
TUIRoomEngine.sharedInstance().openLocalMicrophone(audioQuality) {
// Microphone turned on successfully
} onError: { code, message in
// Failed to open microphone
}
// Open local microphone
TUIRoomDefine.AudioQuality audioQuality = TUIRoomDefine.AudioQuality.DEFAULT;
TUIRoomEngine.sharedInstance().openLocalMicrophone(audioQuality, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
// Microphone turned on successfully
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
// Failed to open microphone
}
});
TUIRoomEngine.once('ready', () => {
const roomEngine = TUIRoomEngine.getInstance();
await roomEngine.updateAudioQuality({ quality: TUIAudioQuality.kAudioProfileDefault });
await roomEngine.openLocalMicrophone();
});

Enable UnlimitedRoom Parameter

In live streaming scenarios, we strongly recommend you enable the unlimitedRoom parameter. Advanced functions such as video preview, instant playback, and multi-template stream mixing require this parameter to be enabled to use.
Swift
Java
Web
var jsonObject = [String: Any]()
jsonObject["api"] = "enableUnlimitedRoom"
var params = [String: Any]()
params["enable"] = true
jsonObject["params"] = params
if let jsonData = try? JSONSerialization.data(withJSONObject: jsonObject, options: []),
let jsonString = String(data: jsonData, encoding: .utf8) {
TUIRoomEngine.callExperimentalAPI(jsonStr: jsonString)
}
JSONObject jsonObject = new JSONObject();
JSONObject params = new JSONObject();
try {
jsonObject.put("api", "enableUnlimitedRoom");
params.put("enable", true);
jsonObject.put("params", params);
TUIRoomEngine.sharedInstance().callExperimentalAPI(jsonObject.toString());
} catch (JSONException e) {
}
await TUIRoomEngine.callExperimentalAPI(JSON.stringify({
api: 'enableUnlimitedRoom',
params: {
enable: true,
},
}));
Note:
After enabling the unlimitedRoom parameter with the example code above, you still need to activate the TUILiveKit service for the changes to take effect. Refer to the activation instructions to complete the TUILiveKit service activation.

Creating a Live Streaming Room

Before going live, you need to fill in key parameters TUILiveInfo. Next, we'll provide detailed introduction:

Parameter: TUILiveInfo

TUILiveInfo is composed of many fields, but you only need to care about filling in the following fields:
Parameter Name
Field Description
Additional Notes
Data Type
Fill Example
roomId
room ID
Only allow a combination of uppercase and lowercase letters (a-z, A-Z), digits (0-9), underline, and hyphen.
This field is a required parameter when creating a room and supports up to 48 bytes.
String
"live_100001"
name
room name
room name of string type (same as roomId if left empty)
String
"live room"
isSeatEnabled
Whether microphone position control is enabled
Boolean type microphone position control enable flag.
Boolean value
true
seatMode
Microphone mode
This field takes effect only after enabling microphone position control.
Divided into freeToTake and applyToTake. In freeToTake mode, the audience can freely join the podium without applying. In applyToTake mode, the audience must obtain the room owner's approval to become a speaker.
Enumeration Value

TUISeatMode
.applyToTake
maxSeatCount
maximum number of microphone slots
The maximum number of microphone slots for the number type, indicating up to maxSeatCount people can be online simultaneously.
The maximum number of microphone slots matches the purchased package's cap on mic-on users.
Digits
10
isPublicVisible
Whether the live room is public
Set to true to display in the room list.
Boolean value
true
keepOwnerOnSeat
Host starts broadcasting and automatically becomes a speaker
If you are in a live streaming scenario, it is strongly recommended to set keepOwnerOnSeat to true, otherwise you must takeSeat to go live normally.
Boolean value
true
After preparing the room information parameter, you can call the TUILiveListManager plug-in's startLive API to start live streaming.
Swift
Java
Web
import RTCRoomEngine

let liveInfo = TUILiveInfo()
liveInfo.roomId = "video_100001" // Replace with your own room ID
liveInfo.name = "denny`s room" // Replace with your own room name
liveInfo.seatMode = .applyToTake // Normally in live broadcasting scenarios, the apply to take microphone mode is used. If your business allows the audience to take the microphone without applying, rewrite here as freeToTake.
liveInfo.maxSeatCount = 10 // Replace with the maximum number of microphone slots in the Live package you have purchased
liveInfo.isSeatEnabled = true // If you do not need microphone position control, set isSeatEnabled to false
liveInfo.isPublicVisible = true // Control whether the live room is public. It is recommended to set to true.
liveInfo.keepOwnerOnSeat = true // If you are in a live streaming scenario, it is strongly recommended to set to true, otherwise you must takeSeat to go live normally.

guard let liveListManager = TUIRoomEngine.sharedInstance().getExtension(extensionType: .liveListManager) as? TUILiveListManager else {
return
}
liveListManager.startLive(liveInfo: liveInfo, onSuccess: { liveInfo in
// Go live successfully
}, onError: { code, message in
// Failed to go live
})
TUILiveListManager.LiveInfo liveInfo = new TUILiveListManager.LiveInfo();
liveInfo.roomId = "video_100001"; // Replace with your own room ID
liveInfo.name = "denny`s room"; // Replace with your own room name
liveInfo.seatMode = TUIRoomDefine.SeatMode.APPLY_TO_TAKE; // Normally in live broadcasting scenarios, the apply to take microphone mode is used. If your business allows the audience to take the microphone without applying, rewrite here as freeToTake.
liveInfo.maxSeatCount = 10; // Replace with the maximum number of microphone slots in the Live package you have purchased
liveInfo.isSeatEnabled = true; // If you do not need microphone position control, set isSeatEnabled to false
liveInfo.isPublicVisible = true; // Control whether the live room is public. It is recommended to set to true.
liveInfo.keepOwnerOnSeat = true; // If you are in a live streaming scenario, it is strongly recommended to set to true, otherwise you must takeSeat to go live normally.

TUILiveListManager liveListManager = (TUILiveListManager)TUIRoomEngine.sharedInstance().getExtension(TUICommonDefine.ExtensionType.LIVE_LIST_MANAGER);
liveListManager.startLive(liveInfo, new TUILiveListManager.LiveInfoCallback() {
@Override
public void onSuccess(TUILiveListManager.LiveInfo liveInfo) {
// Go live successfully
}

@Override
public void onError(TUICommonDefine.Error error, String message) {
// Failed to go live
}
});
TUIRoomEngine.once('ready', () => {
const liveInfo = {
roomId: 'live_100001',
roomType: TUIRoomType.kLivingRoom,
name: 'live room',
isSeatEnabled: true,
seatMode: TUISeatMode.kApplyToTake,
maxSeatCount: 10,
keepOwnerOnSeat: true,
};

const roomEngine = TUIRoomEngine.getInstance();
const liveListManager = roomEngine.getLiveListManager();
const resultLiveInfo = await liveListManager.startLive(liveInfo);
console.log('Live stream started successfully, CDN stream address:', resultLiveInfo.cdnStreamUrl);
});

Ending Live Stream

If you want to end the live stream, please call the TUILiveListManager plug-in's stopLive API to end the live stream.
Swift
Java
Web
import RTCRoomEngine

guard let liveListManager = TUIRoomEngine.sharedInstance().getExtension(extensionType: .liveListManager) as? TUILiveListManager else {
return
}
liveListManager.stopLive { TUILiveStatisticsData in
// Live stream ended successfully
} onError: { code, message in
// Live stream ended unsuccessfully
}
TUILiveListManager liveListManager = (TUILiveListManager)TUIRoomEngine.sharedInstance().getExtension(TUICommonDefine.ExtensionType.LIVE_LIST_MANAGER);
liveListManager.stopLive(new TUILiveListManager.StopLiveCallback() {
@Override
public void onSuccess(TUILiveListManager.LiveStatisticsData statisticData) {
// Live stream ended successfully
}

@Override
public void onError(TUICommonDefine.Error error, String message) {
// Live stream ended unsuccessfully
}
});
TUIRoomEngine.once('ready', () => {
const roomEngine = TUIRoomEngine.getInstance();
const liveListManager = roomEngine.getLiveListManager();
const statistics = await liveListManager.stopLive();
console.log('Live stream ended, stats:', {
Audience count: statistics.totalViewers,
Gift count: statistics.totalGiftsSent,
Like count: statistics.totalLikesReceived
});
});