Room Owner | Listener |
| |
TUIChorus
component and customize your own UI.TestChorus
and click Create.Android/Debug/src/main/java/com/tencent/liteav/debug/GenerateTestUserSig.java
.GenerateTestUserSig.java
:UserSig
described in this document involves configuring SECRETKEY
in client code. In this method, SECRETKEY
may be easily decompiled and reversed, and if your key is disclosed, attackers can steal your Tencent Cloud traffic. Therefore, this method is suitable only for the local execution and debugging of the app.UserSig
distribution method is to integrate the calculation code of UserSig
into your server and provide an application-oriented API. When UserSig
is needed, your application can send a request to the business server for a dynamic UserSig
. For more information, see How do I calculate UserSig on the server?.TUIChorus
with Android Studio (version 3.5 or above) and click Run.Source
folder in the source code contains two subfolders: ui
and model
. The ui
subfolder contains UI code. The table below lists the files (folders) and the UI views they represent. You can refer to it when making UI changes.File or Folder | Description |
base | Basic classes used by the UI |
room | Main room views for room owner and listener |
widget | Common controls |
Source
folder in the source code contains two subfolders: ui
and model
. The model
subfolder contains the reusable open-source component TRTCChorusRoom
. You can find the component’s APIs in TRTCChorusRoom.java
and use them to customize your own UI.TRTCChorusRoom
component depends on the TRTC SDK and IM SDK. Follow the steps below to integrate them into your project.dependencies
.dependencies {complie "com.tencent.liteav:LiteAVSDK_TRTC:latest.release"complie 'com.tencent.imsdk:imsdk:latest.release'complie 'com.google.code.gson:gson:2.3.1'}
defaultConfig
, specify the CPU architecture to be used by your application.defaultConfig {ndk {abiFilters "armeabi-v7a"}}
SDK | Download Page | Integration Guide |
TRTC SDK | ||
IM SDK |
AndroidManifest.xml
. The SDKs need the following permissions (on Android 6.0 and above, the read storage permission must be requested at runtime.)<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
proguard-rules.pro
file, add the SDK classes to the "do not obfuscate" list.-keep class com.tencent.** { *; }
TRTCChorus
componentSource/src/main/java/com/tencent/liteav/tuichorus/model
sharedInstance
API to create an instance of the TRTCChorus
component.setDelegate
API to register event callbacks of the component.login
API to log in to the component, and set the key parameters as described below.Parameter | Description |
sdkAppID | |
userId | ID of the current user, which is a string that can contain letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). We recommend you set it based on your business account system. |
userSig | |
callback | Login callback. The code is 0 if login is successful. |
TRTCChorus mTRTCChorusRoom = TRTCChorusRoom.sharedInstance(this);mTRTCChorusRoom.setDelegate(this);mTRTCChorusRoom.login(SDKAPPID, userId, userSig, new TRTCChorusRoomCallback.ActionCallback() {@Overridepublic void onCallback(int code, String msg) {if (code == 0) {// Logged in}}});
setSelfProfile
to set your nickname and profile photo.createRoom
to create a room, passing in room attributes such as room ID, whether listeners need the room owner’s consent to speak, and the number of seats.enterSeat
to take seat No. 1.onSeatListChanget
notification about the change of the seat list, and can update the change to the UI.onAnchorEnterSeat
notification about the occupation of a seat, and mic capturing will be enabled automatically.// 1. Set your nickname and profile photo.mTRTCChorusRoom.setSelfProfile("my_name", "my_face_url", null);// 2. Call `createRoom` to create a room final TRTCChorusRoomDef.RoomParam roomParam = new TRTCChorusRoomDef.RoomParam(); roomParam.roomName = "Room name"; roomParam.needRequest = false; // Whether your consent is required for listeners to speak roomParam.seatCount = 7; // Number of room seats. In this example, the number is 7. 6 seats are available after you take one. roomParam.coverUrl = "URL of room cover image"; mTRTCChorusRoom.createRoom(mRoomId, roomParam, new TRTCChorusRoomCallback.ActionCallback() { @Override public void onCallback(int code, String msg) { if (code == 0) { //3. Take seat 0 mTRTCChorusRoom.enterSeat(0, new TRTCChorusRoomCallback.ActionCallback() { @Override public void onCallback(int code, String msg) { if (code == 0) { } } }); } } });// 4. After taking a seat, you receive an `onSeatListChange` notification @Override public void onSeatListChange(final List<TRTCChorusRoomDef.SeatInfo> seatInfoList) { // Display the seat list }//5. You receive an `onAnchorEnterSeat` notification @Override public void onAnchorEnterSeat(TRTCChorusRoomDef.UserInfo userInfo) { }
setSelfProfile
to set your nickname and profile photo.getRoomInfoList
.enterRoom
with the room ID passed in to enter.onRoomInfoChange
notification about room change from the component. Record the room information, including room name, whether the room owner’s consent is required for listeners to speak, etc., and update it to the UI.onSeatListChange
notification about seat change from the component. Update the change to the UI.onAnchorEnterSeat
notification that someone becomes a speaker.// 1. Set your nickname and profile photo. mTRTCChorusRoom.setSelfProfile("my_name", "my_face_url", null);// 2. Get the room list from the backend. Suppose it is `roomList`. List<Integer> roomList = GetRoomList();// 3. Call `getRoomInfoList` to get details of the rooms. mTRTCChorusRoom.getRoomInfoList(roomList, new TRTCChorusRoomCallback.RoomInfoCallback() { @Override public void onCallback(int code, String msg, List<TRTCChorusRoomDef.RoomInfo> list) { if (code == 0) { // Refresh the room list on your UI } } });// 4. Select a room, passing in `roomId` to enter mTRTCChorusRoom.enterRoom(roomId, new TRTCChorusRoomCallback.ActionCallback() { @Override public void onCallback(int code, String msg) { if (code == 0) { //Entered room successfully } } });// 5. After successful room entry, you receive an `onRoomInfoChange` notification. @Override public void onRoomInfoChange(TRTCChorusRoomDef.RoomInfo roomInfo) { mNeedRequest = roomInfo.needRequest; mRoomName = roomInfo.roomName; // The UI can display the title and other information }// 6. You receive an `onSeatListChange` notification @Override public void onSeatListChange(final List<TRTCChorusRoomDef.SeatInfo> seatInfoList) {// Display the seat list }// 7. You receive an `onAnchorEnterSeat` notification @Override public void onAnchorEnterSeat(TRTCChorusRoomDef.UserInfo userInfo) { }
pickSeat
, passing in a seat number and the userId
of a listener to place the listener in the seat. All users in the room will receive an onSeatListChange
notification and an onAnchorEnterSeat
notification.kickSeat
, passing in a seat number to remove the speaker from the seat. All users in the room will receive an onSeatListChange
notification and an onAnchorLeaveSeat
notification.closeSeat
, passing in a seat number to block/unblock the seat. Listeners cannot take a blocked seat, and all users in the room will receive an onSeatListChange
notification and an onSeatClose
notification.enterSeat
, passing in a seat number to take the seat. All users in the room will receive an onSeatListChange
notification and an onAnchorEnterSeat
notification.leaveSeat
to leave your seat. All users in the room will receive an onSeatListChange
notification and an onAnchorLeaveSeat
notification.onSeatListChange
> independent events such as onAnchorEnterSeat
.// 1. The room owner places a user in seat No. 1mTRTCChorusRoom.pickSeat(1, "123", new TRTCChorusRoomCallback.ActionCallback() {@Overridepublic void onCallback(int code, String msg) {// 2. A callback is returned.if (code == 0) {}}});// 3. The listener receives the onSeatListChange callback, and refreshes the seat list @Override public void onSeatListChange(final List<TRTCChorusRoomDef.SeatInfo> seatInfoList) { }// 4. The room owner receives a notification about the change of a specific seat, which can be used to determine whether the user has taken the seat public void onAnchorEnterSeat(int index, TRTCChorusRoomDef.UserInfo user) { }
// 1. A listener takes the co-singer seatmTRTCChorusRoom.enterSeat(1, new TRTCChorusRoomCallback.ActionCallback() {@Overridepublic void onCallback(int code, String msg) {// 2. A callback is returned.if (code == 0) {}}});// 3. The listener receives the onSeatListChange callback, and refreshes the seat list @Override public void onSeatListChange(final List<TRTCChorusRoomDef.SeatInfo> seatInfoList) { }// 4. The listener receives a notification about the change of a specific seat and can determine whether he or she has taken the seat successfully public void onAnchorEnterSeat(int index, TRTCChorusRoomDef.UserInfo user) { }
sendInvitation
, passing in information including the room owner’s userId
and custom command words. The API will return an inviteId
, which should be recorded.onReceiveNewInvitation
notification, and a window pops up on the UI asking the room owner whether to accept the request.acceptInvitation
with the inviteId
passed in to accept the request.onInviteeAccepted
notification and calls enterSeat
to become a speaker.// Listener// 1. Call sendInvitation to request to take seat 1String inviteId = mTRTCChorusRoom.sendInvitation("ENTER_SEAT", ownerUserId, "1", null);// 2. Place the user in the seat after the invitation is accepted @Override public void onInviteeAccepted(String id, String invitee) { if(id.equals(inviteId)) { mTRTCChorusRoom.enterSeat(1, null); } }// Room owner //1. The room owner receives the request. @Override public void onReceiveNewInvitation(final String id, String inviter, String cmd, final String content) { if (cmd.equals("ENTER_SEAT")) { // 2. The room owner accepts the request. mTRTCChorusRoom.acceptInvitation(id, null); } }
sendInvitation
, passing in information including the listener's userId
and custom command words. The API will return an inviteId
, which should be recorded.onReceiveNewInvitation
notification, and a window pops up asking the listener whether to agree to speak.acceptInvitation
with the inviteId
passed in to accept the invitation.onInviteeAccepted
notification and calls pickSeat
to make the listener a speaker.// Room owner// 1. Call sendInvitation to invite user 123 to take the co-singer seatString inviteId = mTRTCChorusRoom.sendInvitation("PICK_SEAT", "123", "1", null);// 2. Place the user in the seat after the invitation is accepted @Override public void onInviteeAccepted(String id, String invitee) { if(id.equals(inviteId)) { mTRTCChorusRoom.pickSeat(2, null); } }// Listener // 1. The listener receives the invitation. @Override public void onReceiveNewInvitation(final String id, String inviter, String cmd, final String content) { if (cmd.equals("PICK_SEAT")) { // 2. The listener accepts the invitation. mTRTCChorusRoom.acceptInvitation(id, null); } }
sendRoomTextMsg
to send common text messages. All users in the room will receive an onRecvRoomTextMsg
callback.
IM has its default content moderation rules. Text messages that contain restricted terms will not be forwarded by the cloud.// Sender: send text messagesmTRTCChorusRoom.sendRoomTextMsg("Hello Word!", null);// Recipient: listen for text messagesmTRTCChorusRoom.setDelegate(new TRTCChorusRoomDelegate() {@Overridepublic void onRecvRoomTextMsg(String message, TRTCChorusRoomDef.UserInfo userInfo) {Log.d(TAG, "Received a message from" + userInfo.userName + "userInfo.userName:" + message);}});
sendRoomCustomMsg
to send custom (signaling) messages. All users in the room will receive an onRecvRoomCustomMsg
callback.
Custom messages are often used to transfer custom signals, e.g., to give and broadcast likes.// A sender can customize CMD to distinguish on-screen comments and likes.// For example, use "CMD_DANMU" to indicate on-screen comments and "CMD_LIKE" to indicate likes.mTRTCChorusRoom.sendRoomCustomMsg("CMD_DANMU", "Hello world", null);mTRTCChorusRoom.sendRoomCustomMsg("CMD_LIKE", "", null);// Recipient: listen for custom messagesmTRTCChorusRoom.setDelegate(new TRTCChorusRoomDelegate() {@Overridepublic void onRecvRoomCustomMsg(String cmd, String message, TRTCChorusRoomDef.UserInfo userInfo) {if ("CMD_DANMU".equals(cmd)) {// An on-screen comment is received.Log.d(TAG, "Received an on-screen comment from" + userInfo.userName + ":" + message);} else if ("CMD_LIKE".equals(cmd)) {// A like is received.Log.d(TAG, userInfo.userName + "liked you.");}}});
Was this page helpful?