TRTCChatSalon
is based on Tencent Real-Time Communication (TRTC) and Instant Messaging (IM). Its features include:
TRTCChatSalon
is an open-source class depending on two closed-source Tencent Cloud SDKs. For the specific implementation process, please see Chat Salon (Android).
AVChatRoom
feature of the IM SDK is used to implement chat rooms. The attribute APIs of IM are used to store room information such as the speaker list, and invitation signaling is used to send requests to speak or invite others to speak.TRTCChatSalon
API OverviewAPI | Description |
---|---|
sharedInstance | Gets singleton object. |
destroySharedInstance | Terminates singleton object. |
setDelegate | Sets event callback. |
setDelegateHandler | Sets the thread where the event callback is. |
login | Logs in. |
logout | Logs out. |
setSelfProfile | Sets profile. |
API | Description |
---|---|
createRoom | Creates room (called by room owner). If the room does not exist, the system will automatically create a room. |
destroyRoom | Terminates room (called by room owner). |
enterRoom | Enters room (called by listener). |
exitRoom | Exits room (called by listener). |
getRoomInfoList | Gets room list details. |
getUserInfoList | Gets the user information of the specified userId . If the value is null , the information of all users in the room is obtained. |
API | Description |
---|---|
enterSeat | Becomes a speaker (called by room owner or listener). |
leaveSeat | Becomes a listener (called by speaker). |
pickSeat | Invites a listener to speak (called by room owner). |
kickSeat | Removes a speaker (called by room owner). |
API | Description |
---|---|
startMicrophone | Enables mic capturing. |
stopMicrophone | Stops mic capturing. |
setAudioQuality | Sets audio quality. |
muteLocalAudio | Mutes/Unmutes local audio. |
setSpeaker | Turns the speaker on. |
setAudioCaptureVolume | Sets mic capturing volume. |
setAudioPlayoutVolume | Sets playback volume. |
API | Description |
---|---|
muteRemoteAudio | Mutes/Unmutes specified member. |
muteAllRemoteAudio | Mutes/Unmutes all members. |
API | Description |
---|---|
getAudioEffectManager | Gets background music and audio effect management object TXAudioEffectManager. |
API | Description |
---|---|
sendRoomTextMsg | Broadcasts text message in room. This API is generally used for on-screen comments. |
sendRoomCustomMsg | Sends custom text message. |
API | Description |
---|---|
sendInvitation | Sends invitation. |
acceptInvitation | Accepts invitation. |
rejectInvitation | Declines invitation. |
cancelInvitation | Cancels invitation. |
TRTCChatSalonDelegate
API OverviewAPI | Description |
---|---|
onError | Error |
onWarning | Warning |
onDebugLog | Log |
API | Description |
---|---|
onRoomDestroy | Room termination |
onRoomInfoChange | Room information change |
onUserVolumeUpdate | User volume |
API | Description |
---|---|
onAnchorEnterSeat | Someone became a speaker after requesting or being invited by the room owner. |
onAnchorLeaveSeat | Someone became a listener or was moved to listeners by the room owner. |
onSeatMute | The room owner muted a speaker. |
API | Description |
---|---|
onAudienceEnter | A listener entered the room. |
onAudienceExit | A listener exited the room. |
API | Description |
---|---|
onRecvRoomTextMsg | Receipt of text message |
onRecvRoomCustomMsg | Receipt of custom message |
API | Description |
---|---|
onReceiveNewInvitation | Receipt of invitation |
onInviteeAccepted | Invitation accepted by invitee |
onInviteeRejected | Invitation declined by invitee |
onInvitationCancelled | Invitation canceled by inviter |
This API is used to get a TRTCChatSalon singleton object.
public static synchronized TRTCChatSalon sharedInstance(Context context);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
context | Context | Android context, which will be converted to ApplicationContext for the calling of system APIs |
This API is used to terminate a TRTCChatSalon singleton object.
Note:After the instance is terminated, the externally cached
TRTCChatSalon
instance can no longer be used. You need to call sharedInstance again to get a new instance.
public static void destroySharedInstance();
This API is used to set the event callbacks of TRTCChatSalon. You can use TRTCChatSalonDelegate
to get different status notifications of TRTCChatSalon.
public abstract void setDelegate(TRTCChatSalonDelegate delegate);
Note:
setDelegate
is the delegate callback ofTRTCChatSalon
.
This API is used to set the thread where the event callback is.
public abstract void setDelegateHandler(Handler handler);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
handler | Handler | Status notifications in TRTCChatSalon will be sent to the handler thread you specify. |
This API is used to log in.
public abstract void login(int sdkAppId,
String userId, String userSig,
TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
sdkAppId | int | You can view the SDKAppID via Application Management > Application Info in the TRTC console. |
userId | String | ID of 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 more information on how to get it, please see UserSig. |
callback | ActionCallback | Callback for login. The code will be 0 if login succeeds. |
This API is used to log out.
public abstract void logout(TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
callback | ActionCallback | Callback for logout. The code is 0 if logout succeeds. |
This API is used to set profile.
public abstract void setSelfProfile(String userName, String avatarURL, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userName | String | Nickname |
avatar |
String |
Profile photo address |
callback | ActionCallback | Callback for profile setting. The code is 0 if the operation succeeds. |
This API is used to create a room (called by room owner).
public abstract void createRoom(int roomId, TRTCChatSalonDef.RoomParam roomParam, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
roomId | int | Room ID. You need to assign and manage the IDs in a centralized manner. Multiple roomID values can be aggregated into a chat salon room list. Currently, Tencent Cloud does not provide management services for chat salon room lists. Please manage the list by yourself. |
roomParam | RoomParam | Room information, such as room name, speaker list information, and cover information |
callback | ActionCallback | Callback for room creation result. The code is 0 if the operation succeeds. |
The process of creating a chat salon and becoming a speaker is as follows:
createRoom
to create a chat salon, passing in room attributes (e.g., room ID and whether listeners require room owner’s consent to speak).enterSeat
to become a speaker.onAnchorEnterSeat
notification that someone became a speaker, and mic capturing will be enabled automatically.This API is used to terminate a room (called by room owner).
public abstract void destroyRoom(TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
callback | ActionCallback | Callback for room termination result. The code is 0 if the operation succeeds. |
This API is used to enter a room (called by listener).
public abstract void enterRoom(int roomId, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
roomId | int | Room ID |
callback | ActionCallback | Callback for room entry result. The code is 0 if the operation succeeds. |
The process of entering a room as a listener is as follows:
roomId
and room information of multiple chat salons.enterRoom
with the room ID passed in to enter.onRoomInfoChange
notification about room attribute change from the component. The attributes can be recorded, and corresponding changes can be made to the UI, including room name, whether room owner’s consent is required for listeners to speak, etc.onAnchorEnterSeat
notification that someone became a speaker.This API is used to exit a room.
public abstract void exitRoom(TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
callback | ActionCallback | Callback for room exit result. The code is 0 if the operation succeeds. |
This API is used to get room list details. The room name and cover are set by the room owner via roomInfo
when calling createRoom()
.
Note:If both the room list and room information are managed on your server, you can ignore this parameter.
public abstract void getRoomInfoList(List<Integer> roomIdList, TRTCChatSalonCallback.RoomInfoCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
roomIdList | List&dxlt;Integer&dxgt; | Room ID list |
callback | RoomInfoCallback | Callback for room details |
This API is used to get the user information of a specified userId
.
public abstract void getUserInfoList(List<String> userIdList, TRTCChatSalonCallback.UserListCallback userlistcallback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userIdList | List | IDs of the users to query. If this parameter is null , the information of all users in the room is obtained. |
userlistcallback | UserListCallback | Callback for user details |
This API is used to become a speaker (called by room owner or listener).
Note:After a user becomes a speaker, all members in the room will receive an
onAnchorEnterSeat
notification.
public abstract void enterSeat(TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
callback | ActionCallback | Callback for operation |
Calling this API will immediately modify the speaker list. In cases where listeners need the room owner’s consent to speak, you can call sendInvitation
first to send a request and, after receiving onInvitationAccept
, call enterSeat
.
This API is used to become a listener (called by speaker).
Note:After a speaker becomes a listener, all members in the room will receive an
onAnchorLeaveSeat
notification..
public abstract void leaveSeat(TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
callback | ActionCallback | Callback for operation |
This API is used to invite a listener to speak (called by room owner).
Note:After a listener becomes a speaker following the room owner's invitation, all members in the room will receive an
onAnchorEnterSeat
notification.
public abstract void pickSeat(String userId, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userID | String | User ID |
callback | ActionCallback | Callback for operation |
Calling this API will immediately modify the speaker list. In cases where the room owner needs listeners’ consent to make them speakers, you can call sendInvitation
first to send a request and, after receiving onInvitationAccept
, call pickSeat
.
This API is used to remove a speaker (called by room owner).
Note:After a speaker is removed, all members in the room will receive an
onAnchorLeaveSeat
notification.
public abstract void kickSeat(String userId, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userId | String | User ID of the speaker to remove |
callback | ActionCallback | Callback for operation |
Calling this API will immediately modify the speaker list.
This API is used to enable mic capturing.
public abstract void startMicrophone();
This API is used to stop mic capturing.
public abstract void stopMicrophone();
This API is used to set audio quality.
public abstract void setAudioQuality(int quality);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
quality | int | Audio quality. For more information, please see TRTC SDK. |
This API is used to mute/unmute the local audio.
public abstract void muteLocalAudio(boolean mute);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
mute | boolean | Mutes/Unmutes. For more information, please see TRTC SDK. |
This API is used to turn the speaker on.
public abstract void setSpeaker(boolean useSpeaker);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
useSpeaker | boolean | true : speaker; false : receiver |
This API is used to set the mic capturing volume.
public abstract void setAudioCaptureVolume(int volume);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
volume | int | Capturing volume. Value range: 0-100 (default: 100) |
This API is used to set the playback volume.
public abstract void setAudioPlayoutVolume(int volume);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
volume | int | Playback volume. Value range: 0-100 (default: 100) |
This API is used to mute/unmute a specified member.
public abstract void muteRemoteAudio(String userId, boolean mute);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userId | String | Specified user ID |
mute | boolean | true : mute; false : unmute |
This API is used to mute/unmute all members.
public abstract void muteAllRemoteAudio(boolean mute);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
mute | boolean | true : mute; false : unmute |
This API is used to get the background music and audio effect management object TXAudioEffectManager.
public abstract TXAudioEffectManager getAudioEffectManager();
This API is used to broadcast a text message in the room, which is generally used for on-screen comments.
public abstract void sendRoomTextMsg(String message, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
message | String | Text message |
callback | ActionCallback | Callback for sending result |
This API is used to send custom text messages.
public abstract void sendRoomCustomMsg(String cmd, String message, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
cmd | String | Custom command word used to distinguish between different message types |
message | String | Text message |
callback | ActionCallback | Callback for sending result |
This API is used to send an invitation.
public abstract String sendInvitation(String cmd, String userId, String content, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
cmd | String | Custom command of business |
userId | String | Invitee’s user ID |
content | String | Invitation content |
callback | ActionCallback | Callback for sending result |
Returned value:
Returned Value | Type | Description |
---|---|---|
inviteId | String | Invitation ID |
This API is used to accept an invitation.
public abstract void acceptInvitation(String id, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
callback | ActionCallback | Callback for sending result |
This API is used to decline an invitation.
public abstract void rejectInvitation(String id, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
callback | ActionCallback | Callback for sending result |
This API is used to cancel an invitation.
public abstract void cancelInvitation(String id, TRTCChatSalonCallback.ActionCallback callback);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
callback | ActionCallback | Callback for sending result |
TRTCChatSalonDelegate
Event Callback APIsCallback for error.
Note:This callback indicates that the SDK encountered an unrecoverable error. Such errors must be listened for, and UI reminders should be sent to users if necessary.
void onError(int code, String message);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
code | int | Error code |
message | String | Error message |
Callback for warning.
void onWarning(int code, String message);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
code | int | Error code |
message | String | Warning message |
Callback for log.
void onDebugLog(String message);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
message | String | Log information |
Callback for room termination. When the owner terminates the room, all users in the room will receive this callback.
void onRoomDestroy(String roomId);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
roomId | String | Room ID |
Callback for successful room entry. The information in roomInfo
is passed in by the room owner during room creation.
void onRoomInfoChange(TRTCChatSalonDef.RoomInfo roomInfo);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
roomInfo | RoomInfo | Room information |
Callback of the volume of each member in the room after the volume reminder is enabled.
void onUserVolumeUpdate(String userId, int volume);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userId | String | User ID |
volume | int | Volume. Value range: 0-100 |
Someone became a speaker after requesting or being invited by the room owner.
void onAnchorEnterSeat(TRTCChatSalonDef.UserInfo user);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
user | UserInfo | Details of the user who became a speaker |
A speaker became a listener or was moved to listeners by the room owner.
void onAnchorLeaveSeat(TRTCChatSalonDef.UserInfo user);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
user | UserInfo | Details of the user who became a listener |
The room owner muted a speaker.
void onSeatMute(String userId, boolean isMute);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userId | String | ID of the speaker who was muted |
isMute | boolean | true : muted; false : unmuted |
A listener entered the room.
void onAudienceEnter(TRTCChatSalonDef.UserInfo userInfo);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userInfo | UserInfo | Information of the user who entered the room |
A listener exited the room.
void onAudienceExit(TRTCChatSalonDef.UserInfo userInfo);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
userInfo | UserInfo | Information of the listener who exited the room |
A text message was received.
void onRecvRoomTextMsg(String message, TRTCChatSalonDef.UserInfo userInfo);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
message | String | Text message |
userInfo | UserInfo | User information of sender |
A custom message was received.
void onRecvRoomCustomMsg(String cmd, String message, TRTCChatSalonDef.UserInfo userInfo);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
cmd | String | Custom command word used to distinguish between different message types |
message | String | Text message |
userInfo | UserInfo | User information of sender |
A new invitation was received.
void onReceiveNewInvitation(String id, String inviter, String cmd, String content);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
inviter | String | Inviter’s user ID |
cmd | String | Custom command word specified by business |
content | String | Content specified by business |
The invitee accepted the invitation.
void onInviteeAccepted(String id, String invitee);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
invitee | String | Invitee’s user ID |
The invitee declined the invitation.
void onInviteeRejected(String id, String invitee);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
invitee | String | Invitee’s user ID |
The inviter canceled the invitation.
void onInvitationCancelled(String id, String inviter);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
inviter | String | Inviter’s user ID |
The invitation timed out.
void onInvitationTimeout(String id);
The parameters are as detailed below:
Parameter | Type | Description |
---|---|---|
id | String | Invitation ID |
Was this page helpful?