Interactive Gaming API

Interactive Gaming API

This documentation is provided for the Java language with the following classes:

RtcEngineForGaming Interface Class

Create an RtcEngine Object (create)

public static RtcEngine create(Context context,
                               String appId,
                               IRtcEngineEventHandlerForGamingForGaming handler);

This method creates an RtcEngine object.

The Agora Native SDK supports one RtcEngine instance at a time, therefore the application should create one RtcEngine object only. Unless otherwise specified, all call methods provided by the RtcEngine class are executed asynchronously. It is recommended to call the interface methods in the same thread. Unless otherwise specified, the following rule applies to all APIs whose return values are integer types: A return value of 0 indicates that the call was successful, and a return value less than 0 indicates that the call failed.

Name Description
context Context of the Android activity.
appId App ID, see Get an App ID for details
handler IRtcEngineEventHandlerForGaming is an abstract class that provides default implementations. The SDK uses this class to report to the application on SDK runtime events.
Return Value An RtcEngine object.

Set the Channel Profile (setChannelProfile)

public int setChannelProfile (int profile);

This method configures the channel profile. The Agora RtcEngine needs to know what scenario the application is in to apply different methods for optimization.

Note

  • Use one profile at the same time in the same channel.
  • This method must be called and configured before a user joins a channel because the channel profile cannot be configured when the channel is in use.
Name Description
profile

Channel profile. Choose from one of the following:

  • CHANNEL_PROFILE_GAME_FREE_MODE = 2: Free Mode
  • CHANNEL_PROFILE_GAME_COMMAND_MODE = 3; Command Mode
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Set the User Role (setClientRole)

public int setClientRole (int role, String permissionkey);

This method allows you to set the user role before joining a channel or switch the user role after joining a channel.

Note

This method is only applicable when you set the channel profile as command mode when calling setChannelProfile.

Name Description
role

User role in a command-mode channel:

  • CLIENT_ROLE_BROADCASTER = 1; Host
  • CLIENT_ROLE_AUDIENCE = 2; Audience(default)

Once set, only the host in the channel can talk, not the audience.

permissionKey Set as NULL
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Join a Channel (joinChannel)

public synchronized int joinChannel(String channelName, String info, int uid);

This method allows the user to join a channel. If a channel is not created, this method creates a channel automatically.

Users in the same channel can talk to each other; and multiple users in the same channel can start a group chat. Users using different App IDs cannot call each other. Once in a call, the user must call the leaveChannel() method to exit the current call before entering another channel.

Note

The uid must not be the same as other users in the same channel, otherwise the services for the other users with the same uids in the channel will be stopped.

Name Description
channelName

A string providing the unique channel name for the AgoraRTC session. The length must be within 64 bytes.

Supported format: a-z,A-Z,0-9,space,!

#$%&,()+,

-,:;<=.,>?

@[],^_,{|},~

info (Optional) Additional information about the channel. Other users in the channel will not receive this information.
uid

(Optional) The user ID: A 32-bit unsigned integer ranging from 1 to (2^32-1). It must be unique. If not assigned (or set to 0), the SDK will assign one and return it in the onJoinChannelSuccess callback. The app needs to record and maintain the returned value as the SDK does not maintain it.

The uid is represented as a 32-bit unsigned integer in the SDK. Since unsigned integers are not supported in Java, the uid is handled as a 32-bit signed integer and larger numbers will be interpreted as negative numbers in Java. If necessary, the uid can be converted to a 64-bit integer via “uid&0xffffffffL”.

Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Join a Channel With a Key (joinChannel)

public synchronized int joinChannel(String channelKey, String channelName, String info, int uid);

This method provides the same function as the Join a Channel (joinChannel) method, with the only difference that this method requires a Channel Key. In most cases, the Join a Channel (joinChannel) method will suffice. For added security, use this method with a Channel Key.

Name Description
channelKey For how to get a channel key, see Security Keys.
channelName

A string providing the unique channel name for the AgoraRTC session. The length must be within 64 bytes.

Supported characters: a-z,A-Z,0-9,space,!

#$%&,()+,

-,:;<=.,>?

@[],^_,{|},~

info (Optional) Additional information about the channel. Other users in the channel will not receive this information.
uid (Optional) User ID: A 32-bit unsigned integer ranging from 1 to (2^32-1). It must be unique. If not assigned (or set to 0), the SDK will assign one and return it in the onJoinChannelSuccess callback. The app needs to record and maintain the returned value as the SDK does not maintain it.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Renew the Channel Key (renewChannelKey)

public override int renewChannelKey (string channelKey);

The Channel Key expires after a certain period of time once the Channel Key is enabled. The onRequestChannelKey callback is triggered to retrieve a new key, then call this method to renew it. Failure to do so will result in the SDK disconnecting from the server.

Name Description
channelKey Specifies the Channel key to be renewed.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Leave a Channel (leaveChannel)

public int leaveChannel();

This method lets the user leave a channel (hang up or exit a call).

After joining a channel, the user must call the leaveChannel() method to end the call before joining another one. The leaveChannel method releases all resources related to the call. The leaveChannel() method is called asynchronously, and the user actually does not exit the channel when the call returns. Once the user exits the channel, the SDK triggers the onLeaveChannel callback.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Enable the Audio Mode (enableAudio)

public int enableAudio();

This method enables the audio mode.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Disable the Audio Mode (disableAudio)

public int disableAudio();

This method disables the audio mode.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Specify the Log File (setLogFile)

public int setLogFile (String filePath);

This method specifies the SDK output log file. The log file records all the log data of the SDK’s operation. Ensure that the saving directory in the application exists and is writable.

Name Description
filePath Full file path of the log file. The string of the log file is in UTF-8 code.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Set the Log Filter (setLogFilter)

public int setLogFilter (int filter);

This method sets the SDK output log filter. Use one or a combination of the filters.

Name Description
filter

Set the levels of the filters:

  • LOG_FILTER_OFF = 0;
  • LOG_FILTER_CRITICAL = 0x0008;
  • LOG_FILTER_ERROR = 0x000c;
  • LOG_FILTER_WARN = 0x000e;
  • LOG_FILTER_INFO = 0x000f;
  • LOG_FILTER_CRITICAL = 0x080f;
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Set the Default Audio Route (setDefaultAudioRouteToSpeakerphone)

public int setDefaultAudioRouteToSpeakerphone(boolean defaultToSpeaker);

This method modifies the default audio route (speakerphone) if necessary.

Note

This method only works in audio mode.

Name Description
defaultToSpeaker
  • True: Default audio route is changed to the speakerphone.
  • False: Default audio route is changed to the earpiece.

No matter whether the audio is routed to the speakerphone or earpiece, once a headset is plugged in or bluetooth is connected,

the audio route will be changed. The audio is switched back to the default audio route once removing the headset or disconnecting bluetooth.

Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Enable the Speakerphone (setEnableSpeakerphone)

public int setEnableSpeakerphone( boolean enabled );

This method enables the audio routing to the speakerphone.

After calling this method, the SDK will return the onAudioRouteChanged callback to indicate the changes.

Note

Ensure that you have read the default audio route explanation according to Set the Default Audio Route (setDefaultAudioRouteToSpeakerphone) and checked whether it is necessary to call this method.

Name Description
enabled
  • True:
    • If this API is called after joining a channel, whether the audio was routed to the headset, Bluetooth device, or earpiece, it will be routed to the speaker.
    • If this API is called before joining a channel, when joining a channel, the audio will be routed to the speaker whether the user uses a headset or Bluetooth device.
  • False: The audio will follow the default audio route mentioned in Set the Default Audio Route (setDefaultAudioRouteToSpeakerphone).
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Check Whether the Speakerphone is Enabled (isSpeakerphoneEnabled)

public boolean isSpeakerphoneEnabled();

This method checks whether the speakerphone is enabled.

Name Description
isSpeakerphoneEnabled
  • True: Speakerphone is enabled.
  • False: Speakerphone is disabled.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Set the Speakerphone Volume (setSpeakerphoneVolume)

public int setSpeakerphoneVolume(int volume);
Name Description
volume Sets the speakerphone volume between 0 (lowest) to 255 (highest).
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Enable the Audio Volume Indication (enableAudioVolumeIndication)

public int enableAudioVolumeIndication (int interval, int smooth);

This method enables the SDK to regularly report to the application on which user is talking and the volume of the speaker.

Name Description
interval

Specifies the time interval between two consecutive volume indications.

  • <=0 : Disables the volume indication.
  • >0: Volume indication interval (ms). Recommended to set it to a minimum of 200 ms.
smooth Smoothing factor. Recommended default value is 3.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Mute the Local Audio Stream (muteLocalAudioStream)

public int muteLocalAudioStream (boolean muted);

This method enables/disables sending local audio streams to the network.

Note

When set to True, this method does not disable the microphone and thus does not affect any ongoing recording.

Name Description
muted
  • True: Stops sending local audio streams to the network.
  • False: Allows sending local audio streams to the network.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Mute all Remote Audio Streams (muteAllRemoteAudioStreams)

public int muteAllRemoteAudioStreams (boolean mute);

This method mutes/unmutes all remote users’ audio streams.

Name Description
muted
  • True: Mutes all received audio streams.
  • False: Unmutes all received audio streams.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Mute a Remote Audio Stream (muteRemoteAudioStream)

public int muteRemoteAudioStream (int uid, boolean mute);

This method mutes/unmutes a specified user’s audio stream.

Note

When set to True, this method mutes the audio stream without affecting the audio stream receiving process.

Name Description
uid User ID of the user whose audio stream is to be muted.
mute
  • True: Mutes the user’s audio stream.
  • False: Unmutes the user’s audio stream.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Start an Audio Recording (startAudioRecording)

public int startAudioRecording( String filePath, int quality );

This method starts an audio recording. The SDK allows recording during a call, which supports either one of the following two formats:

  • .wav: Large file size with high sound fidelity OR
  • .aac: Small file size with low sound fidelity

Ensure that the directory to save the recording file exists and is writable. This method is usually called after the joinChannel() method. The recording automatically stops when the leaveChannel() method is called.

Name Description
filePath File path of the recording file. The string of the file name is in UTF-8 code.
quality

Audio recording quality:

  • AUDIO_RECORDING_QUALITY_LOW = 0: Low quality, file size is around 1.2 MB after 10 minutes of recording
  • AUDIO_RECORDING_QUALITY_MEDIUM = 1: Medium quality, file size is around 2B M after 10 minutes of recording
  • AUDIO_RECORDING_QUALITY_HIGH = 2: High quality, file size is around 3.75 MB after 10 minutes of recording
Return Value
  • 0: Method call succeeded
  • <0: Method call failed

Stop Audio Recording (stopAudioRecording)

public int stopAudioRecording();

This method stops recording on the client. Call this method before calling leaveChannel, otherwise the recording automatically stops when the leaveChannel method is called.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Start Audio Mixing (startAudioMixing)

public int startAudioMixing (String filePath,
                             boolean loopback,
                             boolean replace,
                             int cycle
                             int playTime);

This method mixes the specified local audio file with the audio stream from the microphone; or, it replaces the microphone’s audio stream with the specified local audio file. You can choose whether the other user can hear the local audio playback and specify the number of loop playbacks.

Note

  • If you want to use this API, ensure that Android device version is 4.2 or later, and the API version is 16 or later.
  • Call this API when you are in the channel, otherwise it may cause issues.
Name Description
filePath

Name and path of the local audio file to be mixed:

  • If the path begins with /assets/, find the audio file in the /assets/ directory.
  • Otherwise, find the audio file in the absolute path.

Supported audio formats: mp3, aac, m4a, 3gp, wav, and flac.

loopback
  • True: Only the local user can hear the remix or the replaced audio stream.
  • False: Both users can hear the remix or the replaced audio stream.
replace
  • True: The content of the local audio file replaces the audio stream from the microphone.
  • False: Mix the content of the local audio file with the audio stream from the microphone.
cycle

Number of loop playbacks:

  • Positive integer: Number of loop playbacks
  • -1: Infinite loop
playTime

Start time (ms) of the audio file to play

0: Start from the beginning.

Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Stop Audio Mixing (stopAudioMixing)

public int stopAudioMixing();

This method stops audio mixing. Call this API when you are in the channel.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Pause Audio Mixing (pauseAudioMixing)

public int pauseAudioMixing();

This method pauses mixing the specified local audio with the microphone input. Call this API when you are in the channel.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Resume Audio Mixing (resumeAudioMixing)

public int resumeAudioMixing();

This method resumes mixing the specified local audio with the microphone input. Call this API when you are in the channel.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Adjust the Audio Mixing Volume (adjustAudioMixingVolume)

public int adjustAudioMixingVolume(int volume);

This method adjusts the audio volume during audio mixing. Call this API when you are in the channel.

Name Description
volume Volume ranging from 0 to 100. By default, 100 is the original volume.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Get the Audio Mixing Duration (getAudioMixingDuration)

public int getAudioMixingDuration();

This method gets the duration (ms) of the audio mixing. Call this API when you are in the channel.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Get the Current Audio Position (getAudioMixingCurrentPosition)

public int getAudioMixingCurrentPosition();

This method gets the playback position (ms) of the audio. Call this API when you are in the channel.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Adjust the Recording Volume (adjustRecordingSignalVolume)

public int adjustRecordingSignalVolume(int volume);

This method adjusts the recording volume.

Name Description
volume

Recording volume, ranging from 0 to 400:

  • 0: Mute
  • 100: Original volume
  • 400: (Maximum) Four times the original volume with heap overflow protection
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Adjust the Playback Volume (adjustPlaybackSignalVolume)

public int adjustPlaybackSignalVolume(int volume);

This method adjusts the playback volume.

Name Description
volume

Playback volume, ranging from 0 to 400:

  • 0: Mute
  • 100: Original volume
  • 400: (Maximum) Four times the original volume with heap overflow protection
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Get the Audio Effect Manager (getAudioEffectManager)

public IAudioEffectManager getAudioEffectManager();

This method gets the IAudioEffectManager object associated with the current RTC engine.

Get the SDK Version (getSdkVersion)

public static String getSdkVersion();

This method returns the string of the SDK version number.

Get the Media Engine Version (getMediaEngineVersion)

public static String getMediaEngineVersion();

This method returns the media engine version number.

Get the Error Description (getErrorDescription)

public static String getErrorDescription(int error);

This method gets the error description.

Name Description
error Warning code or error code returned in onWarning or onError.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

IAudioEffectManager Interface Class

Get the Audio Effect Volume (getEffectsVolume)

double getEffectsVolume();

This method gets the volume of the audio effects from 0.0 to 1.0.

Set the Audio Effect Volume (setEffectsVolume)

public int setEffectsVolume(double volume);

This method sets the volume of the audio effects.

Name Description
volume Value ranges from 0.0 to 100.0. 100.0 is the default value.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Play the Audio Effect (playEffect)

public int playEffect(int soundId, String filePath, boolean loop, double pitch, double pan, double gain);

This method plays the audio effect.

Name Description
soundId ID of the audio effect. Each audio effect has a unique ID. [1]
filePath Absolute path of the audio effect file.
loop

Sets whether to play the audio effect in loops:

  • True: Yes
  • False: No (default)
pitch

Sets whether to change the volume of the audio effect.

The range is [0.5, 2] with 1.0 as the default value, which means no need to change the volume.

The smaller the value is set, the lower the volume will be.

pan

Sets whether to change the spatial position of the audio effect. The range is [-1, 1]:

  • 0: The audio effect shows right ahead.
  • -1: The audio effect shows on the left.
  • 1: The audio effect shows on the right.
gain

Sets whether to change the volume of a single audio effect. The range is [0.0, 100.0].

The default value is 100.0. The smaller the number, the lower the volume of the audio effect.

Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Footnotes

[1]If the audio effect is loaded into the memory through preloadEffect, ensure that the soundId set is the same as in preloadEffect.

Stop Playing the Audio Effect (stopEffect)

public int stopEffect(int soundId);

This method stops playing a specific audio effect.

Name Description
soundId ID of the audio effect. Each audio effect has a unique ID.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Stop Playing all Audio Effects (stopAllEffects)

public int stopAllEffects();

This method stops playing all audio effects.

Preload the Audio Effect (preloadEffect)

public int preloadEffect(int soundId, String filePath);

This method preloads a specific audio effect file (compressed audio file) in the memory.

Name Description
soundId ID of the audio effect. Each audio effect has a unique ID.
filePath Absolute path of the audio effect file.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Release the Audio Effect (unloadEffect)

public int unloadEffect(int soundId);

This method releases the specific preloaded audio effect from the memory.

Name Description
soundId ID of the audio effect. Each audio effect has a unique ID.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Pause the Audio Effect (pauseEffect)

public int pauseEffect(int soundId);

This method pauses the specific audio effect.

Name Description
soundId ID of the audio effect. Each audio effect has a unique ID.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Pause all Audio Effects (pauseAllEffects)

public int pauseAllEffects();

This method pauses all audio effects.

Name Description
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Resume the Audio Effect (resumeEffect)

public int resumeEffect(int soundId);

This method resumes playing a specific audio effect.

Name Description
soundId ID of the audio effect. Each audio effect has a unique ID.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Resume all Audio Effects (resumeAllEffects)

public int resumeAllEffects();

This method resumes all audio effects.

Set to Voice-only Mode (setVoiceOnlyMode)

public int setVoiceOnlyMode(boolean enable);

This method sets to voice-only mode (transmit the audio stream only), and the other streams will be ignored; for example the sound of the keyboard strokes.

Note

This API will be available starting in Agora Gaming SDK v2.1.

Name Description
enable

True: Enable voice-only mode.

False: Disable voice-only mode.

Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Set the Voice Position of the Remote User (setRemoteVoicePosition)

public int setRemoteVoicePosition(int uid, double pan, double gain);

Sets the voice position of the remote user.

Note

  • This API will be available starting in Agora Gaming SDK v2.1.
  • This API is valid only for earphones, and is invalid when the speakerphone is enabled.
Name Description
uid User ID of the remote user.
pan

Sets whether to change the spatial position of the audio effect. The range is [-1, 1]:

  • 0: The audio effect shows right ahead.
  • -1: The audio effect shows on the left.
  • 1: The audio effect shows on the right.
gain

Sets whether to change the volume of a single audio effect. The range is [0.0, 100.0]

The default value is 100.0. The smaller the number is, the lower the volume of the audio effect.

Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

Set the Local Voice Pitch (setLocalVoicePitch)

public int setLocalVoicePitch(double pitch);

This method changes the voice pitch of the local speaker.

Note

This API will be available starting in Agora Gaming SDK v2.1.

Name Description
pitch Voice frequency in the range of [0.5, 2.0]. The default value is 1.0.
Return Value
  • 0: Method call succeeded.
  • <0: Method call failed.

IRtcEngineEventHandlerForGaming Abstract Class

Join Channel Callback (onJoinChannelSuccess)

public void onJoinChannelSuccess(String channel, int uid, int elapsed);

This callback indicates that the user has successfully joined the specified channel with a Channel Name and User ID assigned. The channel ID is assigned based on the channel name specified in the join() API. If the User ID is not specified when join() is called, the server assigns one automatically.

Name Description
channel Channel Name.
uid

User ID.

If the uid is specified in the joinChannel method, it returns the specified ID; if not, it returns an ID that is automatically assigned by the Agora server.

elapsed Time elapsed (ms) from calling joinChannel until this event occurs.

Rejoin Channel Callback (onRejoinChannelSuccess)

public void onRejoinChannelSuccess(String channel, int uid, int elapsed);

When the client loses connection with the server because of network problems, the SDK automatically attempts to reconnect, and then triggers this callback method upon reconnection.

Name Description
channel Channel Name.
uid

User ID.

If the UID is specified in the joinChannel method, it returns the specified ID;

If not, it returns an ID that is automatically assigned by the Agora server.

elapsed Time elapsed (ms) from calling joinChannel until this event occurs.

Warning Occurred Callback (onWarning)

public void onWarning(int warn);

This callback indicates that some warning occurred during SDK runtime. In most cases, the application can ignore the warnings reported by the SDK because the SDK can usually fix the issue and resume running. For instance, the SDK may report an ERR_OPEN_CHANNEL_TIMEOUT warning upon disconnection with the server and attempts to reconnect.

Name Description
warn Warning code.
msg Warning message.

Error Occurred Callback (onError)

public void onError(int err);

This callback indicates that a network or media error occurred during SDK runtime.

In most cases, reporting an error means that the SDK cannot fix the issue and resume running, and therefore requires actions from the application or simply informs the user on the issue. For instance, the SDK reports an ERR_START_CALL error when failing to initialize a call. In this case, the application informs the user that the call initialization failed, and calls the leaveChannel method to exit the channel.

Name Description
err Error codes.

Audio Quality Callback (onAudioQuality)

public void onAudioQuality(int uid, int quality, short delay, short lost);

During a call, this callback is triggered once every two seconds to report on the audio quality of the current call. By default it is enabled.

Name Description
uid User ID of the speaker
quality

Rating of the audio quality of the user:

  • QUALITY_EXCELLENT( = 1)
  • QUALITY_GOOD( = 2)
  • QUALITY_POOR( = 3)
  • QUALITY_BAD( = 4)
  • QUALITY_VBAD( = 5)
  • QUALITY_DOWN( = 6)
delay Time delay (ms).
lost Packet loss rate (%).

Leave Channel Callback (onLeaveChannel)

public void onLeaveChannel(IRtcEngineEventHandler.RtcStats stats);

When the application calls the leaveChannel() method, the SDK uses this callback to notify the application that the user has successfully left the channel. With this callback function, the application retrieves information such as the call duration and the statistics of data received/transmitted by the SDK.

Name Description
stats

Statistics about the call.

  • totalDuration: Call duration (s), represented by an aggregate value.
  • txBytes: Total number of bytes transmitted, represented by an aggregate value.
  • rxBytes: Total number of bytes received, represented by an aggregate value.
  • txKBitRate: Transmission bitrate (kbit/s), represented by an instantaneous value.
  • rxKBitRate: Receive bitrate (kbit/s), represented by an instantaneous value.
  • lastmileQuality: Network connection quality of the client, represented by an instantaneous value.
  • cpuTotalQuality: System CPU usage in percentage (%).
  • cpuAppQuality: Application CPU usage in percentage (%).
struct SessionStat {
    int totalDuration;
    int txBytes;
    int rxBytes;
    int txKBitRate;
    int rxKBitRate;
    int lastmileQuality;
    int cpuTotalUsage;
    int cpuAppUsage;
    };

Rtc Engine Statistics Callback (onRtcStats)

public void onRtcStats(IRtcEngineEventHandler.RtcStats stats);

The SDK updates the application on the statistics of the Rtc Engine runtime status once every two seconds.

Name Description
stats See the description of onLeaveChannel.

Audio Volume Indication Callback (onAudioVolumeIndication)

public void onAudioVolumeIndication(IRtcEngineEventHandler.AudioVolumeInfo[] speakers, unsigned int speakerNumber, int totalVolume);

This callback indicates who is talking and the speaker’s volume. By default the indication is disabled. If needed, call the enableAudioVolumeIndication() method to trigger this indication.

Name Description
speakers

The speakers (array). Each speaker ():

  • uid: User ID of the speaker.
  • volume: The volume of the speaker between 0 (lowest volume) to 255 (highest volume).
speakerNumber Total number of speakers.
totalVolume Total volume after audio mixing between 0 (lowest volume) to 255 (highest volume).

Channel Network Quality Callback (onNetworkQuality)

public void onNetworkQuality(int uid, int txQuality, int rxQuality);

This callback is triggered every 2 seconds to update the application on the network quality in a communication or live broadcast channel.

Name Description
uid

User ID. The specific callback reports the network quality of the user with this UID.

If uid is 0, it reports the local network quality. The current release only reports the quality for the local user.

txQuality

The transmission quality of the user:

  • QUALITY_EXCELLENT(1)
  • QUALITY_GOOD(2)
  • QUALITY_POOR(3)
  • QUALITY_BAD(4)
  • QUALITY_VBAD(5)
  • QUALITY_DOWN(6)
rxQuality

The receiving quality of the user:

  • QUALITY_EXCELLENT(1)
  • QUALITY_GOOD(2)
  • QUALITY_POOR(3)
  • QUALITY_BAD(4)
  • QUALITY_VBAD(5)
  • QUALITY_DOWN(6)

User Joined the Channel Callback (onUserJoined)

public void onUserJoined (int uid, int elapsed);

This callback method notifies the application that another user has joined the channel. If there are other users in the channel when that user joins, the SDK also reports to the application on the existing users who are already in the channel.

Name Description
uid User ID.
elapsed Time interval (m) from calling joinChannel until this callback is triggered.

User has Gone Offline Callback (onUserOffline)

public void onUserOffline (int uid, int reason);

This callback notifies the application that a user has left the channel or gone offline.

The SDK reads the timeout data to determine if a user has left the channel (or has gone offline). If no data package is received from the user in 15 seconds, the SDK assumes the user is offline. Sometimes a weak network connection may lead to false detections, therefore we recommend using signaling for reliable offline detection.

Name Description
uid User ID.
reason

Reasons for the user going offline:

  • USER_OFFLINE_QUIT: User has quit the call.
  • USER_OFFLINE_DROPPED: The SDK timed out and dropped offline because it had not received any data package for a long time.

When a user quits the call but the message is not passed to the SDK due to an unreliable channel, the SDK may assume that the other user timed out and dropped offline.

User Muted the Audio Callback (onUserMuteAudio)

public void onUserMuteAudio (int uid, boolean muted);

This callback indicates that a user has muted/unmuted his/her audio stream.

Name Description
uid User ID.
muted
  • True: User has muted his/her audio.
  • False: User has unmuted his/her audio.

Connection Lost Callback (onConnectionLost)

public void onConnectionLost();

This callback indicates that the SDK has lost connection with the network, and has remained unconnected for a period of time (10 s by default) despite attempts to reconnect. The SDK will keep trying to reconnect after this callback is triggered. Upon reconnection, an onRejoinChannelSuccess callback will be triggered.

Connection Interrupted Callback (onConnectionInterrupted)

public void onConnectionInterrupted();

This method indicates that the SDK has lost connection with the server.

This method is triggered upon connection lost, while the onConnectionLost method (see above) is triggered when the SDK attempts to reconnect after losing connection. Once the connection is lost, and if the application does not call leaveChannel, the SDK automatically tries to reconnect repeatedly.

Audio Mixing Playback Finished Callback (onAudioMixingFinished)

public void onAudioMixingFinished();

This callback is triggered when the playback of the audio mixing file is finished.

Audio Route Changed Callback (onAudioRouteChanged)

public void onAudioRouteChanged(int routing);

The SDK notifies the application that the audio route is changed to an earpiece, speakerphone, headset, or bluetooth.

Channel Key Expired Callback (onRequestChannelKey)

public void onRequestChannelKey();

When a Channel Key is specified by calling joinChannel(), if the SDK lost connection with the Agora server due to network issues, the Channel Key may expire after a certain period of time and a new Channel Key may be required to reconnect to the server.

This callback notifies the application to generate a new Channel Key, and calls renewChannelKey() to renew the Channel Key.

Client Role Changed Callback (onClientRoleChanged)

public void onClientRoleChanged(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole)

When you set the channel profile as Live Broadcast when calling setChannelProfile,this callback is triggered when there is any role change in the channel.

Name Description
oldRole The role that you switched from
newRole The role that you are now in
enum CLIENT_ROLE_TYPE
{
    CLIENT_ROLE_BROADCASTER = 1,
    CLIENT_ROLE_AUDIENCE = 2,
};