TRTCVideoCall APIs (Android)

Last updated: 2021-10-27 12:00:22

    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 and group video calls. For detailed instructions how to implement it, see Real-Time Video Call (Android).

    • 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.
    addDelegate Registers an event listener.
    removeDelegate 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.
    groupCall Makes a group chat 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
    onGroupCallInviteeListUpdate The group chat invitee list was updated.
    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.

    public static ITRTCCalling sharedInstance(Context context);
    

    destroySharedInstance

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

    public static void destroySharedInstance();
    

    destroy

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

    void destroy();
    

    addDelegate

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

    public abstract void addDelegate(TRTCCallingDelegate delegate);
    
    Note:

    TRTCCallingDelegate is the delegate callback of TRTCCalling.

    removeListener

    This API is used to unregister event callbacks.

    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 int You can view the SDKAppID via Application Management > Application Info in the TRTC console.
    user 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.
    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 during a call to invite more users.

    void 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

    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&dxlt;String&dxgt; 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. After receiving the onInvited() callback, the invitee can call this API to accept the call.

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

    void 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 remote user in the specified TXCloudVideoView.

    void startRemoteView(String userId, TXCloudVideoView txCloudVideoView);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the remote user
    view TXCloudVideoView Control that carries the video image

    stopRemoteView

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

    void stopRemoteView(String userId);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the remote user

    Audio/Video APIs

    openCamera

    This API is used to enable camera and render data in the specified TXCloudVideoView.

    void openCamera(boolean isFrontCamera, TXCloudVideoView txCloudVideoView);
    

    The parameters are as detailed below:

    Parameter Type Description
    isFrontCamera boolean true: turns the front camera on; false: turns the rear camera on.
    txCloudVideoView TXCloudVideoView Control that carries the video image.

    switchCamera

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

    void switchCamera(boolean isFrontCamera);
    

    The parameters are as detailed below:

    Parameter Type Description
    isFrontCamera boolean true: switches to front camera; false: switches to 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(boolean isMute);
    

    The parameters are as detailed below:

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

    setHandsFree

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

    void setHandsFree(boolean isHandsFree);
    

    The parameters are as detailed below:

    Parameter Type Description
    isHandsFree boolean 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.

    void onError(int code, String msg);
    

    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.

    void onReject(String userId);
    

    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.

    void onNoResp(String userId);
    

    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.

    void onLineBusy(String userId);
    

    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.

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

    The parameters are as detailed below:

    Parameter Type Description
    sponsor String User ID of the inviter
    userIdList List&dxlt;String&dxgt; IDs of other users invited
    isFromGroup boolean Whether it is a group call
    callType 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.

    void onCallingCancel();
    

    onCallingTimeOut

    The call timed out.

    void onCallingTimeout();
    

    General Callback APIs

    onGroupCallInviteeListUpdate

    The group chat invitee list was updated.

    void onGroupCallInviteeListUpdate(List<String> userIdList);
    

    The parameters are as detailed below:

    Parameter Type Description
    userIdList List&dxlt;String&dxgt; Invitee ID list.

    onUserEnter

    A user joined the call.

    void onUserEnter(String userId);
    

    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.

    void onUserLeave(String userId);
    

    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.

    void onUserAudioAvailable(String userId, boolean available);
    

    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 the notification, the user can call startRemoteView to render the remote video image.

    void onUserVideoAvailable(String userId, boolean available);
    

    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.

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

    The parameters are as detailed below:

    Parameter Type Description
    volumeMap Map&dxlt;String, Integer&dxgt; Volume table. The corresponding volume can be obtained by each userid. The volume ranges from 0 to 100.

    onCallEnd

    The call ended.

    void onCallEnd();