Callbacks and listeners

更新时间:
复制 MD 格式

This topic describes the callback and listener interfaces of the Windows SDK.

Table of contents

Note The callback method is asynchronous.

AliRtcEventListener(AliRtcEngine callback)

APIDescriptionSupported in the above version
onRemoteUserOnLineNotifyRemote user launch callback. 1.1
onRemoteUserOffLineNotifyRemote user offline callback. 1.1
onRemoteTrackAvailableNotifyCallback when the audio and video streams of remote users change. 1.1
onSubscribeChangedNotifyThe callback for the subscription result. 1.1
onFirstRemoteVideoFrameDrawnThe callback when the first frame of the remote video stream is rendered. 1.1
onOccurWarningWarning callback. 1.1
onOccurErrorError callback. 1.1
onByeCallback when the server is kicked out or the channel is closed. 1.1
onExternalDeviceStateChangeThe callback for the status change of the external device. 1.11
onFirstPacketReceivedThe callback for successful data reception of the first packet. 1.13
onFirstPacketSentThe callback for successful data sending of the first frame. 1.11
onLeaveChannelResultLeave the channel result callback. 1.15
onConnectionLostThe network disconnect callback. 1.15
onTryToReconnectAttempt network reconnection callback. 1.15
onConnectionRecoveryCallback for successful network reconnection. 1.15
onNetworkQualityChangedCallback when the network quality changes. 1.15
onUpdateRoleNotifyCallback when the user role changes. 1.16
onRTCStatsReal-time data callback (triggered once in 2 seconds). 1.17
onPerformanceLowThe callback for insufficient performance of the current device. 1.16.2
onPerformanceRecoveryThe callback for performance recovery of the current device. 1.17.19
onLastmileDetectResultWithQualityThe network quality probe callback. 1.16.2
onAudioSampleCallbackThe callback for the subscribed audio data. 1.16.2
onCaptureVideoSampleThe callback for the locally collected video data of the subscription. 1.16.2
onRemoteVideoSampleThe callback of the subscribed remote video data. 1.16.2
onJoinChannelResultAdd channel result callback. 1.17
onPublishChangedNotifyThe callback for the stream ingest result. 1.17
onRTCLocalVideoStatsThe callback for local video statistics. 1.17
onRTCRemoteVideoStatsRemote video statistics callback. 1.17
onMediaRecordEventRecording event callback. 1.17.9
onAudioVolumeCallbackUser volume size callback. 1.17.9
onMediaExtensionMsgReceivedReceive custom data callbacks. 1.17.1

API operation details

  • onRemoteUserOnLineNotify: remote user online callback.

    void onRemoteUserOnLineNotify(const AliRtc::String& uid)        
    ParameterTypeDescription
    uidconst AliRtc::String&The ID of the remote user.
  • onRemoteUserOffLineNotify: remote user offline callback.

    void onRemoteUserOffLineNotify(const AliRtc::String& uid)      
    ParameterTypeDescription
    uidconst AliRtc::String&The ID of the remote user.
  • onRemoteTrackAvailableNotify: callback when the audio and video streams of remote users change.

    Note This callback is also triggered if a remote user stops publishing.
    void onRemoteTrackAvailableNotify(const AliRtc::String& uid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack)
    ParameterTypeDescription
    uidconst AliRtc::String&The ID of the remote user.
    audioTrackAliRtcAudioTrackThe audio stream after the remote user changes.
    videoTrackAliRtcVideoTrackThe video stream after the remote user changes.
  • onSubscribeChangedNotify: the callback for subscription results.

    void onSubscribeChangedNotify(const AliRtc::String& uid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack)
    ParameterTypeDescription
    uidconst AliRtc::String&The ID of the remote user.
    audioTrackAliRtcAudioTrackSubscribe to a successful audio stream.
    videoTrackAliRtcVideoTrackSubscribe to a successful video stream.
  • onFirstRemoteVideoFrameDrawn: the callback for the completion of rendering of the first frame of the remote video stream.

    void onFirstRemoteVideoFrameDrawn(const AliRtc::String& uid, AliRtcVideoTrack videoTrack)
    ParameterTypeDescription
    uidconst AliRtc::String&The ID of the remote user.
    videoTrackAliRtcVideoTrackThe type of stream to render.
  • onOccurWarning: a warning callback. Currently, the warning callback can be ignored and will not affect normal use.

    void onOccurWarning(int warn)
    ParameterTypeDescription
    warnintThe type of the warning.
  • onOccurError: the error callback.

    If the parameter error is 16908812 or 33620229, you need to call destroy to destroy the instance, recreate the SDK instance, and then call joinChannel to join the channel.

    void onOccurError(int error)
    ParameterTypeDescription
    errorintThe type of the error that occurred.
  • onBye: callback when the server is kicked out or the channel is closed.

    void onBye(int code)      
    ParameterTypeDescription
    codeintThe type of the message. Valid values:
    • 1: kicked out by the server.
    • 2: The channel is closed.
    • 3: The same user ID is logged on to another end and kicked out by the server.
  • onExternalDeviceStateChange: The status of the external device changes.
    virtual void onExternalDeviceStateChange(const AliRtc::String &deviceName, AliRtcExternalDeviceState state) {};
    ParameterTypeDescription
    deviceNameAliRtc::StringThe external device name.
    stateAliRtcExternalDeviceStateThe status of the external device.
  • onFirstPacketReceived: the callback function that sends the first packet.
    virtual void onFirstPacketReceived(const AliRtc::String &uid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack) {};
    ParameterTypeDescription
    audioTrackAliRtcAudioTrackThe ID of the audio.
    videoTrackAliRtcVideoTrackThe ID of the video.
  • onFirstPacketSent: The callback for the first frame data being sent successfully.

    void onFirstPacketSent(AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack)
    ParameterTypeDescription
    audioTrackAliRtcAudioTrackThe first audio packet is sent.
    videoTrackAliRtcVideoTrackThe first packet of the video is sent.
  • onLeaveChannelResult: Leave the channel result callback.

    void onLeaveChannelResult(int result)
    ParameterTypeDescription
    resultint0 is returned if successful and error code information is returned if failed.
  • onConnectionLost: network disconnection callback.

    void onConnectionLost()
  • onTryToReconnect: Attempt the network reconnection callback.

    void onTryToReconnect()
  • onConnectionRecovery: The callback for successful network reconnection.

    void onConnectionRecovery()
  • onNetworkQualityChanged: callback when the network quality changes.

    void onNetworkQualityChanged(const AliRtc::String &uid,AliRtcNetworkQuality upQuality,AliRtcNetworkQuality downQuality)
    ParameterTypeDescription
    uidAliRtc::StringThe ID of the user whose network quality has changed. If the user ID is empty, it means local, and others means remote.
    upQualityAliRtcNetworkQualityUpstream network quality.
    downQualityAliRtcNetworkQualityThe downstream network quality.
  • onUpdateRoleNotify: callback when the user role changes.

    void onUpdateRoleNotify(const AliRtcClientRole old_role, const AliRtcClientRole new_role) {};
    ParameterTypeDescription
    old_roleAliRtcClientRoleThe role before the switch.
    new_roleAliRtcClientRoleThe role after the switch.
  • onRTCStats: real-time data callback (triggered once in 2 seconds). The SDK triggers this statistics callback every two seconds.

    Note The name of a 1.17 or later method is changed from onAliRTCStats to onRTCStats.
    virtual void onRTCStats(const AliRtcStats& stats)
    ParameterTypeDescription
    statsconst AliRtcStats&Session statistics.
  • onPerformanceLow: the callback for insufficient performance of the current device.

    virtual void onPerformanceLow()
  • onPerformanceRecovery : the callback for performance recovery of the current device.

    virtual void onPerformanceRecovery()
  • onLastmileDetectResultWithQuality: network quality detection callback.

    virtual void onLastmileDetectResultWithQuality(AliRtcNetworkQuality networkQuality)
    ParameterTypeDescription
    networkQualityAliRtcNetworkQualityNetwork quality.
  • onAudioSampleCallback: the callback of the subscribed audio data.

    virtual void onAudioSampleCallback(AliRtcAudioSource type, AliRtcAudioDataSample *audioSample)
    ParameterTypeDescription
    typeAliRtcAudioSourceThe type of the audio data source.
    audioSampleAliRtcAudioDataSample *The audio data.
  • onAudioVolumeCallback : user volume callback. In the AliRtcUserVolumeInfo, user_id is 0 to indicate the local stream ingest volume, 1 to indicate the remote mixing volume, and others to indicate the volume of the user.

    virtual void onAudioVolumeCallback(AliRtcAudioSource type, const AliRtcUserVolumeInfo* userVolumeInfo, int userVolumeNumber) {};
    ParameterTypeDescription
    typeAliRtcAudioSourceThe type of the audio data source.
    userVolumeInfoconst AliRtcUserVolumeInfo*An array of user volume information.
    userVolumeNumberintThe number of user volume information.
  • onMediaExtensionMsgReceived: Receive custom data callback. When a user sends custom data in a room, you can use this callback to receive data.
    virtual void onMediaExtensionMsgReceived(const AliRtc::String &uid, unsigned char* message, int size) {};
    ParameterTypeDescription
    uidconst AliRtc::String &User uid.
    messageunsigned char*The received custom data.
    sizeintThe length of the received data.
  • onCaptureVideoSample : the callback for subscribed locally collected video data.

    virtual void onCaptureVideoSample(AliRtcVideoSource videoSource, AliRtcVideoDataSample *videoSample)
    ParameterTypeDescription
    videoSourceAliRtcVideoSourceThe type of the video data.
    videoSampleAliRtcVideoDataSample *Video data.
  • onRemoteVideoSample : the callback for subscribed remote video data.

    virtual void onRemoteVideoSample(const AliRtc::String &uid, AliRtcVideoSource videoSource, AliRtcVideoDataSample *videoSample)
    ParameterTypeDescription
    uidconst AliRtc::String &The ID of the user.
    videoSourceAliRtcVideoSourceThe type of the video source.
    videoSampleAliRtcVideoDataSample *Video data.
  • onJoinChannelResult: Add channel result callback.

     virtual void onJoinChannelResult(int result) {};
    ParameterTypeDescription
    resultintThe result of adding a channel. 0 is returned if it is successful and an error code is returned if it fails.
  • onPublishChangedNotify: callback for stream ingest results.

    virtual void onPublishChangedNotify(int result, bool isPublished) {};
    ParameterParameterDescription
    resultintThe result is returned. 0 is returned if it is successful. An error code is returned if it fails.
    isPublishedintIndicates whether the stream is being ingested. Valid values: true | false.
  • onRTCLocalVideoStats: local video statistics callback.

    virtual void onRTCLocalVideoStats(const AliRtcLocalVideoStats& local_video_stats) {};
    ParameterTypeDescription
    local_video_statsAliRtcLocalVideoStatsThe statistics on local videos.
  • onRTCRemoteVideoStats: remote video statistics callback.

    vvirtual void onRTCRemoteVideoStats(const AliRtcRemoteVideoStats& remote_video_stats) {};
    ParameterTypeDescription
    remote_video_statsAliRtcRemoteVideoStatsThe statistics on remote videos.
  • onMediaRecordEvent: the callback for recording events.

    virtual void onMediaRecordEvent(int event, const AliRtc::String &filePath) {};
    ParameterParameterDescription
    eventintRecord events. Valid values:
    • 0: The recording starts.
    • 1: The recording ends.
    • 2: Failed to open the file.
    • 3: Failed to write the file.
    filePathconst AliRtc::String & Recording file path