tencent cloud

Feedback

TRTCCalling APIs (Flutter)

Last updated: 2022-04-08 14:39:00

    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 Video 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.

    Stream pushing/pulling APIs

    API Description
    startRemoteView Renders the camera data of a remote user in the specified TXCloudVideoView.
    stopRemoteView Stops rendering the data of a remote user.

    Audio/Video APIs

    API Description
    openCamera Turns on the camera and renders the camera data in the specified TXCloudVideoView.
    switchCamera Switches between the front and rear cameras.
    closeCamera Turns off the camera.
    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
    onUserVideoAvailable Whether a user is sending video
    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 signature. For more information on how to get it, please see 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();
    

    Stream Pushing/Pulling APIs

    startRemoteView

    This API is used to render the camera data of a remote user in the specified TRTCCloudVideoView.

    void startRemoteView(String userId, int streamType, int viewId);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the remote user
    streamType int Video stream type of the userId specified for stopping watching
    viewId int viewId called back by TRTCCloudVideoView, the control that carries the video image

    stopRemoteView

    This API is used to stop rendering the data of a remote user.

    void stopRemoteView(String userId, int streamType);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the remote user
    streamType int Type of video stream of the specified userId to stop rendering

    Audio/Video APIs

    openCamera

    This API is used to turn on the camera and render data in the specified TRTCCloudVideoView.

    void openCamera(bool isFrontCamera, int viewId);
    

    The parameters are as detailed below:

    Parameter Type Description
    isFrontCamera bool true: turns on the front camera; false: turns on the rear camera.
    viewId int viewId returned by TRTCCloudVideoView, the class that loads video images

    switchCamera

    This API is used to switch between the front and rear cameras.

    void switchCamera(bool isFrontCamera);
    

    The parameters are as detailed below:

    Parameter Type Description
    isFrontCamera bool true: switches to the front camera; false: switches to the rear camera.

    closeCamara

    This API is used to turn the camera off.

    void closeCamera();
    

    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

    onUserVideoAvailable

    Whether a user is sending video. After receiving this callback, you can call startRemoteView to render the remote user's video.

    The parameters are as detailed below:

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

    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