Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AgoraRtcEvents

The AgoraRtcEvents class reports runtime events to the applications.

Hierarchy

  • AgoraRtcEvents

Index

Properties

Properties

onActiveSpeaker

onActiveSpeaker: (uid: number) => void

Occurs when the most active speaker is detected.

After a successful call of enableAudioVolumeIndication, the SDK continuously determines which remote user has the loudest volume. The remote user determined to be the loudest and most continuous speaker is considered the most active user.

When the number of users is more than or equal to two and an active speaker exists, the SDK triggers this callback and reports the uid of the most active speaker.

  • If the most active speaker is always the same user, the SDK triggers this callback only once.
  • If the most active speaker changes to another user, the SDK triggers this callback again and reports the uid of the new active speaker.

Type declaration

    • (uid: number): void
    • Parameters

      • uid: number

        User ID of the active speaker. A uid of 0 represents the local user.

      Returns void

onApiCallExecuted

onApiCallExecuted: (err: ERROR_CODE_TYPE, api: string, result: string) => void

Occurs when a method is executed by the SDK.

Type declaration

    • Parameters

      • err: ERROR_CODE_TYPE

        The error code (ERROR_CODE_TYPE) returned by the SDK when a method call fails. If the SDK returns 0, then the method call is successful.

      • api: string

        The method executed by the SDK.

      • result: string

        The result of the method call.

      Returns void

onAudioDeviceStateChanged

onAudioDeviceStateChanged: (deviceId: string, deviceType: MEDIA_DEVICE_TYPE, deviceState: MEDIA_DEVICE_STATE_TYPE) => void

Occurs when the audio device state changes.

This callback notifies the application that the system's audio device state is changed. For example, a headset is unplugged from the device.

Type declaration

onAudioDeviceVolumeChanged

onAudioDeviceVolumeChanged: (deviceType: MEDIA_DEVICE_TYPE, volume: number, muted: boolean) => void

Occurs when the volume of the playback device, microphone, or application changes.

Type declaration

    • Parameters

      • deviceType: MEDIA_DEVICE_TYPE

        Device type: MEDIA_DEVICE_TYPE.

      • volume: number

        Volume of the device. The value ranges between 0 and 255.

      • muted: boolean
        • true: The audio device is muted.
        • false: The audio device is not muted.

      Returns void

onAudioEffectFinished

onAudioEffectFinished: (soundId: number) => void

Occurs when the local audio effect playback finishes.

The SDK triggers this callback when the local audio effect file playback finishes.

Type declaration

    • (soundId: number): void
    • Parameters

      • soundId: number

        ID of the local audio effect. Each local audio effect has a unique ID.

      Returns void

onAudioMixingFinished

onAudioMixingFinished: () => void

Occurs when the audio mixing file playback finishes.

deprecated

This method is deprecated. Use onAudioMixingStateChanged instead.

You can start an audio mixing file playback by calling the startAudioMixing method. The SDK triggers this callback when the audio mixing file playback finishes.

If the startAudioMixing method call fails, an error code returns in the onError callback.

Type declaration

    • (): void
    • Returns void

onAudioMixingStateChanged

onAudioMixingStateChanged: (state: AUDIO_MIXING_STATE_TYPE, reason: AUDIO_MIXING_REASON_TYPE) => void

Occurs when the state of the local user's audio mixing file changes.

When the state of the audio mixing file changes, the SDK triggers this callback and reports the audio mixing status and the error code of the audio playback failure.

If the local audio mixing file does not exist, or if the SDK does not support the file format or cannot access the music file URL, the SDK returns WARN_AUDIO_MIXING_OPEN_ERROR (701).

Type declaration

onAudioPublishStateChanged

onAudioPublishStateChanged: (channel: string, oldState: STREAM_PUBLISH_STATE, newState: STREAM_PUBLISH_STATE, elapseSinceLastState: number) => void

Occurs when the audio publishing state changes.

This callback indicates the publishing state change of the local audio stream.

Type declaration

onAudioQuality

onAudioQuality: (uid: number, quality: QUALITY_TYPE, delay: number, lost: number) => void

Reports the statistics of the audio stream from each remote user/host.

deprecated

This method is deprecated. Use the onRemoteAudioStats callback instead.

The SDK triggers this callback once every two seconds to report the audio quality of each remote user/host sending an audio stream. If a channel has multiple users/hosts sending audio streams, the SDK triggers this callback as many times.

Type declaration

    • (uid: number, quality: QUALITY_TYPE, delay: number, lost: number): void
    • Parameters

      • uid: number

        User ID of the speaker.

      • quality: QUALITY_TYPE

        Audio quality of the user: QUALITY_TYPE.

      • delay: number

        Time delay (ms) of sending the audio packet from the sender to the receiver, including the time delay of audio sampling pre-processing, transmission, and the jitter buffer.

      • lost: number

        Packet loss rate (%) of the audio packet sent from the sender to the receiver.

      Returns void

onAudioRouteChanged

onAudioRouteChanged: (routing: AUDIO_ROUTE_TYPE) => void

Occurs when the local audio route changes.

The SDK triggers this callback when the local audio route switches to an earpiece, speakerphone, headset, or Bluetooth device.

Type declaration

onAudioSubscribeStateChanged

onAudioSubscribeStateChanged: (channel: string, uid: number, oldState: STREAM_SUBSCRIBE_STATE, newState: STREAM_SUBSCRIBE_STATE, elapseSinceLastState: number) => void

Occurs when the audio subscribing state changes.

This callback indicates the subscribing state change of a remote audio stream.

Type declaration

onAudioVolumeIndication

onAudioVolumeIndication: (speakers: AudioVolumeInfo[], speakerNumber: number, totalVolume: number) => void

Reports the volume information of users.

By default, this callback is disabled. You can enable it by calling enableAudioVolumeIndication. Once this callback is enabled and users send streams in the channel, the SDK triggers the onAudioVolumeIndication callback at the time interval set in enableAudioVolumeIndication.

The SDK triggers two independent onAudioVolumeIndication callbacks simultaneously, which separately report the volume information of the local user who sends a stream and the remote users (up to three) whose instantaneous volumes are the highest.

note

After you enable this callback, calling muteLocalAudioStream affects the SDK's behavior as follows:

  • If the local user calls muteLocalAudioStream, the SDK stops triggering the local user's callback.
  • 20 seconds after a remote user whose volume is one of the three highest calls muteLocalAudioStream, the remote users' callback excludes this remote user's information; 20 seconds after all remote users call muteLocalAudioStream, the SDK stops triggering the remote users' callback.

Type declaration

    • (speakers: AudioVolumeInfo[], speakerNumber: number, totalVolume: number): void
    • Parameters

      • speakers: AudioVolumeInfo[]

        The volume information of users. See AudioVolumeInfo. An empty speakers array in the callback indicates that no remote user is in the channel or sending a stream at the moment.

      • speakerNumber: number

        Total number of users.

        • In the local user’s callback, when the local user sends a stream: speakerNumber = 1.
        • In the remote users' callback, the value ranges between 0 and 3. If the number of remote users who send streams is greater than or equal to three, speakerNumber = 3.
      • totalVolume: number

        Total volume after audio mixing. The value ranges between 0 (lowest volume) and 255 (highest volume).

        • In the local user’s callback, totalVolume is the volume of the local user who sends a stream.
        • In the remote users' callback, totalVolume is the sum of the volume of all remote users (at most three) whose instantaneous volumes are the highest.

        If the user calls startAudioMixing, totalVolume is the sum of the voice volume and audio-mixing volume.

      Returns void

onCameraExposureAreaChanged

onCameraExposureAreaChanged: (x: number, y: number, width: number, height: number) => void

Occurs when the camera exposure area changes.

The SDK triggers this callback when the local user changes the camera exposure position by calling the setCameraExposurePosition method.

Type declaration

    • (x: number, y: number, width: number, height: number): void
    • Parameters

      • x: number

        x coordinate of the changed camera exposure area.

      • y: number

        y coordinate of the changed camera exposure area.

      • width: number

        Width of the changed camera exposure area.

      • height: number

        Height of the changed camera exposure area.

      Returns void

onCameraFocusAreaChanged

onCameraFocusAreaChanged: (x: number, y: number, width: number, height: number) => void

Occurs when the camera focus area changes.

The SDK triggers this callback when the local user changes the camera focus position by calling the setCameraFocusPositionInPreview method.

Type declaration

    • (x: number, y: number, width: number, height: number): void
    • Parameters

      • x: number

        x coordinate of the changed camera focus area.

      • y: number

        y coordinate of the changed camera focus area.

      • width: number

        Width of the changed camera focus area.

      • height: number

        Height of the changed camera focus area.

      Returns void

onCameraReady

onCameraReady: () => void

Occurs when the camera turns on and is ready to capture the video.

deprecated

This method is deprecated. Use LOCAL_VIDEO_STREAM_STATE_CAPTURING(1) in the onLocalVideoStateChanged callback instead.

If the camera fails to turn on, fix the error reported in the onError callback.

Type declaration

    • (): void
    • Returns void

onChannelMediaRelayEvent

onChannelMediaRelayEvent: (code: CHANNEL_MEDIA_RELAY_EVENT) => void

Reports events during the media stream relay.

Type declaration

onChannelMediaRelayStateChanged

onChannelMediaRelayStateChanged: (state: CHANNEL_MEDIA_RELAY_STATE, code: CHANNEL_MEDIA_RELAY_ERROR) => void

Occurs when the state of the media stream relay changes.

The SDK returns the state of the current media relay with any error message.

Type declaration

onClientRoleChanged

onClientRoleChanged: (oldRole: CLIENT_ROLE_TYPE, newRole: CLIENT_ROLE_TYPE) => void

Occurs when the user role switches in the live interactive streaming. For example, from a host to an audience or vice versa.

This callback notifies the application of a user role switch when the application calls the setClientRole method.

The SDK triggers this callback when the local user switches the user role by calling the setClientRole method after joining the channel.

Type declaration

onConnectionBanned

onConnectionBanned: () => void

Occurs when your connection is banned by the Agora Server.

deprecated

This method is deprecated and replaced by the onConnectionStateChanged callback.

Type declaration

    • (): void
    • Returns void

onConnectionInterrupted

onConnectionInterrupted: () => void

Occurs when the connection between the SDK and the server is interrupted.

deprecated

This method is deprecated and replaced by the onConnectionStateChanged callback.

The SDK triggers this callback when it loses connection with the server for more than four seconds after the connection is established.

After triggering this callback, the SDK tries reconnecting to the server. You can use this callback to implement pop-up reminders.

This callback is different from onConnectionLost:

  • The SDK triggers the onConnectionInterrupted callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
  • The SDK triggers the onConnectionLost callback when it loses connection with the server for more than 10 seconds, whether or not it joins the channel.

If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora edge server, the SDK stops rejoining the channel.

Type declaration

    • (): void
    • Returns void

onConnectionLost

onConnectionLost: () => void

Occurs when the SDK cannot reconnect to Agora edge server 10 seconds after its connection to the server is interrupted.

The SDK triggers this callback when it cannot connect to the server 10 seconds after calling the joinChannel method, whether or not it is in the channel.

This callback is different from onConnectionInterrupted:

  • The SDK triggers the onConnectionInterrupted callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
  • The SDK triggers the onConnectionLost callback when it loses connection with the server for more than 10 seconds, whether or not it joins the channel.

If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora edge server, the SDK stops rejoining the channel.

Type declaration

    • (): void
    • Returns void

onConnectionStateChanged

onConnectionStateChanged: (state: CONNECTION_STATE_TYPE, reason: CONNECTION_CHANGED_REASON_TYPE) => void

Occurs when the connection state between the SDK and the server changes.

onError

onError: (err: ERROR_CODE_TYPE, msg: string) => void

Reports an error during SDK runtime.

In most cases, the SDK cannot fix the issue and resume running. The SDK requires the application to take action or informs the user about the issue.

For example, the SDK reports an ERR_START_CALL error when failing to initialize a call. The application informs the user that the call initialization failed and invokes the leaveChannel method to leave the channel.

Type declaration

onFacePositionChanged

onFacePositionChanged: (imageWidth: number, imageHeight: number, vecRectangle: Rectangle[], vecDistance: number[], numFaces: number) => void

Reports the face detection result of the local user.

Once you enable face detection by calling enableFaceDetection (true), you can get the following information on the local user in real-time:

  • The width and height of the local video.
  • The position of the human face in the local video.
  • The distance between the human face and the device screen. This value is based on the fitting calculation of the local video size and the position of the human face.

Note

  • If the SDK does not detect a face, it reduces the frequency of this callback to reduce power consumption on the local device.
  • The SDK stops triggering this callback when a human face is in close proximity to the screen.
  • On Android, the distance value reported in this callback may be slightly different from the actual distance. Therefore, Agora does not recommend using it for accurate calculation.

Type declaration

    • (imageWidth: number, imageHeight: number, vecRectangle: Rectangle[], vecDistance: number[], numFaces: number): void
    • Parameters

      • imageWidth: number

        The width (px) of the local video.

      • imageHeight: number

        The height (px) of the local video.

      • vecRectangle: Rectangle[]

        The position and size of the human face on the local video. See Rectangle

        • x: The x coordinate (px) of the human face in the local video. Taking the top left corner of the captured video as the origin, the x coordinate represents the relative lateral displacement of the top left corner of the human face to the origin.
        • y: The y coordinate (px) of the human face in the local video. Taking the top left corner of the captured video as the origin, the y coordinate represents the relative longitudinal displacement of the top left corner of the human face to the origin.
        • width: The width (px) of the human face in the captured video.
        • height: The height (px) of the human face in the captured video.
      • vecDistance: number[]

        The distance (cm) between the human face and the screen.

      • numFaces: number

        The number of faces detected. If the value is 0, it means that no human face is detected.

      Returns void

onFirstLocalAudioFrame

onFirstLocalAudioFrame: (elapsed: number) => void

Occurs when the engine sends the first local audio frame.

deprecated

This callback is deprecated. Use the onFirstLocalAudioFramePublished callback instead.

Type declaration

    • (elapsed: number): void
    • Parameters

      • elapsed: number

        Time elapsed (ms) from the local user calling joinChannel until the SDK triggers this callback.

      Returns void

onFirstLocalAudioFramePublished

onFirstLocalAudioFramePublished: (elapsed: number) => void

Occurs when the first audio frame is published.

The SDK triggers this callback under one of the following circumstances:

Type declaration

    • (elapsed: number): void
    • Parameters

      • elapsed: number

        The time elapsed (ms) from the local client calling joinChannel until the SDK triggers this callback.

      Returns void

onFirstLocalVideoFrame

onFirstLocalVideoFrame: (width: number, height: number, elapsed: number) => void

Occurs when the first local video frame is displayed/rendered on the local video view.

Type declaration

    • (width: number, height: number, elapsed: number): void
    • Parameters

      • width: number

        Width (px) of the first local video frame.

      • height: number

        Height (px) of the first local video frame.

      • elapsed: number

        Time elapsed (ms) from the local user calling the joinChannel method until the SDK triggers this callback. If you call the startPreview method before calling the joinChannel method, then elapsed is the time elapsed from calling the startPreview method until the SDK triggers this callback.

      Returns void

onFirstLocalVideoFramePublished

onFirstLocalVideoFramePublished: (elapsed: number) => void

Occurs when the first video frame is published.

The SDK triggers this callback under one of the following circumstances:

Type declaration

    • (elapsed: number): void
    • Parameters

      • elapsed: number

        The time elapsed (ms) from the local client calling joinChannel until the SDK triggers this callback.

      Returns void

onFirstRemoteAudioDecoded

onFirstRemoteAudioDecoded: (uid: number, elapsed: number) => void

Occurs when the SDK decodes the first remote audio frame for playback.

deprecated

This callback is deprecated. Use onRemoteAudioStateChanged instead.

This callback is triggered in either of the following scenarios:

  • The remote user joins the channel and sends the audio stream.
  • The remote user stops sending the audio stream and re-sends it after 15 seconds. Reasons for such an interruption include:
    • The remote user leaves channel.
    • The remote user drops offline.
    • The remote user calls the muteLocalAudioStream method to stop sending the local audio stream.
    • The remote user calls the disableAudio method to disable audio.

Type declaration

    • (uid: number, elapsed: number): void
    • Parameters

      • uid: number

        User ID of the remote user sending the audio stream.

      • elapsed: number

        Time elapsed (ms) from the local user calling the joinChannel method until the SDK triggers this callback.

      Returns void

onFirstRemoteAudioFrame

onFirstRemoteAudioFrame: (uid: number, elapsed: number) => void

Occurs when the engine receives the first audio frame from a specific remote user.

deprecated

This callback is deprecated. Use onRemoteAudioStateChanged instead.

Type declaration

    • (uid: number, elapsed: number): void
    • Parameters

      • uid: number

        User ID of the remote user.

      • elapsed: number

        Time elapsed (ms) from the remote user calling joinChannel until the SDK triggers this callback.

      Returns void

onFirstRemoteVideoDecoded

onFirstRemoteVideoDecoded: (uid: number, width: number, height: number, elapsed: number) => void

Occurs when the first remote video frame is received and decoded.

deprecated

This callback is deprecated and replaced by the onRemoteVideoStateChanged callback with the following parameters:

This callback is triggered in either of the following scenarios:

  • The remote user joins the channel and sends the video stream.
  • The remote user stops sending the video stream and re-sends it after 15 seconds. Reasons for such an interruption include:
    • The remote user leaves the channel.
    • The remote user drops offline.
    • The remote user calls the muteLocalVideoStream method to stop sending the video stream.
    • The remote user calls the disableVideo method to disable video.

The application can configure the user view settings in this callback.

Type declaration

    • (uid: number, width: number, height: number, elapsed: number): void
    • Parameters

      • uid: number

        User ID of the remote user sending the video stream.

      • width: number

        Width (px) of the video stream.

      • height: number

        Height (px) of the video stream.

      • elapsed: number

        Time elapsed (ms) from the local user calling the joinChannel method until the SDK triggers this callback.

      Returns void

onFirstRemoteVideoFrame

onFirstRemoteVideoFrame: (uid: number, width: number, height: number, elapsed: number) => void

Occurs when the first remote video frame is rendered.

The SDK triggers this callback when the first frame of the remote video is displayed in the user's video window. The application can retrieve the time elapsed from a user joining the channel until the first video frame is displayed.

Type declaration

    • (uid: number, width: number, height: number, elapsed: number): void
    • Parameters

      • uid: number

        User ID of the remote user sending the video stream.

      • width: number

        Width (px) of the video frame.

      • height: number

        Height (px) of the video stream.

      • elapsed: number

        Time elapsed (ms) from the local user calling the joinChannel method until the SDK triggers this callback.

      Returns void

onJoinChannelSuccess

onJoinChannelSuccess: (channel: string, uid: number, elapsed: number) => void

Occurs when a user joins a channel.

This callback notifies the application that a user joins a specified channel when the application calls the joinChannel method.

The channel name assignment is based on channelId specified in the joinChannel method. If the uid is not specified in the joinChannel method, the server automatically assigns a uid.

Type declaration

    • (channel: string, uid: number, elapsed: number): void
    • Parameters

      • channel: string

        The channel name.

      • uid: number

        User ID of the user joining the channel.

      • elapsed: number

        Time elapsed (ms) from the user calling the joinChannel method until the SDK triggers this callback.

      Returns void

onLastmileProbeResult

onLastmileProbeResult: (result: LastmileProbeResult) => void

Reports the last-mile network probe result.

The SDK triggers this callback within 30 seconds after the app calls the startLastmileProbeTest method.

Type declaration

onLastmileQuality

onLastmileQuality: (quality: QUALITY_TYPE) => void

Reports the last mile network quality of the local user once every two seconds before the user joins the channel.

Last mile refers to the connection between the local device and Agora edge server. After the application calls the enableLastmileTest method, this callback reports once every two seconds the uplink and downlink last mile network conditions of the local user before the user joins the channel.

Type declaration

onLeaveChannel

onLeaveChannel: (stats: RtcStats) => void

Occurs when a user leaves the channel.

This callback notifies the application that a user leaves the channel when the application calls the leaveChannel method.

The application retrieves information, such as the call duration and statistics.

Type declaration

onLocalAudioStateChanged

onLocalAudioStateChanged: (state: LOCAL_AUDIO_STREAM_STATE, error: LOCAL_AUDIO_STREAM_ERROR) => void

Occurs when the local audio state changes. This callback indicates the state change of the local audio stream, including the state of the audio recording and encoding, and allows you to troubleshoot issues when exceptions occur.

note

When the state is LOCAL_AUDIO_STREAM_STATE_FAILED(3), see the error parameter for details.

Type declaration

onLocalAudioStats

onLocalAudioStats: (stats: LocalAudioStats) => void

Reports the statistics of the local audio stream.

The SDK triggers this callback once every two seconds.

Type declaration

onLocalPublishFallbackToAudioOnly

onLocalPublishFallbackToAudioOnly: (isFallbackOrRecover: boolean) => void

Occurs when the published media stream falls back to an audio-only stream due to poor network conditions or switches back to the video after the network conditions improve.

If you call setLocalPublishFallbackOption and set option as STREAM_FALLBACK_OPTION_AUDIO_ONLY the SDK triggers this callback when the published stream falls back to audio-only mode due to poor uplink conditions, or when the audio stream switches back to the video after the uplink network condition improves.

note

If the local stream fallbacks to the audio-only stream, the remote user receives the onUserMuteVideo callback.

Type declaration

    • (isFallbackOrRecover: boolean): void
    • Parameters

      • isFallbackOrRecover: boolean

        Whether the published stream falls back to audio-only or switches back to the video:

        • true: The published stream falls back to audio-only due to poor network conditions.
        • false: The published stream switches back to the video after the network conditions improve.

      Returns void

onLocalUserRegistered

onLocalUserRegistered: (uid: number, userAccount: string) => void

Occurs when the local user successfully registers a user account by calling the registerLocalUserAccount method or joins a channel by calling the joinChannelWithUserAccount method.This callback reports the user ID and user account of the local user.

Type declaration

    • (uid: number, userAccount: string): void
    • Parameters

      • uid: number

        The ID of the local user.

      • userAccount: string

        The user account of the local user.

      Returns void

onLocalVideoStateChanged

onLocalVideoStateChanged: (localVideoState: LOCAL_VIDEO_STREAM_STATE, error: LOCAL_VIDEO_STREAM_ERROR) => void

Occurs when the local video stream state changes.

This callback indicates the state of the local video stream, including camera capturing and video encoding, and allows you to troubleshoot issues when exceptions occur.

note

For some device models, the SDK will not trigger this callback when the state of the local video changes while the local video capturing device is in use, so you have to make your own timeout judgment.

Type declaration

onLocalVideoStats

onLocalVideoStats: (stats: LocalVideoStats) => void

Reports the statistics of the local video stream.

The SDK triggers this callback once every two seconds for each user/host. If there are multiple users/hosts in the channel, the SDK triggers this callback as many times.

note

If you have called the enableDualStreamMode method, the onLocalVideoStats callback reports the statistics of the high-video stream (high bitrate, and high-resolution video stream).

Type declaration

onMediaEngineLoadSuccess

onMediaEngineLoadSuccess: () => void

Occurs when the media engine loads.

Type declaration

    • (): void
    • Returns void

onMediaEngineStartCallSuccess

onMediaEngineStartCallSuccess: () => void

Occurs when the media engine call starts.

Type declaration

    • (): void
    • Returns void

onMetadataReceived

onMetadataReceived: (metadata: Metadata) => void

Occurs when the local user receives the metadata.

Type declaration

onMicrophoneEnabled

onMicrophoneEnabled: (enabled: boolean) => void

Occurs when the microphone is enabled/disabled.

deprecated

The onMicrophoneEnabled callback is deprecated. Use LOCAL_AUDIO_STREAM_STATE_STOPPED (0) or LOCAL_AUDIO_STREAM_STATE_RECORDING (1) in the onLocalAudioStateChanged callback instead.

The SDK triggers this callback when the local user resumes or stops capturing the local audio stream by calling the enbaleLocalAudio method.

Type declaration

    • (enabled: boolean): void
    • Parameters

      • enabled: boolean

        Whether the microphone is enabled/disabled:

        • true: Enabled.
        • false: Disabled.

      Returns void

onNetworkQuality

onNetworkQuality: (uid: number, txQuality: QUALITY_TYPE, rxQuality: QUALITY_TYPE) => void

Reports the last mile network quality of each user in the channel once every two seconds.

Last mile refers to the connection between the local device and Agora edge server. This callback reports once every two seconds the last mile network conditions of each user in the channel. If a channel includes multiple users, the SDK triggers this callback as many times.

Type declaration

    • Parameters

      • uid: number

        User ID. The network quality of the user with this uid is reported. If uid is 0, the local network quality is reported.

      • txQuality: QUALITY_TYPE

        Uplink transmission quality rating of the user in terms of the transmission bitrate, packet loss rate, average RTT (Round-Trip Time), and jitter of the uplink network. txQuality is a quality rating helping you understand how well the current uplink network conditions can support the selected VideoEncoderConfiguration. For example, a 1000 Kbps uplink network may be adequate for video frames with a resolution of 640 * 480 and a frame rate of 15 fps in the LIVE_BROADCASTING profile, but may be inadequate for resolutions higher than 1280 * 720. See QUALITY_TYPE.

      • rxQuality: QUALITY_TYPE

        Downlink network quality rating of the user in terms of the packet loss rate, average RTT, and jitter of the downlink network. See QUALITY_TYPE.

      Returns void

onNetworkTypeChanged

onNetworkTypeChanged: (type: NETWORK_TYPE) => void

Occurs when the local network type changes.

When the network connection is interrupted, this callback indicates whether the interruption is caused by a network type change or poor network conditions.

Type declaration

onRejoinChannelSuccess

onRejoinChannelSuccess: (channel: string, uid: number, elapsed: number) => void

Occurs when a user rejoins the channel after disconnection due to network problems.

When a user loses connection with the server because of network problems, the SDK automatically tries to reconnect and triggers this callback upon reconnection.

Type declaration

    • (channel: string, uid: number, elapsed: number): void
    • Parameters

      • channel: string

        The channel name.

      • uid: number

        User ID of the user rejoining the channel.

      • elapsed: number

        Time elapsed (ms) from starting to reconnect until the SDK triggers this callback.

      Returns void

onRemoteAudioMixingBegin

onRemoteAudioMixingBegin: () => void

Occurs when a remote user starts audio mixing. When a remote user calls startAudioMixing to play the background music, the SDK reports this callback.

Type declaration

    • (): void
    • Returns void

onRemoteAudioMixingEnd

onRemoteAudioMixingEnd: () => void

Occurs when a remote user finishes audio mixing.

Type declaration

    • (): void
    • Returns void

onRemoteAudioStateChanged

onRemoteAudioStateChanged: (uid: number, state: REMOTE_AUDIO_STATE, reason: REMOTE_AUDIO_STATE_REASON, elapsed: number) => void

Occurs when the remote audio state changes.

This callback indicates the state change of the remote audio stream.

note

This callback does not work properly when the number of users (in the COMMUNICATION profile) or hosts (in the LIVE_BROADCASTING profile) in the channel exceeds 17.

Type declaration

onRemoteAudioStats

onRemoteAudioStats: (stats: RemoteAudioStats) => void

Reports the statistics of the audio stream from each remote user/host.

This callback replaces the onAudioQuality callback.

The SDK triggers this callback once every two seconds for each remote user/host. If a channel includes multiple remote users, the SDK triggers this callback as many times.

Type declaration

onRemoteAudioTransportStats

onRemoteAudioTransportStats: (uid: number, delay: number, lost: number, rxKBitRate: number) => void

Reports the transport-layer statistics of each remote audio stream.

deprecated

This callback is deprecated and replaced by the onRemoteAudioStats callback.

This callback reports the transport-layer statistics, such as the packet loss rate and network time delay, once every two seconds after the local user receives an audio packet from a remote user.

Type declaration

    • (uid: number, delay: number, lost: number, rxKBitRate: number): void
    • Parameters

      • uid: number

        User ID of the remote user sending the audio packet.

      • delay: number

        Network time delay (ms) from the remote user sending the audio packet to the local user.

      • lost: number

        Packet loss rate (%) of the audio packet sent from the remote user.

      • rxKBitRate: number

        Received bitrate (Kbps) of the audio packet sent from the remote user.

      Returns void

onRemoteSubscribeFallbackToAudioOnly

onRemoteSubscribeFallbackToAudioOnly: (uid: number, isFallbackOrRecover: boolean) => void

Occurs when the remote media stream falls back to audio-only stream due to poor network conditions or switches back to the video stream after the network conditions improve.

If you call setRemoteSubscribeFallbackOption and set option as STREAM_FALLBACK_OPTION_AUDIO_ONLY the SDK triggers this callback when the remote media stream falls back to audio-only mode due to poor uplink conditions, or when the remote media stream switches back to the video after the uplink network condition improves.

note

Once the remote media stream switches to the low stream due to poor network conditions, you can monitor the stream switch between a high and low stream in the RemoteVideoStats callback.

Type declaration

    • (uid: number, isFallbackOrRecover: boolean): void
    • Parameters

      • uid: number

        ID of the remote user sending the stream.

      • isFallbackOrRecover: boolean

        Whether the remotely subscribed media stream falls back to audio-only or switches back to the video:

        • true: The remotely subscribed media stream falls back to audio-only due to poor network conditions.
        • false: The remotely subscribed media stream switches back to the video stream after the network conditions improved.

      Returns void

onRemoteVideoStateChanged

onRemoteVideoStateChanged: (uid: number, state: REMOTE_VIDEO_STATE, reason: REMOTE_VIDEO_STATE_REASON, elapsed: number) => void

Occurs when the remote video state changes.

note

This callback does not work properly when the number of users (in the COMMUNICATION profile) or hosts (in the LIVE_BROADCASTING profile) in the channel exceeds 17.

Type declaration

onRemoteVideoStats

onRemoteVideoStats: (stats: RemoteVideoStats) => void

Reports the statistics of the video stream from each remote user/host.

The SDK triggers this callback once every two seconds for each remote user/host. If a channel includes multiple remote users, the SDK triggers this callback as many times.

Type declaration

onRemoteVideoTransportStats

onRemoteVideoTransportStats: (uid: number, delay: number, lost: number, rxKBitRate: number) => void

Reports the transport-layer statistics of each remote video stream.

deprecated

This callback is deprecated and replaced by the onRemoteVideoStats callback. This callback reports the transport-layer statistics, such as the packet loss rate and network time delay, once every two seconds after the local user receives a video packet from a remote user.

Type declaration

    • (uid: number, delay: number, lost: number, rxKBitRate: number): void
    • Parameters

      • uid: number

        User ID of the remote user sending the video packet.

      • delay: number

        Network time delay (ms) from the remote user sending the video packet to the local user.

      • lost: number

        Packet loss rate (%) of the video packet sent from the remote user.

      • rxKBitRate: number

        Received bitrate (Kbps) of the video packet sent from the remote user.

      Returns void

onRequestToken

onRequestToken: () => void

Occurs when the token expires.

After a token is specified by calling the joinChannel method, if the SDK losses connection with the Agora server due to network issues, the token may expire after a certain period of time and a new token may be required to reconnect to the server.

This callback notifies the app to generate a new token and call joinChannel to rejoin the channel with the new token.

Type declaration

    • (): void
    • Returns void

onRtcStats

onRtcStats: (stats: RtcStats) => void

Reports the statistics of the current call.

The SDK triggers this callback once every two seconds after the user joins the channel.

Type declaration

onRtmpStreamingEvent

onRtmpStreamingEvent: (url: string, eventCode: RTMP_STREAMING_EVENT) => void

Reports events during the RTMP streaming.

Type declaration

onRtmpStreamingStateChanged

onRtmpStreamingStateChanged: (url: string, state: RTMP_STREAM_PUBLISH_STATE, errCode: RTMP_STREAM_PUBLISH_ERROR) => void

Occurs when the state of the RTMP streaming changes.

The SDK triggers this callback to report the result of the local user calling the addPublishStreamUrl or removePublishStreamUrl method.

This callback indicates the state of the RTMP streaming. When exceptions occur, you can troubleshoot issues by referring to the detailed error descriptions in the errCode parameter.

Type declaration

onStreamInjectedStatus

onStreamInjectedStatus: (url: string, uid: number, status: INJECT_STREAM_STATUS) => void

Occurs when a voice or video stream URL address is added to the live interactive streaming.

Type declaration

onStreamMessage

onStreamMessage: (uid: number, streamId: number, data: Uint8Array, length: number) => void

Occurs when the local user receives the data stream from the remote user within five seconds.

The SDK triggers this callback when the local user receives the stream message that the remote user sends by calling the sendStreamMessage method.

Type declaration

    • (uid: number, streamId: number, data: Uint8Array, length: number): void
    • Parameters

      • uid: number

        User ID of the remote user sending the message.

      • streamId: number

        Stream ID.

      • data: Uint8Array

        The data received by the local user.

      • length: number

        Length of the data in bytes.

      Returns void

onStreamMessageError

onStreamMessageError: (uid: number, streamId: number, code: number, missed: number, cached: number) => void

Occurs when the local user does not receive the data stream from the remote user within five seconds.

The SDK triggers this callback when the local user fails to receive the stream message that the remote user sends by calling the sendStreamMessage method.

Type declaration

    • (uid: number, streamId: number, code: number, missed: number, cached: number): void
    • Parameters

      • uid: number

        User ID of the remote user sending the message.

      • streamId: number

        Stream ID.

      • code: number

        Error code: ERROR_CODE_TYPE.

      • missed: number

        Number of lost messages.

      • cached: number

        Number of incoming cached messages when the data stream is interrupted.

      Returns void

onStreamPublished

onStreamPublished: (url: string, error: number) => void

Reports the result of calling the addPublishStreamUrl method. (CDN live only.)

deprecated

This method is deprecated, use the onRtmpStreamingStateChanged callback instead.

Type declaration

    • (url: string, error: number): void
    • Parameters

      • url: string

        The RTMP URL address.

      • error: number

        Error code: ERROR_CODE_TYPE. Main errors include:

        • 0(ERR_OK): The publishing succeeds.
        • -1(ERR_FAILED): The publishing fails.
        • -2(ERR_INVALID_ARGUMENT): Invalid argument used. If, for example, you did not call setLiveTranscoding to configure LiveTranscoding before calling addPublishStreamUrl , the SDK reports ERR_INVALID_ARGUMENT.
        • -10(ERR_TIMEDOUT): The publishing timed out.
        • -19(ERR_ALREADY_IN_USE): The chosen URL address is already in use for CDN live streaming.
        • -22(ERR_RESOURCE_LIMITED): The backend system does not have enough resources for the CDN live streaming.
        • -130(ERR_ENCRYPTED_STREAM_NOT_ALLOWED_PUBLISH): You cannot publish an encrypted stream.
        • -151(ERR_PUBLISH_STREAM_CDN_ERROR)
        • -152(ERR_PUBLISH_STREAM_NUM_REACH_LIMIT)
        • -153(ERR_PUBLISH_STREAM_NOT_AUTHORIZED)
        • -154(ERR_PUBLISH_STREAM_INTERNAL_SERVER_ERROR)
        • -156(ERR_PUBLISH_STREAM_FORMAT_NOT_SUPPORTED)

      Returns void

onStreamUnpublished

onStreamUnpublished: (url: string) => void

Reports the result of calling the removePublishStreamUrl method. (CDN live only.)

deprecated

This method is deprecated, use the onRtmpStreamingStateChanged callback instead.

This callback indicates whether you have successfully removed an RTMP stream from the CDN.

Type declaration

    • (url: string): void
    • Parameters

      • url: string

        The RTMP URL address.

      Returns void

onTokenPrivilegeWillExpire

onTokenPrivilegeWillExpire: (token: string) => void

Occurs when the token expires in 30 seconds.

The user becomes offline if the token used in the joinChannel method expires. The SDK triggers this callback 30 seconds before the token expires to remind the application to get a new token. Upon receiving this callback, generate a new token on the server and call the renewToken method to pass the new token to the SDK.

Type declaration

    • (token: string): void
    • Parameters

      • token: string

        The token that expires in 30 seconds.

      Returns void

onTranscodingUpdated

onTranscodingUpdated: () => void

Occurs when the publisher's transcoding is updated.

When the LiveTranscoding class in the setLiveTranscoding method updates, the SDK triggers the onTranscodingUpdated callback to report the update information to the local host.

note

If you call the setLiveTranscoding method to set the LiveTranscoding class for the first time, the SDK does not trigger the onTranscodingUpdated callback.

Type declaration

    • (): void
    • Returns void

onUserEnableLocalVideo

onUserEnableLocalVideo: (uid: number, enabled: boolean) => void

Occurs when a specified remote user enables/disables the local video capturing function.

deprecated

This callback is deprecated and replaced by the onRemoteVideoStateChanged callback with the following parameters:

This callback is only applicable to the scenario when the user only wants to watch the remote video without sending any video stream to the other user.

The SDK triggers this callback when the remote user resumes or stops capturing the video stream by calling the enableLocalVideo method.

Type declaration

    • (uid: number, enabled: boolean): void
    • Parameters

      • uid: number

        User ID of the remote user.

      • enabled: boolean

        Whether the specified remote user enables/disables the local video capturing function:

        • true: Enable. Other users in the channel can see the video of this remote user.
        • false: Disable. Other users in the channel can no longer receive the video stream from this remote user, while this remote user can still receive the video streams from other users.

      Returns void

onUserEnableVideo

onUserEnableVideo: (uid: number, enabled: boolean) => void

Occurs when a specific remote user enables/disables the video module.

deprecated

This callback is deprecated and replaced by the onRemoteVideoStateChanged callback with the following parameters:

Once the video module is disabled, the remote user can only use a voice call. The remote user cannot send or receive any video from other users.

The SDK triggers this callback when the remote user enables or disables the video module by calling the enableVideo or disableVideo method.

note

This callback returns invalid when the number of users in a channel exceeds 17.

Type declaration

    • (uid: number, enabled: boolean): void
    • Parameters

      • uid: number

        User ID of the remote user.

      • enabled: boolean

        Whether the remote user enables/disables the video module:

        • true: Enable. The remote user can enter a video session.
        • false: Disable. The remote user can only enter a voice session, and cannot send or receive any video stream.

      Returns void

onUserInfoUpdated

onUserInfoUpdated: (uid: number, info: UserInfo) => void

Occurs when the SDK gets the user ID and user account of the remote user.

After a remote user joins the channel, the SDK gets the UID and user account of the remote user, caches them in userInfo, and triggers this callback on the local client.

Type declaration

    • Parameters

      • uid: number

        The ID of the remote user.

      • info: UserInfo

        agora.UserInfo contains the user ID and user account of the remote user.

      Returns void

onUserJoined

onUserJoined: (uid: number, elapsed: number) => void

Occurs when a remote user (COMMUNICATION)/ host (LIVE_BROADCASTING) joins the channel.

  • COMMUNICATION profile: This callback notifies the application that another user joins the channel. If other users are already in the channel, the SDK also reports to the application on the existing users.
  • LIVE_BROADCASTING profile: This callback notifies the application that the host joins the channel. If other hosts are already in the channel, the SDK also reports to the application on the existing hosts. We recommend limiting the number of hosts to 17.

The SDK triggers this callback under one of the following circumstances:

  • A remote user/host joins the channel by calling the joinChannel method.
  • A remote user switches the user role to the host by calling the setClientRole method after joining the channel.
  • A remote user/host rejoins the channel after a network interruption.
  • The host injects an online media stream into the channel by calling the addInjectStreamUrl method.
note

In the LIVE_BROADCASTING profile:

  • The host receives this callback when another host joins the channel.
  • The audience in the channel receives this callback when a new host joins the channel.
  • When a web application joins the channel, the SDK triggers this callback as long as the web application publishes streams.

Type declaration

    • (uid: number, elapsed: number): void
    • Parameters

      • uid: number

        User ID of the user or host joining the channel.

      • elapsed: number

        Time delay (ms) from the local user calling the joinChannel method until the SDK triggers this callback.

      Returns void

onUserMuteAudio

onUserMuteAudio: (uid: number, muted: boolean) => void

Occurs when a remote user's audio stream playback pauses/resumes.

deprecated

This method is deprecated, use the  onRemoteAudioStateChanged callback instead.

The SDK triggers this callback when the remote user stops or resumes sending the audio stream by calling the muteLocalAudioStream method.

note

This callback does not work properly when the number of users (in the COMMUNICATION profile) or hosts (in the LIVE_BROADCASTING profile) in the channel exceeds 17.

Type declaration

    • (uid: number, muted: boolean): void
    • Parameters

      • uid: number

        User ID of the remote user.

      • muted: boolean

        Whether the remote user's audio stream is muted/unmuted:

        • true: Muted.
        • false: Unmuted.

      Returns void

onUserMuteVideo

onUserMuteVideo: (uid: number, muted: boolean) => void

Occurs when a remote user's video stream playback pauses/resumes.

You can also use the onRemoteVideoStateChanged callback with the following parameters:

The SDK triggers this callback when the remote user stops or resumes sending the video stream by calling the muteLocalVideoStream method.

note

This callback does not work properly when the number of users (in the COMMUNICATION profile) or hosts (in the LIVE_BROADCASTING profile) in the channel exceeds 17.

Type declaration

    • (uid: number, muted: boolean): void
    • Parameters

      • uid: number

        User ID of the remote user.

      • muted: boolean

        Whether the remote user's video stream playback is paused/resumed:

        • true: Paused.
        • false: Resumed.

      Returns void

onUserOffline

onUserOffline: (uid: number, reason: USER_OFFLINE_REASON_TYPE) => void

Occurs when a remote user (COMMUNICATION)/ host (LIVE_BROADCASTING) leaves the channel.

Reasons why the user is offline:

  • Leave the channel: When the user/host leaves the channel, the user/host sends a goodbye message. When the message is received, the SDK assumes that the user/host leaves the channel.
  • Drop offline: When no data packet of the user or host is received for a certain period of time, the SDK assumes that the user/host drops offline. Unreliable network connections may lead to false detections, so we recommend using the Agora RTM SDK for more reliable offline detection.

Type declaration

onVideoDeviceStateChanged

onVideoDeviceStateChanged: (deviceId: string, deviceType: MEDIA_DEVICE_TYPE, deviceState: MEDIA_DEVICE_STATE_TYPE) => void

Occurs when the video device state changes.

Type declaration

onVideoPublishStateChanged

onVideoPublishStateChanged: (channel: string, oldState: STREAM_PUBLISH_STATE, newState: STREAM_PUBLISH_STATE, elapseSinceLastState: number) => void

Occurs when the video publishing state changes.

This callback indicates the publishing state change of the local video stream.

Type declaration

onVideoSizeChanged

onVideoSizeChanged: (uid: number, width: number, height: number, rotation: number) => void

Occurs when the video size or rotation of a specified user changes.

Type declaration

    • (uid: number, width: number, height: number, rotation: number): void
    • Parameters

      • uid: number

        User ID of the remote user or local user (0) whose video size or rotation changes.

      • width: number

        New width (pixels) of the video.

      • height: number

        New height (pixels) of the video.

      • rotation: number

        New rotation of the video [0 to 360).

      Returns void

onVideoStopped

onVideoStopped: () => void

Occurs when the video stops playing.

deprecated

This method is deprecated. Use LOCAL_VIDEO_STREAM_STATE_STOPPED(0) in the onLocalVideoStateChanged callback instead.

The application can use this callback to change the configuration of the view (for example, displaying other pictures in the view) after the video stops playing.

Type declaration

    • (): void
    • Returns void

onVideoSubscribeStateChanged

onVideoSubscribeStateChanged: (channel: string, uid: number, oldState: STREAM_SUBSCRIBE_STATE, newState: STREAM_SUBSCRIBE_STATE, elapseSinceLastState: number) => void

Occurs when the audio subscribing state changes.

This callback indicates the subscribing state change of a remote video stream.

Type declaration

onWarning

onWarning: (warn: WARN_CODE_TYPE, msg: string) => void

Reports a warning during SDK runtime.

In most cases, the application can ignore the warning reported by the SDK because the SDK can usually fix the issue and resume running. For example, when losing connection with the server, the SDK may report WARN_LOOKUP_CHANNEL_TIMEOUT and automatically try to reconnect.

Type declaration

Generated using TypeDoc