To quickly enable the interactive live video streaming feature, you can modify the demo we provide and adapt it to your needs. You can also use the TRTCLiveRoom
component and customize your own UI.
TestLive
and click Create.Note:This feature uses two basic PaaS services of Tencent Cloud, namely TRTC and IM. When you activate TRTC, IM will be activated automatically. IM is a value-added service. See Value-added Service Pricing for its billing details.
In the Modify Configuration step, select your platform.
Find and open /example/lib/debug/GenerateTestUserSig.dart
.
Set parameters in GenerateTestUserSig.dart
as follows.
Click Next to complete the creation.
After compilation, click Return to Overview Page.
Note:
- The method for generating
UserSig
described in this document involves configuringSECRETKEY
in client code. In this method,SECRETKEY
may be easily decompiled and reversed, and if your key is leaked, attackers can steal your Tencent Cloud traffic. Therefore, this method is only suitable for the local execution and debugging of the demo.- The correct
UserSig
distribution method is to integrate the calculation code ofUserSig
into your server and provide an application-oriented API. WhenUserSig
is needed, your application can send a request to the business server for a dynamicUserSig
. For more information, see How do I calculate UserSig on the server?.
Note:An Android project must be run on a real device rather than a simulator.
flutter pub get
.The TRTCLiveRoom
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 |
list | The list and room creation views |
room | Main room views for speakers and listeners |
The TRTCLiveRoom
folder in the source code contains two subfolders: ui
and model
. The model
subfolder contains the reusable open-source component TRTCLiveRoom
. You can find the component's APIs in TRTCLiveRoom.dart
and use them to customize your own UI.
The interactive live streaming component TRTCLiveRoom
depends on the TRTC SDK and IM SDK. You can configure pubspec.yaml
to download their updates automatically.
Add the following dependencies to pubspec.yaml
of your project.
dependencies:
tencent_trtc_cloud: latest version number
tencent_im_sdk_plugin: latest version number
Add request for mic permission in Info.plist
:
<key>NSMicrophoneUsageDescription</key>
<string>Audio calls are possible only with mic access.</string>
TRTCLiveRoom
componentCopy all the files in the directory below to your project:
lib/TRTCLiveRoom/model/
sharedInstance
API to create an instance of the TRTCLiveRoom
component.registerListener
function 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 | You can view `SDKAppID` in the TRTC console. |
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 | Tencent Cloud's proprietary security signature. To obtain one, see UserSig. |
useCDNFirst | Specifies the way audience watch live streams. `true` means that audience watch live streams over CDNs, which is cost-efficient but has high latency. `false` means that audience watch live streams in the low latency mode, the cost of which is between that of CDN live streaming and co-anchoring, but the latency is within 1 second. |
CDNPlayDomain | Specifies the domain name for CDN live streaming, which takes effect only if `useCDNFirst` is set to `true`. You can set it in CSS console > Domain Management. |
setSelfProfile
to set your nickname and profile photo.startCameraPreview
to enable camera preview, add beauty filter buttons to the UI, and set beauty filters through getBeautyManager
.
Note:Only the Enterprise Edition SDK supports face changing and stickers.
createRoom
to create a live streaming room.startPublish
to start streaming. To enable CDN live streaming, specify useCDNFirst
and CDNPlayDomain
in the TRTCLiveRoomConfig
parameter, which is passed in during login, and specify streamID
for playback when calling startPublish
.setSelfProfile
to set your nickname and profile photo.Note:The room list in the demo is for demonstration only. The business logic of live streaming room lists vary significantly. Tencent Cloud does not provide list management services for the time being. Please manage the list by yourself.
getRoomInfos
to get short descriptions of the rooms, which are provided by anchors when they call createRoom
to create the rooms.
Note:If your room list already displays enough information, you can skip the step of calling
getRoomInfos
.
enterRoom
, with the room ID passed in to enter the room.startPlay
, with the anchor’s userId
passed in to start playback.userId
of the anchor, you can call startPlay
, passing in the anchor’s userId
to start playback.userId
, you can find it in the onAnchorEnter
event callback, which you will receive after entering the room. You can then call startPlay
to start playback. requestJoinAnchor
to send a co-anchoring request to the anchor.TRTCLiveRoomDelegate#onRequestJoinAnchor
) about the co-anchoring request.responseJoinAnchor
to accept or decline the co-anchoring request.onAnchorAccepted
event notification, which carries the anchor's response.startCameraPreview
to turn the local camera on and then startPublish
to push streams.TRTCLiveRoomDelegate#onAnchorEnter
) that a new stream is available, which carries the audience’s userId
.startPlay
to play the audience’s video.requestRoomPK
to send a competition request to anchor B.TRTCLiveRoomDelegate onRequestRoomPK
notification.responseRoomPK
to accept or decline the competition request.TRTCLiveRoomDelegate onAnchorEnter
notification, calls startPlay
to play anchor A's video.onRoomPKAccepted
notification, which specifies whether the competition request is accepted.TRTCLiveRoomDelegate onAnchorEnter
notification, anchor A calls startPlay
to play anchor B's video.sendRoomTextMsg
to send common text messages. All users in the room will receive the onRecvRoomTextMsg
callback.// Sender: send text messages
trtcLiveCloud.sendRoomTextMsg("Hello Word!");
// Recipient: listen for text messages
onListenerFunc(type, params) async {
switch (type) {
case TRTCLiveRoomDelegate.onRecvRoomTextMsg:
// Group text messages are received. This feature can be used to enable text chat rooms.
break;
}
}
sendRoomCustomMsg
to send custom (signaling) messages. All users in the room will receive an onRecvRoomCustomMsg
callback.
Was this page helpful?