RTC Room Engine
SDK to implement the video broadcasting feature.RTC RoomEngine
SDK, you need to call the SDK login to ensure the subsequent features work properly.RTC Room Engine
to implement the core steps of starting a voice chat requires 4 steps: create and join a live room, go live on stage, enable media devices, and set up local preview. The following will provide a detailed introduction.TUIRoomInfo
. The following sections will provide a detailed introduction:TUIRoomInfo
consists of many fields, but usually, you only need to focus on filling in the following fields:Parameter Name | Field Description | Additional Notes | Data Type | Example |
roomId | Room ID | Only letters (a-z, A-Z), digits (0-9), underscores, and hyphens are allowed. This field is a required parameter when creating a room and can contain up to 48 bytes. | New Character String | "live_100001" |
name | Room Name | Room name of string type. (If not provided, it will be the same as roomId) | New Character String | "denny`s room" |
seatMode | Microphone Mode | This field is effective only when microphone control is enabled. It is divided into "freeToTake" and "applyToTake" modes. In freeToTake mode, audience members can take the microphone freely without applying. In applyToTake mode, audience members need the room owner's approval to take the microphone. | Enumeration Value | TUISeatMode.applyToTake |
maxSeatCount | Maximum Number of Microphones | The maximum number of mic positions of numeric type, referring to the maximum number of people on mic simultaneously, maxSeatCount. The maximum number of seats is consistent with the maximum number of participants in the package you purchased. | Digits | 10 |
isSeatEnabled | Whether to enable microphone position control | Boolean type mic control enable flag. | Boolean value | true |
roomType | Room type | Divided into two room types: "conference" and "live". Voice chat belongs to live, so use live here. | Enumeration Value | TUIRoomType.live |
TUIRoomInfo
, you can call the createRoom
and enterRoom
API functions to create and join a live room.RoomInfo
. The following sections will provide a detailed introduction:RoomInfo
consists of many fields, but usually, you only need to focus on filling in the following fields:Parameter Name | Field Description | Additional Notes | Data Type | Example |
roomId | Room ID | Only letters (a-z, A-Z), digits (0-9), underscores, and hyphens are allowed. This field is a required parameter when creating a room and can contain up to 48 bytes. | New Character String | "live_100001" |
name | Room Name | Room name of string type. (If not provided, it will be the same as roomId) | New Character String | "denny`s room" |
seatMode | Microphone Mode | This field is effective only when microphone control is enabled. It is divided into "FREE_TO_TAKE" and "APPLY_TO_TAKE" modes. In FREE_TO_TAKE mode, audience members can take the microphone freely without applying. In APPLY_TO_TAKE mode, audience members need the room owner's approval to take the microphone. | Enumeration Value | SeatMode.APPLY_TO_TAKE |
maxSeatCount | Maximum Number of Microphones | The maximum number of mic positions of numeric type, referring to the maximum number of people on mic simultaneously, maxSeatCount. The maximum number of seats is consistent with the maximum number of participants in the package you purchased. | Digits | 10 |
isSeatEnabled | Whether to enable microphone position control | Boolean type mic control enable flag. | Boolean value | true |
roomType | Room type | Divided into two room types: "CONFERENCE" and "LIVE". Voice chat belongs to live, so use live here. | Enumeration Value | RoomType.LIVE |
TUIRoomInfo
, you can call the createRoom
and enterRoom
API functions to create and join a live room.import RTCRoomEnginelet roomInfo = TUIRoomInfo()roomInfo.roomId = "video_100001" // Please replace it with your own room IDroomInfo.name = "denny`s room" // Please replace it with your own room name.roomInfo.seatMode = .applyToTake // In typical video live streaming scenarios, the apply-to-take mode is used for joining the mic. If in your case, the audience doesn't need to apply to join the mic, you can change this to freeToTake.roomInfo.maxSeatCount = 10 // Please replace it with the maximum number of seats in the Live package you purchased.roomInfo.isSeatEnabled = true // If you do not need seat control, you can set isSeatEnabled to falseroomInfo.roomType = .live // Ensure the room type is live.TUIRoomEngine.sharedInstance().createRoom(roomInfo) { [weak self] inguard let self = self else { return }TUIRoomEngine.sharedInstance.enterRoom(self.roomId, roomType: .live) { [weak self] roomInfo inguard let self = self else { return }// Successfully joined the live streaming room} onError: { code, message in// Failed to join the live streaming room}} onError: { code, message in// Failed to create the live streaming room}
TUIRoomDefine.RoomInfo roomInfo = new TUIRoomDefine.RoomInfo();roomInfo.roomId = "video_100001"; // Please replace it with your own room IDroomInfo.name = "denny`s room"; // Please replace it with your own room name.roomInfo.seatMode = TUIRoomDefine.SeatMode.APPLY_TO_TAKE; // In typical video live streaming scenarios, the apply-to-take mode is used for joining the mic. If in your case, the audience doesn't need to apply to join the mic, you can change this to freeToTake.roomInfo.maxSeatCount = 10; // Please replace it with the maximum number of seats in the Live package you purchased.roomInfo.isSeatEnabled = true; // If you do not need seat control, you can set isSeatEnabled to falseroomInfo.roomType = TUIRoomDefine.RoomType.LIVE; // Ensure the room type is live.TUIRoomEngine.sharedInstance().createRoom(roomInfo, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {TUIRoomEngine.sharedInstance().enterRoom(roomInfo.roomId, TUIRoomDefine.RoomType.LIVE, new TUIRoomDefine.GetRoomInfoCallback() {@Overridepublic void onSuccess(TUIRoomDefine.RoomInfo roomInfo) {// Successfully joined the live streaming room}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to join the live streaming room}});}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to create the live streaming room}});
takeSeat
API to take the mic and start streaming.import RTCRoomEnginelet index = -1; // Please replace this with the seat number you want to apply for. Setting it to -1 means no need to pay attention to the seat index.let timeout = 30 // Please replace this with the timeout duration for your speaking request, in seconds. If set to 0, the SDK will not perform timeout detection or trigger timeout callbacks.TUIRoomEngine.sharedInstance().takeSeat(index, timeout: TimeInterval(timeout)) { requestId, userId in// Took the mic successfully} onRejected: { requestId, userId, messagae in// Seat request rejected} onCancelled: { requestId, userId in// Seat request canceled} onTimeout: { requestId, userId in// Seat request timed out} onError: { requestId, userId, code, message in// Failed to join the microphone}
int index = -1; // Please replace this with the seat number you want to apply for. Setting it to -1 means no need to pay attention to the seat index.int 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 callbacksTUIRoomEngine.sharedInstance().takeSeat(index, timeout, new TUIRoomDefine.RequestCallback() {@Overridepublic void onAccepted(String requestId, String userId) {// Took the mic successfully}@Overridepublic void onRejected(String requestId, String userId, String message) {// Seat request rejected}@Overridepublic void onCancelled(String requestId, String userId) {// Seat request canceled}@Overridepublic void onTimeout(String requestId, String userId) {// Seat request timed out}@Overridepublic void onError(String requestId, String userId, TUICommonDefine.Error error, String message) {// Failed to join the microphone}});
openLocalMicrophone
and openLocalCamera
APIs to enable the microphone and camera, ensuring that the audience can see your video and hear your voice.openLocalMicrophone
API requires an audio quality parameter quality
.quality
is an enumeration of type TUIAudioQuality
.Enumeration value types | Meaning |
speech | Voice mode. Mono; audio bitrate: 18kbps; suitable for voice call scenarios. |
default | Default mode. Mono; audio bitrate: 50kbps; the default audio quality of the SDK, recommended if there are no special requirements. |
music | Music mode. Stereo + full band; audio bitrate: 128kbps; suitable for scenarios requiring high-fidelity music transmission, such as online karaoke and music live streaming. |
openLocalCamera
API requires two parameters: isFront
to select the front or rear camera, and quality
for video quality.isFront
is a boolean value, true for the front camera and false for the rear camera.quality
is an enumeration of type TUIVideoQuality
.Enumeration value types | Meaning |
quality360P | 360p: SD |
quality540P | 540p: SD |
quality720P | 720p: HD |
quality1080P | 1080p: FHD |
default
, front camera enabled, and video quality set to quality1080P
.openLocalMicrophone
and openLocalCamera
APIs to enable the microphone and camera, ensuring that the audience can see your video and hear your voice.openLocalMicrophone
API requires an audio quality parameter quality
.quality
is an enumeration of type AudioQuality
.Enumeration value types | Meaning |
SPEECH | Voice mode. Mono; audio bitrate: 18kbps; suitable for voice call scenarios. |
DEFAULT | Default mode. Mono; audio bitrate: 50kbps; the default audio quality of the SDK, recommended if there are no special requirements. |
MUSIC | Music mode. Stereo + full band; audio bitrate: 128kbps; suitable for scenarios requiring high-fidelity music transmission, such as online karaoke and music live streaming. |
openLocalCamera
API requires two parameters: isFront
to select the front or rear camera, and quality
for video quality.isFront
is a boolean value, true for the front camera and false for the rear camera.quality
is an enumeration of type VideoQuality
.Enumeration value types | Meaning |
Q_360P | 360p: SD |
Q_540P | 540p: SD |
Q_720P | 720p: HD |
Q_1080P | 1080p: FHD |
DEFAULT
, front camera enabled, and video quality set to Q_1080P
.import RTCRoomEngine// Turn on the local miclet audioQuality: TUIAudioQuality = .defaultTUIRoomEngine.sharedInstance().openLocalMicrophone(audioQuality) {// Successfully turned on the mic} onError: { code, message in// Failed to turn on the mic}// Turn on the front cameralet isFrontCamera = truelet videoQuality: TUIVideoQuality = .quality1080PTUIRoomEngine.sharedInstance().openLocalCamera(isFront: isFrontCamera, quality: videoQuality) {// Successfully turned on the front camera} onError: { code, message in// Failed to open the front camera}
// Turn on the local micTUIRoomDefine.AudioQuality audioQuality = TUIRoomDefine.AudioQuality.MUSIC;TUIRoomEngine.sharedInstance().openLocalMicrophone(audioQuality, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Successfully turned on the mic}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to turn on the mic}});// Turn on the front cameraboolean isFrontCamera = true;TUIRoomDefine.VideoQuality videoQuality = TUIRoomDefine.VideoQuality.Q_1080P;TUIRoomEngine.sharedInstance().openLocalCamera(isFrontCamera, videoQuality, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Successfully opened the front camera}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to open the front camera}});
setLocalVideo
API.import RTCRoomEnginelet videoView = UIView()// ...add viewoView to your view and layout itTUIRoomEngine.sharedInstance().setLocalVideoView(view: videoView)
TUIVideoView videoView = new TUIVideoView(context);// ...add viewoView to your view and layout itTUIRoomEngine.sharedInstance().setLocalVideoView(videoView);
enterRoom
API to successfully enter the room to hear the video host's voice. If you also want to watch the host's video, please ensure you have completed Step 2 after successfully entering the room.enterRoom
to enter a voice chat room, the room type should be set to live
.import RTCRoomEnginelet roomId = "video_100001"let roomType = .liveTUIRoomEngine.sharedInstance().enterRoom(roomId, roomType: roomType) { roomInfo in// Entered room successfully} onError: { code, message in// Failed to enter the room}
String roomId = "video_100001";TUIRoomDefine.RoomType roomType = TUIRoomDefine.RoomType.LIVE;TUIRoomEngine.sharedInstance().enterRoom(roomId, roomType, new TUIRoomDefine.GetRoomInfoCallback() {@Overridepublic void onSuccess(TUIRoomDefine.RoomInfo roomInfo) {// Entered room successfully}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to enter the room}});
setRemoteVideoView
to set the remote video viewing view, passing in three parameters: the userId of the user to be viewed, the type of video stream to be played, and the view object used to play the video.TUIVideoStreamType
.Enumeration value types | Meaning |
cameraStream | HD Camera Video Stream |
screenStream | Screen Share Video Stream |
cameraStreamLow | Low-definition Camera Video Stream |
setRemoteVideoView
to set the remote video viewing view, passing in three parameters: the userId of the user to be viewed, the type of video stream to be played, and the view object used to play the video.VideoStreamType
.Enumeration value types | Meaning |
CAMERA_STREAM | HD Camera Video Stream |
SCREEN_STREAM | Screen Share Video Stream |
CAMERA_STREAM_LOW | Low-definition Camera Video Stream |
import RTCRoomEnginelet videoView = UIView()// ...add viewoView to your view and layout itlet ownerId = "" // Please replace it with the host user ID of the live room you joined.let streamType = TUIVideoStreamType.cameraStreamTUIRoomEngine.sharedInstance().setRemoteVideoView(userId: ownerId,streamType: streamType,view: videoView)
TUIVideoView videoView = new TUIVideoView(context);// ...add viewoView to your view and layout itString ownerId = ""; // Please replace it with the host user ID of the live room you joined.TUIRoomDefine.VideoStreamType streamType = TUIRoomDefine.VideoStreamType.CAMERA_STREAM;TUIRoomEngine.sharedInstance().setRemoteVideoView(ownerId, streamType, videoView);
startPlayRemoteVideo
API to watch the remote user's video stream. The playing screen will be displayed on the view object set in Step 2.startPlayRemoteVideo
requires two video parameters: the user ID of the user to watch and the type of video stream to play.import RTCRoomEnginelet ownerId = "" // Please replace it with the host user ID of the live room you joined.let streamType = TUIVideoStreamType.cameraStreamTUIRoomEngine.sharedInstance().startPlayRemoteVideo(userId: ownerId,streamType: streamType) { userId in// Playing video screen} onLoading: { userId in// Video screen loading} onError: { userId, code, message in// Video screen playback failed}
String ownerId = ""; // Please replace it with the host user ID of the live room you joined.TUIRoomDefine.VideoStreamType streamType = TUIRoomDefine.VideoStreamType.CAMERA_STREAM;TUIRoomEngine.sharedInstance().startPlayRemoteVideo(ownerId, streamType, new TUIRoomDefine.PlayCallback() {@Overridepublic void onPlaying(String userId) {// Playing video screen}@Overridepublic void onLoading(String userId) {// Video screen loading}@Overridepublic void onPlayError(String userId, TUICommonDefine.Error error, String message) {// Video screen playback failed}});
Was this page helpful?