TRTCCalling API (Android)

Last updated: 2020-09-22 15:09:51

    TRTCCalling supports one-to-one and group audio calls based on Tencent Real-Time Communication (TRTC) and Instant Messaging (IM). It is an open-source class depending on two closed-source Tencent Cloud SDKs. For the specific implementation process, please see Android.

    • TRTC SDK: the TRTC SDK is used as the 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 component singleton.
    destroySharedInstance Terminates component singleton.
    addDelegate Adds event callback.
    removeDelegate Removes callback.
    destroy Terminates instance when it is no longer needed.
    login Logs in. All other features can be used only after login.
    logout Logs out. Calls cannot be made after logout.

    Call operation APIs

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

    Audio control APIs

    API Description
    setMicMute Mutes local audio capturing.
    setHandsFree Sets hands-free mode.

    TRTCCallingDelegate API Overview

    General event callbacks

    API Description
    onError Callback for error.

    Inviter callbacks

    API Description
    onReject Callback for declined call.
    onNoResp Callback for no answer.
    onLineBusy Callback for busy line.

    Invitee callbacks

    API Description
    onInvited Callback for received call.
    onCallingCancel Callback for current call cancellation.
    onCallingTimeOut Callback for current call timeout.

    General callbacks

    API Description
    onGroupCallInviteeListUpdate Callback for group chat invitee list update.
    onUserEnter Callback for user entering call.
    onUserLeave Callback for user leaving call.
    onUserAudioAvailable Callback for whether audio upstreaming is enabled.
    onUserVoiceVolume Callback for user call volume level.
    onCallEnd Callback for call end.

    Basic SDK APIs

    sharedInstance

    sharedInstance is the component singleton of TRTCCalling.

    public static ITRTCCalling sharedInstance(Context context);

    destroySharedInstance

    This API is used to terminate the component singleton.

    public static void destroySharedInstance();

    destroy

    This API is used to terminate the instance when it is no longer needed.

    void destroy();

    addDelegate

    This API is used to get the event callback of TRTCCalling. You can use TRTCCallingDelegate to get various status notifications of TRTCCalling.

    public abstract void addDelegate(TRTCCallingDelegate delegate);

    Note:

    TRTCCallingDelegate is the delegation callback of TRTCCalling.

    removeListener

    This API is used to remove the callback.

    void removeDelegate(TRTCCallingDelegate listener);

    login

    This API is used to log in to the component.

    void login( int sdkAppId,
                final String userId, 
                String userSign, 
                final ActionCallBack callback);

    The parameters are as detailed below:

    Parameter Type Description
    sdkAppID UInt32 You can view the SDKAppID in the TRTC Console > Application Management > "Application Info".
    user String ID of 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.
    callback ActionCallBack Callback for login. onSuccess indicates a login success.

    logout

    This API is used to log out of the component.

    void logout(final ActionCallBack callBack);

    The parameters are as detailed below:

    Parameter Type Description
    callBack ActionCallBack Callback for logout. onSuccess indicates a logout success.

    Call Operation APIs

    call

    This API is used to make a one-to-one call. It can be called in an ongoing call to invite another user.

    void call(String userId, int type);

    The parameters are as detailed below:

    Parameter Type Description
    userId String Caller ID.
    type int 1: audio call; 2: video call.

    groupCall

    This API is used to make an IM group call. Invitees will receive the onInvited() callback. This API can be called in an ongoing call to invite other users, and existing users in the call will receive the onGroupCallInviteeListUpdate() callback.

    void groupCall(List<String> userIdList, int type, String groupId);

    The parameters are as detailed below:

    Parameter Type Description
    userIdList List<String> Invitee ID list.
    type int 1: audio call; 2: video call.
    groupId String Group ID.

    accept

    This API is used to accept the current call. The invitee can call it to accept the call when receiving the onInvited() callback.

    void accept();

    reject

    This API is used to decline the current call. The invitee can call it to decline the call when receiving the onInvited() callback.

    void reject();

    hangup

    This API is used to end the current call. It can be called during an ongoing call to end it.

    void hangup();

    Audio Control APIs

    setMicMute

    This API is used to mute the local audio capturing.

    void setMicMute(boolean isMute);

    The parameters are as detailed below:

    Parameter Type Description
    isMute boolean true: disables mic; false: enables mic.

    setHandsFree

    This API is used to mute the remote audio.

    void setHandsFree(boolean isHandsFree);

    The parameters are as detailed below:

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

    TRTCCallingDelegate Event Callback

    General Event Callbacks

    onError

    Callback for error.

    Note:

    The SDK encountered an irrecoverable error and must be listened on. Corresponding UI reminders should be displayed based on the actual conditions.

    void onError(int code, String msg);

    The parameters are as detailed below:

    Parameter Type Description
    code int Error code.
    msg String Error message.

    Inviter Callbacks

    onReject

    Callback for declined call.

    void onReject(String userId);

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user who declines the call.

    onNoResp

    Callback for no answer.

    void onNoResp(String userId);

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user who does not answer.

    onLineBusy

    Callback for busy line.

    void onLineBusy(String userId);

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user whose line is busy.

    Invitee Callbacks

    onInvited

    Callback for received call.

    void onInvited(String sponsor, List<String> userIdList, boolean isFromGroup, int callType);

    The parameters are as detailed below:

    Parameter Type Description
    sponsor String Caller ID.
    userIds List<String> List of invitee IDs except the local user.
    isFromGroup boolean Whether it is a group call invitation.
    type int 1: audio call; 2: video call.

    onCallingCancel

    Callback for current call cancellation. The invitee will receive this callback if the invitee does not process the request and then the inviter cancels the request.

    void onCallingCancel();

    onCallingTimeOut

    Callback for current call timeout.

    void onCallingTimeout();

    General Callbacks

    onGroupCallInviteeListUpdate

    Callback for group chat invitee list update.

    void onGroupCallInviteeListUpdate(List<String> userIdList);

    The parameters are as detailed below:

    Parameter Type Description
    userIdList List<String> Invitee ID list.

    onUserEnter

    Callback for user entering call.

    void onUserEnter(String userId);

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user who enters the call.

    onUserLeave

    Callback for user leaving call.

    void onUserLeave(String userId);

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user who leaves the call.

    onUserAudioAvailable

    Callback for whether audio upstreaming is enabled.

    void onUserAudioAvailable(String userId, boolean available);

    The parameters are as detailed below:

    Parameter Type Description
    userId String In-call user ID.
    available boolean Whether user audio is available.

    onUserVoiceVolume

    Callback for user call volume level.

    void onUserVoiceVolume(Map<String, Integer> volumeMap);

    The parameters are as detailed below:

    Parameter Type Description
    volumeMap Map<String, Integer> Volume level table. The corresponding volume level can be obtained by each userid. The volume level ranges from 0 to 100.

    onCallEnd

    Callback for call end.

    void onCallEnd();