This article will introduce how to complete the integration of the TUIRoomKit Component in the shortest time. By following this document, you will complete the following key steps within an hour and ultimately obtain an audio/video conference function with a complete UI interface.
Environment preparation
Minimum compatibility with Android 4.1 (SDK API Level 16), recommended to use Android 5.0 (SDK API Level 21) and above.
Android Studio 3.5 and above (Gradle 3.5.4 and above).
First, please Create an application in the TRTC Console and record the SDKAppID and SecretKey parameters. These parameters will be used in the subsequent integration process. The location of the application creation and parameters is shown in the following figure:
Step 2: Integrate the TUIRoomKit Component
1. Clone/Download the code from Github, then copy the debug, timcommon, tuichat, tuicore, tuiroomkit, and tuivideoseat subdirectories in the Android directory to the same level directory of your current project's app.
2. Find the setting.gradle file in the project root directory and add the following code to it. Its function is to import tuiroomkit as a local module into your current project.
include ':debug'
include ':timcommon'
include ':tuichat'
include ':tuicore'
include ':tuiroomkit'
include ':tuivideoseat'
3. Find the build.gradle file in the app directory and add the following code to it. Its function is to declare the current app's dependency on the newly added tuiroomkit component.
api project(':tuiroomkit')
Note
TUIRoomKit depends on TRTC SDK and IM SDK. During use, please add the following code to the build.gradle of your project's root directory:
Since we use Java's reflection feature in the SDK, some classes in the SDK need to be added to the non-confusion list. Therefore, you need to add the following code to the proguard-rules.pro file:
-keep class com.tencent.**{*;}
Attention
TUIRoomKit will help you apply for camera, mic, read storage permissions, etc. dynamically.
If you need to reduce them due to your business issue, you can modify tuiroomkit/src/main/AndroidManifest.xml.
Step 3: Login to TUIRoomKit Component
Add the following code to your project, which initializes the component by calling the related interfaces in TUIRoomKit. This step is crucial because only after initialization can you use the various functions of TUIRoomKit. Please be patient and check if the relevant parameters are configured correctly:
TUIRoomKit.sharedInstance(context).login(1400000001,// Please replace with the SDKAppID obtained in step 1
"998",// Please replace with your UserID
"xxxxxxxxxx");// You can calculate a UserSig in the Console and fill it in this position
Parameter Description
Here is a detailed introduction to the key parameters used in the login function:
SDKAppID:You have already obtained it in Step 1, so it will not be repeated here.
UserID:The ID of the current user, string type, only allows to contain English letters (a-z and A-Z), numbers (0-9), hyphens (-), and underscores (_).
UserSig:Encrypt the SDKAppID, UserID, etc. with the Secret Key obtained in Step 1 to get the UserSig, which is a ticket for authorization and is used for Tencent Cloud to recognize whether the current user can use the TRTC service. You can create a temporary usable UserSig through the UserSig generation function at the top of the Console overview page.
This step is also the step with the most feedback from developers we have received so far. Common problems are as follows:
SDKAppID is set incorrectly. Please use the SDKAppID of the international site correctly, otherwise, you will not be able to access it.
UserSig is misconfigured as an encryption key (SecretKey). UserSig is obtained by encrypting the SDKAppID, UserID, and expiration time with the SecretKey, not by directly configuring the SecretKey as UserSig.
UserID is set to simple strings like "1", "123", "111", etc. Since TRTC does not support multi-terminal login with the same UserID, simple UserIDs like "1", "123", "111" are easily occupied by your colleagues, causing login failure. Therefore, we recommend that you set some UserIDs with high identifiability when debugging.
The sample code in Github uses the genTestUserSig function to calculate UserSig locally to quickly get you through the current access process. However, this solution exposes your SecretKey in the App code, which is not conducive to your subsequent upgrades and protection of your SecretKey. Therefore, we strongly recommend that you put the calculation logic of UserSig on the server side and have the app request the real-time calculated UserSig from your server every time it uses the TUIRoomKit Component.
Step 4: Use TUIRoomKit
Set user information
You can set the user's username and avatar by calling TUIRoomKit's setSelfInfo.
You can create a room by calling TUIRoomKit's createRoom method and specifying the room type as TUIRoomKit.UIScene.MEETING.
publicenumRoomScene{
MEETING,// Meeting type room
LIVE // Live broadcast type room
}
publicclassRoomInfo{
publicString name;// Room name, can only be set by the room owner
publicString owner;// Room owner ID, no need to set, can be automatically obtained after entering the room
publicString roomId;// Room number
publicboolean isOpenCamera;// Whether to open the camera when entering the room
publicboolean isUseSpeaker // Whether to use the speaker when entering the room
publicboolean isOpenMicrophone;// Whether to open the mic when entering the room
publicboolean isCameraDisableForAllUser =false;// Whether to disable video for all users in the room, can only be set by the room owner, default is allowed
publicboolean isMicrophoneDisableForAllUser =false;// Whether to disable audio for all users in the room, can only be set by the room owner, default is allowed
publicboolean isMessageDisableForAllUser =false;// Whether to disable sending barrage messages in the room, can only be set by the room owner, default is allowed
publicTUIRoomDefine.SpeechMode speechMode =TUIRoomDefine.SpeechMode.FREE_TO_SPEAK;//Speech management mode in the room, default is free to speak
}
RoomInfo roomInfo =newRoomInfo();
roomInfo.name ="xx";// Please set the room name as needed
roomInfo.roomId ="998";// Please set the room number as needed
roomInfo.isOpenCamera =true;// Please set according to your business needs
roomInfo.isOpenMicrophone =true;// Please set according to your business needs
roomInfo.isUseSpeaker =true;// Please set according to your business needs
When joining a room, the RoomInfo parameter only needs to focus on roomId, isOpenCamera, isOpenMicrophone, and isUseSpeaker fields. Other fields do not need to be set.
Suggestions and Feedback
If you have any suggestions or feedback, please contact colleenyu@tencent.com.