Serverless cloud function has the features of one-click trigger, free operation and maintenance, elastic scaling and so on. TRTC real-time audio and video can quickly support the construction of real-time interactive entertainment and social applications by accessing the cloud function service, reducing the delay and storage cost. In addition, the programmability of cloud functions enables rapid integration of other cloud services and third-party services, expansion of business boundaries and efficient innovation of gameplay.
01. Application Scenarios
AI Interactive classroom
Through recording and broadcasting live teaching videos and AI technology, interactive online teaching is carried out.
- Before class, according to the teacher’s curriculum setting, the knowledge point explanation, interactive questioning, question feedback and solution information are recorded into video clips and uploaded to the video library.
- In class, the existing recorded and played videos are pushed to the TRTC room for live broadcasting through the cloud function. Students learn interactively through voice and touch screen. The server uses AI technology to intelligently recognize students’ real-time voice and answer, seamlessly switch teaching segments according to students’ performance, and give different feedback in real time, thus providing personalized teaching experience.
Watch Together room service
- The RTMP live stream can be pushed to TRTC room through cloud function for real-time communication and hot spots.
- Movies, music and other on-demand programs can be converted into online media streams and input to TRTC rooms through cloud functions, value-added services and community circles.
02. Operation Scenarios
Push the existing recorded video or RTMP live stream to the real-time audio and video TRTC room for live broadcast. If you need to enable real-time recording of push stream live, you can choose Redis, and API gateway will write the progress into Redis in real time. The working process is as follows:
The parameters involved in the API gateway call are as follows:
- If the value of Redis is false, the live stream will be pushed from the videoSrc video source pull stream and the live stream will start from the latest.
- If redis is true, API gateway will first query redis to see if there is a record of the last live stream push for the same videoSrc video source:
- If there is a record, the last push stream is restored.
- If no record is recorded, the stream is restarted. Live push stream progress is written to Redis in real time through callbacks.
03. Procedure
1. Create a cloud function
1.1 Log in to the Cloud Function Console, choose Function Service in the navigation tree on the left, and click Add. The page for creating a function is displayed. Set parameters as prompted. As shown below:
- The function of cloud console: console.cloud.tencent.com/scf
- Creation method: Select Create Template.
- Fuzzy search: Enter “TRTC Live Push stream” and search. Click View Details in the template. You can view related information in the Template Details window that is displayed. You can download the template.
1.2 Click Next and set parameters as prompted. As shown below:
- Function name: Fill by default.
- Asynchronous execution: Selected to enable. When enabled, the function will respond to events in asynchronous execution mode. The event invocation does not need to block waiting for the result of processing. The event will enter the asynchronous execution state after being invoked.
- Status tracking: Check to enable. After this function is enabled, the system records the real-time status of asynchronous events and provides statistics, query, and termination of events. The event status data generated will be kept for 3 days.
- Execution timeout period: Change it as required.
1.3 Configuring API Gateway Triggers By default, the API service is created and integrated response is disabled. You can also choose custom creation. Ensure that the integration response is turned off during custom creation. Click Finish to complete function creation and API gateway trigger creation. As shown below:
1.4 If Redis is used to record real-time flow progress, the VPC of cloud functions must be configured on the same private network as Redis because Redis can only be accessed from private networks. As shown below:
2. Create a TRTC application
2.1 Log in to the real-time audio and video console, and choose Development Assistance > Run Demo Quickly in the navigation tree.
2.2 Enter a Demo name and click Create. You can test run the template based on your client.
- Real time audio and video console address: console.cloud.tencent.com/trtc/monito…
3. Test the function
3.1 Constructing AN HTTP Request Using Postman. As shown below:
3.2 After the request is sent, the asynchronous function response “Async Run task Submitted” will be received. The RequstId of this function will be returned through the X-SCf-reqID in the HTTP header information. As shown below:
3.3 On the “Function Service” page of the Cloud Function Console, click the name of the cloud function created in “**1. Create Cloud Function” ** to go to the “Function Details” page and view the printed push flow logs. As shown below:
3.4 Switch to the real-time audio and video console, and click the room ID on the Monitoring Dashboard page to view the monitoring details. As shown below:
3.5 If you want to stop the push flow during the push flow, you can call the InvokeRequestId parameter to stop the push flow (status tracking must be enabled). InvokeRequestId can be obtained from the x-SCF-reqID of the response header in 2. Create a TRTC application.
- Termination function asynchronous events: cloud.tencent.com/document/ap…
05. Application for internal test of “Page recording”
In the article “Real-time Rendering and Recording Convergence using Serverless Cloud Functions and Headless Chrome”, I told everyone about the pain points of recording requirements in online education scenes, and introduced a new solution: Headless Chrome page recording. At present, internal teams are using it. If you also want to participate in the test of this scheme, please click here to complete the internal test form and we will contact you in 1-3 working days. Thank you for your attention and support.
One More Thing
Experience Tencent Cloud Serverless Demo immediately and receive Serverless new user package 👉 Tencent Cloud Serverless novice experience
Welcome to: Serverless Chinese!