This section summarizes some common business processes in online claw machines to help you better understand the implementation of the entire scenario.
Online Claw Machine TRTC Streaming
Online Claw Machine RTMP Streaming
The diagram below illustrates the sequence of RTC Engine streaming for an online claw machine, including processes such as RTC Engine streaming from a network camera and user-side stream pulling.
The diagram below illustrates the sequence of RTMP streaming for an online claw machine, including processes such as RTMP streaming from a network camera and user streaming pull.
Integration Preparation
Step 1: Activate the Service
The online claw machine scenario typically relies on the paid PaaS service of RTC Engine for implementation. RTC Engine provides real-time audio and video interaction capabilities. You can choose to activate the service based on your specific business requirements.
1. Log in to the RTC Engine console, then click Create application on the Applications page. You can choose to upgrade the RTC Engine application edition as needed. For example, upgrading to the Pro Edition includes additional value-added feature services.
Note:
It is recommended to create two separate applications for the test environment and the production environment. The first activation of RTC Engine includes a free 10,000-minute trial package.
The RTC Engine monthly packages (Free Trial, Lite, Standard, and Pro packages) offer different value-added feature services. For details, see RTC Engine Monthly Packages.
2. After creating the application, you can view its basic information in Application Management > Application Overview. Keep your SDKAppID and SDKSecretKey secure for future use, and take precautions to prevent key leakage that may result in unauthorized traffic usage.
Step 2: Import the SDK
The RTC Engine SDK has been released to the mavenCentral repository. You can configure Gradle for automatic download and update the SDK.
1. Add the dependency for the appropriate version of the SDK in dependencies.
// RTC Engine SDK for the Lite Edition, including two features, that is, RTC and live streaming playback.
Do not set android:hardwareAccelerated="false". Disabling hardware acceleration will result in failure to render remote video streams.
LiteAVSDK does not have built-in permission request logic, so you need to declare the corresponding permissions yourself. Some permissions (such as storage, recording and camera) also require runtime dynamic requests.
If the Android project’s targetSdkVersion is 31 or the target device runs Android 12 or higher, it is mandatory to dynamically request the android.permission.BLUETOOTH_CONNECT permission in the code to ensure proper Bluetooth feature. For more details, see Android Official Documentation.
2. Obfuscate configuration.
Java's reflection is used inside the SDK, so you need to add the relevant SDK classes to the non-obfuscation list in the proguard-rules.pro file:
-keep class com.tencent.**{*;}
Step 4: Perform Authentication and Authorization
UserSig is a security protection signature designed by TRTC to prevent malicious attackers from misappropriating your cloud service usage rights. RTC Engine validates this authentication credential when entering a room.
Debugging phase: You can generate the UserSig using either the Client Sample Code or the Console Access. This method is intended solely for debugging and testing purposes.
Production stage: It is recommended to use the server-side computation scheme for UserSig with a higher security level to prevent client-side reverse engineering and key leakage.
Implementation process:
1. Before calling the initialization API of the SDK, your application must first request a UserSig from your server.
2. Your server generates the UserSig based on the SDKAppID and UserID.
3. The server returns the generated UserSig to your app.
4. Your app sends the obtained UserSig to the SDK through the designated API.
5. The SDK submits the SDKAppID + UserID + UserSig to the TRTC server for verification.
6. TRTC verifies the validity of the UserSig.
7. After the verification is passed, the RTC Engine SDK will be provided with real-time audio and video services.
Note:
The method of generating UserSig locally during the debugging and testing stage is not recommended for the production environment because it may be easily decompiled and reversed, causing key leakage.
We provide UserSig server generation source code in multiple languages (Java/GO/PHP/Nodejs/Python/C#/C++). For details, see UserSig Generation Source Code.
Step 5: Initialize the SDK
// Create an RTC Engine SDK instance (singleton mode).
2. Configure the SdkAppID, UserID, UserSig, RoomID, and other information on the RTC Engine network camera or streaming box to start streaming.
Note:
RTC Engine room IDs are divided into numeric type roomID and string type strRoomID. The rooms of these two types are not interconnected. It is recommended to unify the room ID type.
RTC Engine user roles are divided into hosts and audiences. Only hosts have streaming permissions. The user role should be specified when entering the room. If the user role is not specified, the default role is host.
For the online claw machine scenario, it is recommended to use the TRTC_APP_SCENE_VIDEOCALL mode for entering a room, as it ensures lower latency.
Log.d(TAG,"Actively call exitRoom to exit the room.");
}elseif(reason ==1){
Log.d(TAG,"Removed from the current room by the server.");
}elseif(reason ==2){
Log.d(TAG,"The current room has been dissolved.");
}
}
Note:
After all resources occupied by the SDK are released, the SDK will throw the onExitRoom callback notification to inform you.
If you need to call enterRoom again or switch to another audio and video SDK, wait for the onExitRoom callback before proceeding. Otherwise, you may encounter various exceptional issues such as camera, microphone device being forcibly occupied.
2. Dissolve room.
Server-side Dissolve Room.
RTC Engine provides the server-side API DismissRoom for dissolving rooms with numeric types and the API DismissRoomByStrRoomId for dissolving rooms with string types. You can use these server-side APIs to remove all users from the room and dissolve the room.
Client-side Dissolve Room.
The client does not provide an API for directly dissolving a room. Each client should call exitRoom to exit the room. Once all anchors and audiences have exited the room, the room will be automatically dissolved according to the RTC Engine room lifecycle rules. For details, see RTC Engine Exit the Room.
Exception Handling
Error Handling
RTC Engine SDK throws unrecoverable errors in the onError callback. For details, see RTC Engine Error Codes.
1. UserSig related.
UserSig verification failure will result in enter Room to failure.You can see UserSig tool for verification.
Error Example
Value
Description
ERR_TRTC_INVALID_USER_SIG
-3320
Enter Room parameter UserSig is incorrect. Please check if TRTCParams.userSig is empty.
ERR_TRTC_USER_SIG_CHECK_FAILED
-100018
UserSig verification failed. Please check ifTRTCParams.userSig is correct or expired.
2. Enter or Exit Room related.
If entering room fails, you should first verify the correctness of the room entry parameters. It is essential that the room entry and exit APIs are called in a paired manner. This means that, even in the event of a failed room entry, the room exit API must still be called.
Error Example
Value
Description
ERR_TRTC_CONNECT_SERVER_TIMEOUT
-3308
Enter Room request timed out. Check for network disconnection or VPN. You can also try switching to 4G for testing.
ERR_TRTC_INVALID_SDK_APPID
-3317
Enter Room parameter sdkAppId is incorrect. Check if TRTCParams.sdkAppId is empty
ERR_TRTC_INVALID_ROOM_ID
-3318
Enter Room parameter roomId is incorrect. Check if TRTCParams.roomId or TRTCParams.strRoomId is empty. Note that roomId and strRoomId cannot be used interchangeably.
ERR_TRTC_INVALID_USER_ID
-3319
Enter Room parameter userId is incorrect. Check if TRTCParams.userId is empty.
ERR_TRTC_ENTER_ROOM_REFUSED
-3340
Enter Room request was refused. Check ifenterRoom is called consecutively to enter rooms with the same ID.
3. Device related.
Listen for device-related errors and notify users via the UI when they occur.
Error Example
Value
Description
ERR_CAMERA_START_FAIL
-1301
Failed to turn the camera on.
For example, if there is an exception for the camera's configuration program (driver) on a Windows or Mac device, you should try disabling then re-enabling the device, restarting the machine, or updating the configuration program.
ERR_MIC_START_FAIL
-1302
Failed to turn the microphone on.
For example, if there is an exception for the microphone's configuration program (driver) on a Windows or Mac device, you should try disabling and then re-enabling the device, restarting the machine, or updating the configuration program.
ERR_CAMERA_NOT_AUTHORIZED
-1314
Camera device not authorized. This typically occurs on mobile devices, probably because the user denied the permission.
ERR_MIC_NOT_AUTHORIZED
-1317
Microphone device not authorized. This typically occurs on mobile devices, probably because the user denied the permission.
ERR_CAMERA_OCCUPY
-1316
Camera is currently occupied. Try opening another camera.
ERR_MIC_OCCUPY
-1319
Microphone is currently occupied.
For example, when the user is currently having a call on a mobile device, the microphone cannot be turned on.
Black Screen During Playback
In RTMP claw machine streaming scenarios, RTMP streaming successfully enters the RTC Engine room, but playback fails. The issue occurs because the streaming configuration includes B-frames, which are not supported by RTC Engine rooms, resulting in failed RTMP stream playback. Example streaming configuration:
Audience Playback Stuck
In claw machine scenarios, when an RTC Engine audience enters a room and plays back for a period of time, playback may freeze, especially after multiple peer-join or onUserVideoAvailable callbacks. The audience's playback screen may freeze on the last frame. If this occurs, first check the dashboard for detailed call information. If the dashboard shows that the host has entered and exited the room multiple times, the issue is likely due to mutual kicking. Dashboard example:
Solution: Try stopping the current device’s stream to resolve the issue. If the problem remains unresolved, then check whether 2 identical streaming addresses are configured on the same machine.