TRTCLiveRoom
is based on Tencent Real-Time Communication (TRTC) and Tencent Cloud Chat. With TRTCLiveRoom:TRTCLiveRoom
is an open-source class depending on two closed-source Tencent Cloud SDKs. For the specific implementation process, see Interactive Live Video Streaming (Flutter).AVChatRoom
feature of the Chat SDK is used to implement chat rooms, and Chat messages are used to facilitate the co-anchoring process.API | Description |
Gets a singleton object. | |
Terminates a singleton object. | |
Registers an event listener. | |
Removes an event listener. | |
Logs in. | |
Logs out. | |
Sets profile. |
API | Description |
Creates a room (called by anchor). If the room does not exist, the system will automatically create a room. | |
Closes a room (called by anchor). | |
Enters a room (called by audience). | |
Exits a room (called by audience). | |
Gets room list details. | |
Gets the anchor and co-anchors in a room. This API works only if it is called after enterRoom() . | |
Gets the list of all users in a room. This API works only if it is called after enterRoom() . |
API | Description |
Enables preview of the local video. | |
Stops local video capturing and preview. | |
Starts live streaming (pushing streams). | |
Stops live streaming (pushing streams). | |
Plays a remote video. This API can be called in common playback and co-anchoring scenarios. | |
Stops rendering a remote video. |
API | Description |
Requests co-anchoring (called by audience). | |
Responds to a co-anchoring request (called by anchor). | |
Removes a user from co-anchoring (called by anchor). |
API | Description |
Sends a cross-room communication request (called by anchor). | |
Responds to a cross-room communication request (called by anchor). | |
Quits cross-room communication. |
API | Description |
Switches between the front and rear cameras. | |
Sets the mirror mode. | |
Mutes/Unmutes the local user. | |
Mutes/Unmutes a remote user. | |
Mutes/Unmutes all remote users. |
API | Description |
API | Description |
API | Description |
Broadcasts a text chat message in a room. This API is generally used for on-screen comments. | |
Sends a custom text message. |
API | Description |
Callback for error. | |
Callback for warning. | |
You were kicked offline because another user logged in to the account. |
API | Description |
You entered the room. | |
Whether a remote user has playable video in the primary stream (usually used for camera images) | |
The room was closed. |
API | Description |
There is a new anchor/co-anchoring viewer in the room. | |
An anchor/co-anchoring viewer quit cross-room communication/co-anchoring. | |
An audience member entered the room. | |
An audience member left the room. |
API | Description |
A co-anchoring request was received. | |
The co-anchoring request was accepted. | |
The co-anchoring request was rejected. | |
A user was removed from co-anchoring. |
API | Description |
A cross-room communication request was received. | |
The cross-room communication request was accepted. | |
The cross-room communication request was rejected. | |
The cross-room communication ended. |
API | Description |
A text message was received. | |
A custom message was received. |
static Future<TRTCLiveRoom> sharedInstance()
TRTCLiveRoom
instance can no longer be used. You need to call sharedInstance again to get a new instance.static void destroySharedInstance()
TRTCLiveRoomDelegate
to get various status notifications of TRTCLiveRoom.void registerListener(VoiceListenerFunc func);
registerListener
is the delegate callback of TRTCLiveRoom
. void unRegisterListener(VoiceListenerFunc func);
Future<ActionCallback> login(int sdkAppId, String userId, String userSig, TRTCLiveRoomConfig config);
Parameter | Type | Description |
sdkAppId | int | |
userId | String | The ID of the current user, which is a string that can contain only letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). |
userSig | String | Tencent Cloud's proprietary security signature. For how to calculate and use it, see FAQs > UserSig. |
config | TRTCLiveRoomConfig | Global configuration information, which needs to be initialized during login and cannot be modified afterward. useCDNFirst : Specifies the way the audience watches live streams. true means watching over CDNs, which is cost-efficient but has high latency. false means watching under the low latency mode, the cost of which is between that of CDN live streaming and co-anchoring, but the latency is lower than 1 second. CDNPlayDomain : Specifies the domain name for CDN live streaming. It takes effect only if useCDNFirst is set to true . You can set it in Domain Management of the CSS console. |
Future<ActionCallback> logout();
Future<ActionCallback> setSelfProfile(String userName, String avatarURL);
Parameter | Type | Description |
userName | String | Nickname |
avatarURL | String | Profile photo URL |
Future<ActionCallback> createRoom(int roomId, TRTCCreateRoomParam roomParam);
Parameter | Type | Description |
roomId | int | The room ID. You need to assign and manage the IDs in a centralized manner. Multiple roomId values can be aggregated into a live room list. Currently, Tencent Cloud does not provide list management services. Please manage your own room lists. |
roomParam | RoomParam | Room information, such as room name and cover information. If both the room list and room information are managed on your server, you can ignore this parameter. |
startCameraPreview()
to enable camera preview and set beauty filters. createRoom()
to create a room, the result of which is returned via the ActionCallback
callback.startPublish()
to push streams.Future<ActionCallback> destroyRoom();
Future<ActionCallback> enterRoom(int roomId);
Parameter | Type | Description |
roomId | int | The room ID. |
roomID
and other information of multiple rooms.enterRoom()
to enter the room.startPlay(userId)
, passing in the anchor’s userId
to start playback.userId
, the user can call startPlay(userId)
to start playback.userId
before room entry, he or she can find it in the onAnchorEnter(userId)
callback of TRTCLiveRoomDelegate
, which is returned after room entry. The user can then call startPlay(userId)
to start playback.Future<ActionCallback> exitRoom();
roomInfo
when they call createRoom()
.Future<RoomInfoCallback> getRoomInfos(List<String> roomIdList);
Parameter | Type | Description |
roomIdList | List<String> | Room ID list |
enterRoom()
.Future<UserListCallback> getAnchorList();
enterRoom()
.Future<UserListCallback> getRoomMemberList(int nextSeq)
Parameter | Type | Description |
nextSeq | int | Pulling-by-page flag. It is set to 0 when the information is pulled for the first time. If the callback succeeds and nextSeq is not 0, pagination is needed. The value of this field is passed in for the next pull until the value becomes 0. |
Future<void> startCameraPreview(bool isFrontCamera, int viewId);
Parameter | Type | Description |
isFrontCamera | bool | true: Front camera; false: Rear camera. |
viewId | int | Called back video view ID |
Future<void> stopCameraPreview();
Future<void> startPublish(String streamId);
Parameter | Type | Description |
streamId | String? | The streamId used to bind live streaming CDNs. You need to specify the streamId of the anchor if you want the audience to recieve the anchor's streams via live streaming CDNs. |
Future<void> stopPublish();
Future<void> startPlay(String userId, int viewId);
Parameter | Type | Description |
userId | String | The ID of the user whose video is to be played. |
viewId | int | Called back video view ID. |
userId
, after entering a room, a user can call startPlay(userId)
to play the anchor's video.userId
before room entry, they can find it in the onAnchorEnter(userId)
callback of TRTCLiveRoomDelegate
, which is returned after room entry. They can then call startPlay(userId)
to play the anchor’s video.onAnchorEnter(userId)
callback from TRTCLiveRoomDelegate
and can call startPlay(userId), passing in the
userId` returned by the callback to play co-anchoring video.onAnchorExit()
callback is received.Future<void> stopPlay(String userId);
Parameter | Type | Description |
userId | String | The ID of the remote user. |
Future<ActionCallback> requestJoinAnchor();
requestJoinAnchor()
to send a co-anchoring request to the anchor.onRequestJoinAnchor()
callback of TRTCLiveRoomDelegate
.responseJoinAnchor()
to accept or reject the co-anchoring request.responseCallback
callback, which carries the anchor’s response.startCameraPreview()
to enable local camera preview.startPublish()
to push streams.onAnchorEnter()
callback of TRTCLiveRoomDelegate
.startPlay()
to play the co-anchoring viewer’s video.onAnchorEnter()
callback and can call startPlay()
to play other co-anchoring viewers’ video.onRequestJoinAnchor()
callback of TRTCLiveRoomDelegate
.Future<ActionCallback> responseJoinAnchor(String userId, boolean agreee);
Parameter | Type | Description |
userId | String | The user ID of the audience member. |
agree | bool | true : Accept; false : Reject |
onKickoutJoinAnchor()
callback of TRTCLiveRoomDelegate
.Future<ActionCallback> kickoutJoinAnchor(String userId);
Parameter | Type | Description |
userId | String | The ID of the co-anchoring user. |
Future<ActionCallback> requestRoomPK(int roomId, String userId);
Parameter | Type | Description |
roomId | int | The Room ID of the anchor to call. |
userId | String | The user ID of the anchor to call. |
requestRoomPK()
to send a cross-room communication request to anchor B.onRequestRoomPK()
callback of TRTCLiveRoomDelegate
.responseRoomPK()
to respond to the cross-room communication request.onAnchorEnter()
callback of TRTCLiveRoomDelegate
and call startPlay()
to play anchor A's video.onRoomPKAccepted
or onRoomPKRejected
callback.onAnchorEnter()
callback of TRTCLiveRoomDelegate
and calls startPlay()
to play anchor B’s video.responseCallback
passed in to requestRoomPK
.Future<ActionCallback> responseRoomPK(String userId, boolean agree);
Parameter | Type | Description |
userId | String | The user ID of the anchor sending the communication request. |
agree | bool | true : Accept; false : Reject |
onQuitRoomPk()
callback of TRTCLiveRoomDelegate
.Future<ActionCallback> quitRoomPK();
Future<void> switchCamera(boolean isFrontCamera);
Future<void> setMirror(boolean isMirror);
Parameter | Type | Description |
isMirror | bool | Enables/Disables mirroring. |
Future<void> muteLocalAudio(boolean mute);
Parameter | Type | Description |
mute | boolean | true : Mute; false : Unmute |
Future<void> muteRemoteAudio(String userId, boolean mute);
Parameter | Type | Description |
userId | String | The ID of the remote user. |
mute | boolean | true : Mute; false : Unmute |
Future<void> muteAllRemoteAudio(boolean mute);
Parameter | Type | Description |
mute | boolean | true : Mute; false : Unmute |
getAudioEffectManager();
getBeautyManager();
TXBeautyManager
:Future<ActionCallback> sendRoomTextMsg(String message);
Parameter | Type | Description |
message | String | A text message. |
Future<ActionCallback> sendRoomCustomMsg(String cmd, String message);
Parameter | Type | Description |
cmd | String | A custom command word used to distinguish between different message types |
message | String | Custom text message |
TRTCLiveRoomDelegate
Event Callback APIsParameter | Type | Description |
errCode | int | Error code |
errMsg | String | Error message |
Parameter | Type | Description |
warningCode | int | Warning code |
warningMsg | String | Warning message |
Parameter | Type | Description |
result | int | If result is greater than 0, it indicates the time (ms) room entry took; if result is less than 0, it represents the error code for room entry. |
Parameter | Type | Description |
userId | String | The user ID. |
available | boolean | Whether the user's video is enabled. |
startPlay()
of TRTCLiveRoom
to play the video of the anchor/co-anchoring viewer.Parameter | Type | Description |
userId | String | User ID of the new anchor/co-anchoring viewer |
userName | String | Username |
userAvatar | String | The address of the user profile photo. |
stopPlay()
of TRTCLiveRoom
to stop playing the video of the anchor/co-anchoring viewer.Parameter | Type | Description |
userId | String | ID of the user who quitted co-anchoring |
userName | String | Username |
userAvatar | String | The address of the user profile photo. |
void onAudienceEnter(TRTCLiveRoomDef.TRTCLiveUserInfo userInfo);
Parameter | Type | Description |
userInfo | TRTCLiveRoomDef.TRTCLiveUserInfo | Information of the viewer who enters the room, such as user ID, nickname, and profile photo. |
Parameter | Type | Description |
userId | String | User ID of the viewer |
userName | String | Username |
userAvatar | String | The address of the user profile photo. |
Parameter | Type | Description |
userId | String | ID of the request sending user |
userName | String | Username |
userAvatar | String | The address of the user profile photo. |
Parameter | Type | Description |
userId | String | User ID of the anchor |
Parameter | Type | Description |
userId | String | User ID of the anchor |
stopPublish()
of TRTCLiveRoom
to quit co-anchoring.onAnchorEnter()
callback of TRTCLiveRoomDelegate
and call startPlay()
to play the other anchor’s video.Parameter | Type | Description |
userId | String | User ID of the anchor sending the request |
userName | String | Username |
userAvatar | String | The address of the user profile photo. |
Parameter | Type | Description |
userId | String | User ID of the anchor who accepted the request |
Parameter | Type | Description |
userId | String | User ID of the anchor who rejected the request |
Parameter | Type | Description |
message | String | Text message |
Parameter | Type | Description |
command | String | Custom command word used to distinguish between different message types |
message | String | Custom text message |
Was this page helpful?