In one-to-one or one-to-many small classes, you can record streams in multiple dimensions for different students:
This document describes how to use API Gateway and SCF to record a single anchor's audio/video stream in a TRTC room and upload the recording file to COS for storage. This solution provides out-of-the-box, flexible, convenient, and programmable live recording capabilities. SCF offers 512 MB of memory by default for recording file storage. If you need more storage space, you can choose to use the mount capability of CFS. The workflow is as shown below:
The parameters for calling APIs are as follows:
Parameter | Type | Required | Description |
---|---|---|---|
SdkAppId | Int | Yes | Application ID, which is used to distinguish different TRTC applications. |
RoomId | Int | Yes | Room ID in integer type, which is used to uniquely identify a room in a TRTC application. |
StrRoomId | String | No | Room ID in string type. Either RoomId or StrRoomId must be configured. If both are configured, RoomId will be used. |
UserId | String | Yes | Recorded user ID, which is used to uniquely identify a user in a TRTC application. |
UserSig | String | Yes | Recorded user signature, which is used to authenticate the user login. |
CosConfig | cosConfig | Yes | COS storage configuration for recording file storage. |
Callback | String | No | Callback address after recording. The POST method is used for callback. |
Mode | String | No |
// The parameters involved in CosConfig
are as follows:
Parameter | Type | Required | Description |
---|---|---|---|
SecretId | String | No | SecretId of Tencent Cloud account. For more information, please see Root Account Access Key Management. |
SecretKey | String | No | SecretKey of Tencent Cloud account. For more information, please see Root Account Access Key Management. |
Region | String | Yes | COS region, such as ap-guangzhou . |
Bucket | String | Yes | Bucket name, such as susu-123456789 . |
Path | String | Yes | Path in the bucket. For example, for /test , the root directory is / . |
Note:
UserId
is the specified user ID. Idempotency is not guaranteed for multiple requests to API Gateway.- If
SecretId
andSecretKey
are not configured inCosConfig
, the function will use the permission of the execution roleSCF_ExecuteRole
when accessing COS.
Trigger conditions for stopping recording:
RoomId
, you need to call the RemoveUser API.StrRoomId
, you need to call the RemoveUserByStrRoomId API.After recording is stopped, the data returned by the function is as follows:
Parameter | Type | Required | Description |
---|---|---|---|
SdkAppId | String | Yes | Application ID. |
RoomId | String | Yes | Room ID in integer type. |
UserId | String | Yes | Recorded user ID. |
StrRoomId | String | Yes | Room ID in string type. |
Files | Array | Yes | [{},{},{},{}] |
Note:If callback is configured, after the stop, SCF will pass the returned data to the callback address in POST method.
Each item in the Files
array is a JSON object as follows:
Parameter | Type | Required | Description |
---|---|---|---|
UserId | String | Yes | Recorded user ID. |
RecordFile | String | Yes | URL of the recording file uploaded to COS. |
Status | Int | Yes | |
Message | String | Yes | Execution result of the recording task, such as recording failed, transcoding failed, and write to COS failed. |
Note:To enable CFS, you need to set the environment variable
CFS_PATH
to a local directory, such as/mnt/audio/
.
Create a TRTC application and enter the application.
Use Postman to construct an HTTP request, where roomId
is the room ID of the created TRTC application, and userId
is the ID of another random user (which must be unique). Below is the sample code:
{
"SdkAppId": 1400000000,
"RoomId": 43474,
"UserId": "user_55952145",
"Mode": "02",
"UserSig": "eJwtzNEKgkAUBNB-2efQ3e3eUqG3tMCKJJEIIxxxxxxxxxxxxxxxhvmweLWzGlUxj0mLs1GXKVf3mgrq*GFUdUR0UQrAYWDyW6Y15cwTwDm4UkxF36iXpkq1joiSc9xxxxxxxxxxxxx-S*CZeOk9sHfnEhCwlUW*fE4oWusw3dULlJ7HoSJ2e6d9fM8Y98fxUAzWA__",
"CosConfig": {
"Region": "ap-shanghai",
"Bucket": "test-123456789",
"Path": "/trtc"
}
}
See the figure below:
After the request is sent, an async function response "Async run task submitted" will be received. The RequestId
of this function will be returned through x-scf-reqid
in the HTTP header as shown below:
On the Function Service page in the SCF console, click the name of the function created in the Creating function step above to enter the function details page.
Select the Log Query tab on the function details page to view the printed recording log information as shown below:
Log in to the TRTC console and click the room ID on the Monitoring Dashboard page to view all users in the room, one of whom is the recorded user .
To stop recording, you can call the RemoveUser or RemoveUserByStrRoomId API to move the user out of the room.
Was this page helpful?