To quickly implement the audio call feature, you can use the demo we provide and adapt it to your needs. You can also use the TRTCCalling
component and customize your own UI.
TestAudioCall
, 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 Pricing for its billing details.
/example/lib/debug/GenerateTestUserSig.dart
.GenerateTestUserSig.dart
as follows.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 TRTCCallingDemo
folder in the source code contains two subfolders: ui
and model
. The ui
folder contains the UI code.
File or Folder | Description |
---|---|
TRTCCallingVideo.dart | The main view for audio/video calls, where calls are answered/declined |
TRTCCallingContact.dart | The view for contacts, where one can search for registered users to call |
The TRTCCallingDemo
folder in the source code contains two subfolders: ui
and model
. The model
subfolder contains the reusable open-source component TRTCCalling
. You can find the component's APIs in TRTCCalling.dart
.
You can use the open-source component TRTCCalling
to customize your own UI. This means you will use the model of the demo but design the UI by yourself.
The audio/video call component TRTCCalling
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>
TRTCCalling
componentCopy all the files in model to your project.
/lib/TRTCCallingDemo/model
TRTCCalling.sharedInstance()
to get an instance of the component.login(SDKAppID, userId, userSig)
to log in to the component. For the key parameters passed in, see the table 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 only letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). We recommend that you keep it in line with your user account system. |
userSig | Tencent Cloud's proprietary security signature. For how to calculate and use a signature, please see UserSig. |
// Initialize
sCall = await TRTCCalling.sharedInstance();
sCall.login(1400000123, "userA", "xxxx");
call()
of TRTCCalling
, passing in the user ID of the callee (userid
) and call type (type
). For an audio call, the call type should be TRTCCalling.typeAudioCall
.onInvited()
callback and can start the corresponding view based on the call type set by the inviter, which is represented by callType
in the callback.accept()
to answer the call and openCamera()
to turn the local camera on. He or she can also call reject()
to reject the call.onUserAudioAvailable()
event notification, which indicates that they have received each other’s audio. Remote audio will be played back automatically by default.The table below lists the APIs of the TRTCCalling
component.
API | Description |
---|---|
registerListener | Registers a TRTCCalling listener, through which users can receive status notifications. |
unRegisterListener | Unregisters a listener. |
destroy | Destroys an instance. |
login | Logs in to IM. All features can be used only after login. |
logout | Logs out of IM. Calls cannot be made after logout. |
call | Makes a C2C call. The invitee will receive the onInvited event notification. |
accept | Answers a call. |
reject | Declines a call. |
hangup | Ends a call. |
setMicMute | Mutes/Unmutes the mic. |
setHandsFree | Enables/Disables the hands-free mode. |
Was this page helpful?