tencent cloud

Feedback

TRTCCalling APIs (Flutter)

Last updated: 2022-03-17 15:50:50

    TRTCCalling is an open-source class based on two closed-source SDKs: Tencent Cloud Real-Time Communication (TRTC) and Instant Messaging (IM). It supports one-to-one audio/video calls. For detailed instructions how to implement it, please see Real-Time Audio Call (Flutter).

    • TRTC SDK: the TRTC SDK is used as a low-latency audio/video call component.
    • IM SDK: the IM SDK is used to send and process signaling messages.

    `TRTCCalling` API Overview

    Basic SDK APIs

    API Description
    sharedInstance Gets a singleton.
    destroySharedInstance Destroys a singleton.
    registerListener Registers an event listener.
    unRegisterListener Unregisters an event listener.
    destroy Destroys an instance that is no longer needed.
    login Logs in. All features can be used only after login.
    logout Logs out. No calls can be made after logout.

    Call operation APIs

    API Description
    call Makes a one-to-one call.
    accept Accepts the current call.
    reject Declines the current call.
    hangup Ends the current call.

    Audio control APIs

    API Description
    setMicMute Mutes the local mic.
    setHandsFree Enables the hands-free mode.

    `TRTCCallingDelegate` API Overview

    Common event callback APIs

    API Description
    onError Callback for error.

    Inviter callback APIs

    API Description
    onReject The call was declined.
    onNoResp The invitee did not answer.
    onLineBusy The line is busy.

    Invitee callback APIs

    API Description
    onInvited An invitation was received.
    onCallingCancel The call was canceled.
    onCallingTimeOut The call timed out.

    General callback APIs

    API Description
    onUserEnter A user joined the call.
    onUserLeave A user left the call.
    onUserAudioAvailable Whether a user is sending audio
    onUserVoiceVolume Call volume of the user
    onCallEnd The call ended.

    Basic SDK APIs

    sharedInstance

    This API is used to get a singleton of the TRTCCalling component.

    static Future<TRTCCalling> sharedInstance();
    

    destroySharedInstance

    This API is used to destroy a singleton of the TRTCCalling component.

    static void destroySharedInstance();
    

    destroy

    This API is used to destroy an instance that is no longer needed.

    void destroy();
    

    registerListener

    This API is used to register callbacks for TRTCCalling events. You can receive status notifications of TRTCCalling via TRTCCallingDelegate.

    void registerListener(VoiceListenerFunc func);
    

    unRegisterListener

    This API is used to unregister event callbacks.

    void unRegisterListener(VoiceListenerFunc func);
    

    login

    This API is used to log in to the component.

    Future<ActionCallback> login(int sdkAppId, String userId, String userSig);
    

    The parameters are as detailed below:

    Parameter Type Description
    sdkAppID int You can view the SDKAppID via Application Management > Application Info in the TRTC console.
    userId String 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 (_).
    userSig String Tencent Cloud's proprietary security protection signature. For more information on how to get it, please see How to Calculate UserSig.

    logout

    This API is used to log out of the component.

    Future<ActionCallback> logout();
    

    Call Operation APIs

    call

    This API is used to make a one-to-one call. It can be called during a call to invite more users.

    Future<ActionCallback> call(String userId, int type);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID of the callee
    type int 1: audio call; 2: video call

    accept

    This API is used to accept the current call. After receiving the onInvited() callback, the invitee can call this API to accept the call.

    Future<ActionCallback> accept();
    

    reject

    This API is used to decline the current call. After receiving the onInvited() callback, the invitee can call this API to decline the call.

    Future<ActionCallback> reject();
    

    hangup

    This API is used to end the current call.

    void hangup();
    

    Audio Control APIs

    setMicMute

    This API is used to mute the local mic.

    void setMicMute(bool isMute);
    

    The parameters are as detailed below:

    Parameter Type Description
    isMute bool true: mutes the mic; false: unmutes the mic.

    setHandsFree

    This API is used to enable the hands-free mode.

    void setHandsFree(bool isHandsFree);
    

    The parameters are as detailed below:

    Parameter Type Description
    isHandsFree bool true: enables the hands-free mode; false: disables the hands-free mode.

    TRTCCallingDelegate Callback APIs

    Common Event Callback APIs

    onError

    Callback for error.

    Note:

    This callback indicates that the SDK encountered an unrecoverable error. Such errors must be listened for, and UI reminders should be sent to users if necessary.

    The parameters are as detailed below:

    Parameter Type Description
    code int Error code
    msg String Error message

    Inviter Callback APIs

    onReject

    The call was declined.

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID of the invitee who declined the call

    onNoResp

    The invitee did not answer.

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID of the invitee who did not answer

    onLineBusy

    The line is busy.

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID of the invitee whose line is busy

    Invitee Callback APIs

    onInvited

    A call invitation was received.

    The parameters are as detailed below:

    Parameter Type Description
    sponsor String User ID of the inviter
    userIds List<String> IDs of other users invited
    isFromGroup bool Whether it is a group call
    type int 1: audio call; 2: video call

    onCallingCancel

    The call was canceled. The invitee will receive this callback if the inviter cancels the invitation before he or she handles it.

    onCallingTimeOut

    The call timed out.

    General Callback APIs

    onUserEnter

    A user joined the call.

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user who joined the call

    onUserLeave

    A user left the call.

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user who left the call

    onUserAudioAvailable

    Whether a user is sending audio.

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID
    available boolean Whether the user has available audio

    onUserVoiceVolume

    Call volume of a user.

    The parameters are as detailed below:

    Parameter Type Description
    userVolumes List Volume of every speaking user in the room. Value range: 0-100.
    totalVolume int Total volume of all remote users. Value range: 0-100.

    onCallEnd

    The call ended.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support