Callbacks and listeners

更新时间:
复制 MD 格式

After reading this topic, you can learn more about the callback and listener interfaces of iOS SDK and Mac SDK.

Table of contents

The AliRtcEngineDelegate callback is shown as follows.

Note The callback method is asynchronous.
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
onNetworkQualityChangedCallback when the network quality changes. 1.4
onOccurWarningWarning callback. 1.1
onOccurErrorError callback. 1.1
onByeCallback when the server is kicked out or the channel is closed. 1.1
onFirstPacketSentWithAudioTrackThe callback for successful data sending of the first frame. 1.11
onFirstRemoteVideoFrameDrawnThe callback when the first frame of the remote video stream is rendered. 1.1
onFirstPacketReceivedWithAudioTrackThe callback for successful data reception of the first packet.
  • Mac:1.13
  • iOS:1.17.9
onVideoDetectCallbackRTC collects video data callback (iOS only). 1.14
onUserAudioMutedUser muteAudio notification callback (iOS only). 1.14
onUserVideoMutedUser muteVideo notification callback (iOS only). 1.14
onUserAudioInterruptedBeginUser audio is interrupted notification callback (iOS only). 1.14
onUserAudioInterruptedEndedUser audio interrupt end notification callback (iOS only). 1.14
onConnectionLostThe network disconnect callback. 1.14
onTryToReconnectAttempt network reconnection callback. 1.14
onConnectionRecoveryCallback for successful network reconnection. 1.14
onLeaveChannelResultLeave the channel result callback. 1.15
onUserWillResignActiveThe remote user application retreats to the background callback (iOS only). 1.15
onUserWillBecomeActiveThe remote user application returns a foreground callback (iOS only). 1.15
onPerformanceLowThe callback for insufficient performance of the current device. 1.16
onPerformanceRecoveryThe callback for performance recovery of the current device. 1.16
onUpdateRoleNotifyWithOldRoleCallback when the user role changes. 1.16
onFirstLocalVideoFrameDrawnThe local preview render gets the first frame callback (iOS only). 1.16.2
onAudioPlayingStateChangedAccompanying playback callback (iOS only). 1.16.2
onLastmileDetectResultWithQualityThe network quality probe callback. 1.16.2
onAudioDeviceRecordLevelAudio capture device test callback (Mac only). 1.16.2
onAudioDevicePlayoutLevelAudio playback device test callback (Mac only). 1.16.2
onAudioDevicePlayoutEndThe audio playback device test ends (Mac only). 1.16.2
onVideoSampleCallbackSubscribed video data callback (Mac only). 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
onVideoTextureThe Texture callback for the subscribed video. 1.16.2
onJoinChannelResultAdd channel result callback.
  • Mac:1.17
  • iOS:1.17.9
onPublishResultThe callback for the status change of the published stream. 1.17
onMediaRecordEventRecording event callback. 1.17
onRtcStatsReal-time data callback (triggered once in 2 seconds). 1.17
onRtcLocalVideoStatsThe callback for local video statistics. 1.17
onRtcRemoteVideoStatsRemote video statistics callback. 1.17
onAudioSampleCallbackThe callback for the subscribed audio data. 1.17
onAudioVolumeCallbackUser volume size callback. 1.17.9
onMediaExtensionMsgReceivedReceive custom data callbacks. 1.17.1
onAudioEffectFinishedThe callback for the end of sound playback. 1.17.30
onVideoTextureCreatedTexture callback for the subscribed video. 1.17
onVideoTextureDestoryCallback for the destruction of the Texture of the subscribed video. 1.17
onVideoPixelBufferThe callback for subscribing to the video collection data. 1.17
onSubscribeResultCallbacks for subscribing to media streams from remote users. 1.17.39
onUnsubscribeResultCallback for unsubscribing a remote user media stream. 1.17.39

API operation details

  • onRemoteUserOnLineNotify: remote user online callback.

    - (void)onRemoteUserOnLineNotify:(NSString *)uid;          
    ParameterTypeDescription
    uidNSString *The ID of the remote user.
  • onRemoteUserOffLineNotify: remote user offline callback.

    - (void)onRemoteUserOffLineNotify:(NSString *)uid;         
    ParameterTypeDescription
    uidNSString *The ID of the remote user.
  • onRemoteTrackAvailableNotify: callback when the audio and video streams of remote users change.

    - (void)onRemoteTrackAvailableNotify:(NSString *)uid audioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;              
    ParameterTypeDescription
    uidNSString *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:(NSString *)uid audioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;                   
    ParameterTypeDescription
    uidNSString *The ID of the remote user.
    audioTrackAliRtcAudioTrackSubscribe to a successful audio stream.
    videoTrackAliRtcVideoTrackSubscribe to a successful video stream.
  • onNetworkQualityChanged: Callback when the network quality changes. We recommend that you prompt users on the interface when the network quality is poor.

    - (void)onNetworkQualityChanged:(NSString *)uid 
            upNetworkQuality:(AliRtcNetworkQuality)upQuality             
            downNetworkQuality:(AliRtcNetworkQuality)downQuality;
    ParameterTypeDescription
    uidNSString *The 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.
  • 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.
  • onFirstPacketSentWithAudioTrack: The callback for the first frame data being sent successfully.

    - (void)onFirstPacketSentWithAudioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;
    ParameterTypeDescription
    audioTrackAliRtcAudioTrackThe type of audio stream that was sent successfully.
    videoTrackAliRtcVideoTrackThe type of the successfully sent video stream.
  • onFirstRemoteVideoFrameDrawn: the callback for the completion of rendering of the first frame of the remote video stream.

    - (void)onFirstRemoteVideoFrameDrawn:(NSString *)uid videoTrack:(AliRtcVideoTrack)videoTrack;
    ParameterTypeDescription
    uidNSString *The ID of the remote user.
    videoTrackAliRtcVideoTrackThe type of stream to render.
  • onFirstPacketReceivedWithAudioTrack: The first data packet is received.

    • iOS code, as follows:
      - (void)onFirstPacketReceivedWithUid:(NSString *)uid                         audioTrack:(AliRtcAudioTrack)audioTrack                         videoTrack:(AliRtcVideoTrack)videoTrack;
    • Mac code, as follows:
      - (void)onFirstPacketReceivedWithAudioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;
    ParameterTypeDescription
    audioTrackAliRtcAudioTrackThe type of audio stream that was sent successfully.
    videoTrackAliRtcVideoTrackThe type of the successfully sent video stream.
  • onVideoDetectCallback (available for iOS only):RTC collects video data callbacks.

    Note The return value of the callback is of the long type. The face data detected in the App layer Face Recognition module returns the pointer of the structure stored in this face data to the SDK. After the SDK receives this pointer, it passes the receipt to the App again in the onVideoTexture callback.
    - (long)onVideoDetectCallback:(AliRtcVideoSource)type videoFrame:(AliRtcVideoDataSample *)videoFrame;
    ParameterTypeDescription
    typeAliRtcVideoSourceThe type of the video stream.
    videoFrameAliRtcVideoDataSample *The video data frame.
  • onUserAudioMuted (iOS only): Users cancel audio notifications.

    - (void)onUserAudioMuted:(NSString *)uid audioMuted:(BOOL)isMute;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    isMuteBOOLYES indicates mute, and NO indicates unmute.
  • onUserVideoMuted (iOS only): Users cancel video notifications.

    - (void)onUserVideoMuted:(NSString *)uid videoMuted:(BOOL)isMute;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    isMuteBOOLYES indicates ingest black frames, and NO indicates normal ingest.
  • onUserAudioInterruptedBegin (only available for iOS): User audio is interrupted notification (general user calls and other audio preemption scenarios).

    - (void)onUserAudioInterruptedBegin:(NSString *)uid;
    ParameterTypeDescription
    uidNSString *The ID of the user whose audio was interrupted.
  • onUserAudioInterruptedEnded (available for iOS only): User audio interruption end notification (corresponding onUserAudioInterruptedBegin).

    - (void)onUserAudioInterruptedEnded:(NSString *)uid;
    ParameterTypeDescription
    uidNSString *The ID of the user whose audio interruption ended.
  • onConnectionLost: network disconnection callback. The Mac environment supports this callback since version 1.15.

    - (void)onConnectionLost;
  • onTryToReconnect: Attempt the network reconnection callback. The Mac environment supports this callback since version 1.15.

    - (void)onTryToReconnect;
  • onConnectionRecovery: The callback for successful network reconnection. The Mac environment supports this callback since version 1.15.

    - (void)onConnectionRecovery;
  • onLeaveChannelResult: Leave the channel result callback. This callback is returned after you call the leaveChannel operation. If you call destroy directly after you call the leaveChannel operation, no callback is received.

    - (void)onLeaveChannelResult:(int)result;
    ParameterTypeDescription
    resultint0 is returned for success and an error code is returned for failure.
  • onUserWillResignActive: The remote user application is retreated to the background.

    (void)onUserWillResignActive:(NSString *)uid
    ParameterTypeDescription
    uidNSString *The ID of the user.
  • onUserWillBecomeActive: The remote user application returns to the foreground.

    (void)onUserWillBecomeActive:(NSString *)uid
    ParameterTypeDescription
    uidNSString *The ID of the user.
  • onPerformanceLow: the callback for insufficient performance of the current device.

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

    - (void)onPerformanceRecovery;
  • onUpdateRoleNotifyWithOldRole: callback when the user role changes (this callback is triggered when the setClientRole method is called to switch the role successfully).

    - (void)onUpdateRoleNotifyWithOldRole:(AliRtcClientRole)oldRole newRole:(AliRtcClientRole)newRole;
    ParameterTypeDescription
    oldRoleAliRtcClientRoleThe type of the role before the change.
    newRoleAliRtcClientRoleThe role type after the change.
  • onFirstLocalVideoFrameDrawn: local preview rendering gets the first frame callback.

    - (void)onFirstLocalVideoFrameDrawn;
  • onAudioPlayingStateChanged: Accompaniment playback callback.

    /**
    * @brief The playback status of the accompaniment.
    * @param playState The current playback status.
    * @param errorCode The error code is returned.
     */
    - (void)onAudioPlayingStateChanged:(AliRtcAudioPlayingStateCode)playState errorCode:(AliRtcAudioPlayingErrorCode)errorCode;
    ParameterTypeDescription
    playStatusAliRtcAudioPlayingStateCodeThe current playback status.
    errorCodeintThe error code returned.
  • onLastmileDetectResultWithQuality: network quality detection callback.

    - (void)onLastmileDetectResultWithQuality:(AliRtcNetworkQuality)networkQuality;
    ParameterTypeDescription
    networkQualityAliRtcNetworkQualityNetwork quality.
  • onAudioDeviceRecordLevel: the audio capture device test callback.

    - (void)onAudioDeviceRecordLevel:(int)level;
    ParameterTypeDescription
    levelintThe audio collection device volume value.
  • onAudioDevicePlayoutLevel: the audio playback device test callback.

    - (void)onAudioDevicePlayoutLevel:(int) level;
    ParameterTypeDescription
    levelintThe volume value of the audio playback device.
  • onAudioDevicePlayoutEnd: The audio playback device test ends (the audio file is played).

    - (void)onAudioDevicePlayoutEnd;
  • onVideoSampleCallback: the callback of the subscribed video data.

    - (void)onVideoSampleCallback:(NSString *)uid videoSource:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *)videoSample;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    typeAliRtcVideoSourceThe type of the video stream.
    videoSampleAliRtcVideoDataSample *The frame rate of the video.
  • onCaptureVideoSample: the callback for subscribed locally collected video data.

    - (void)onCaptureVideoSample:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *)videoSample;
    ParameterTypeDescription
    videoSourceAliRtcVideoSourceThe video source.
    videoSampleAliRtcVideoDataSample *The frame rate of the video.
  • onRemoteVideoSample: the callback for subscribed remote video data.

    - (void)onRemoteVideoSample:(NSString *)uid videoSource:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *)videoSample;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    videoSourceAliRtcVideoSourceThe type of the video stream.
    videoSampleAliRtcVideoDataSample *The frame rate of the video.
  • onVideoTexture: the video texture (texture) callback for the subscription.

    - (int)onVideoTexture:(NSString *)uid videoTextureType:(AliRtcVideoTextureType)videoTextureType textureId:(int)textureId width:(int)width height:(int)height rotate:(int)rotate extraData:(long)extraData ;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    videoTextureTypeAliRtcVideoTextureTypeThe type of the texture.
    textureIdintThe ID of the texture.
    widthintThe width of the video.
    heightintThe height of the video.
    rotateintThe video direction.
    extraDatalongThe pointer to the face data structure of the long data type is returned in the onVideoDetectCallback callback.
  • onJoinChannelResult: Add channel result callback (this callback is equivalent to calling the block operation of the joinChannel interface. When you are processing events after adding a channel, select one of them).

    • iOS code, as follows:
      (void)onJoinChannelResult:(int)result authInfo:(AliRtcAuthInfo *)authInfo;
    • Mac code, as follows:
      - (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.
  • onPublishResult: The status of the publish stream changes. This callback is equivalent to calling the block operation of the publish operation. When you are processing events after publishing, select one of them.

    - (void)onPublishResult:(int)result isPublished:(BOOL)isPublished;
    ParameterTypeDescription
    resultintThe result of the current push-pull stream.
    isPublishedBOOLIndicates whether the stream is being ingested. Valid values:
    • YES: Yes.
    • NO: No.
  • onMediaRecordEvent: the callback for recording events.

    - (void)onMediaRecordEvent:(int)event filePath:(NSString *)filePath;
    ParameterTypeDescription
    eventintRecord events. Valid values:
    • 0: The recording starts.
    • 1: The recording ends.
    • 2: Failed to open the file.
    • 3: Failed to write the file.
    filePathNSString *The path of the recording file.
  • onRtcStats: real-time data callback (triggered once in 2 seconds).

    - (void)onRtcStats:(AliRtcStats)stats;
    ParameterTypeDescription
    statsAliRtcStatsData callback.
  • onRtcLocalVideoStats: local video statistics callback, which is triggered once in 2 seconds.

    - (void)onRtcLocalVideoStats:(AliRtcLocalVideoStats *)localVideoStats;
    ParameterTypeDescription
    localVideoStatsAliRtcLocalVideoStats *The statistics on local videos.
  • onRtcRemoteVideoStats: remote video statistics callback, which is triggered once in 2 seconds.

    - (void)onRtcRemoteVideoStats:(AliRtcRemoteVideoStats *)remoteVideoStats;
    ParameterTypeDescription
    remoteVideoStatsAliRtcLocalVideoStats *The statistics on remote videos.
  • onAudioSampleCallback: the callback of the subscribed audio data.

    - (void)onAudioSampleCallback:(AliRtcAudioSource)audioSource audioSample:(AliRtcAudioDataSample *)audioSample;
    ParameterTypeDescription
    audioSourceAliRtcAudioSourceThe type of the bare audio data source.
    audioSampleAliRtcAudioDataSample *The bare audio data.
  • onAudioVolumeCallback: user volume callback. Voice status and uid.

    - (void)onAudioVolumeCallback:(AliRtcAudioSource)audioSource userAudioinfo:(NSArray <AliRtcUserVolumeInfo *> *)array;
    ParameterTypeDescription
    audioSourceAliRtcAudioSourceThe type of the audio data.
    arrayNSArray <AliRtcUserVolumeInfo*> *Callback user volume information array, including user UID, voice status, and volume.
  • onMediaExtensionMsgReceived: Receive custom data callback. When a user sends custom data in a room, you can use this callback to receive data.
    - (void)onMediaExtensionMsgReceived:(NSString *)uid message:(NSData *)data;
    ParameterTypeDescription
    uidNSStringThe UID of the Alibaba Cloud account.
    dataNSDataThe received custom data.
  • onAudioEffectFinished: the callback for the end of sound playback.
    - (void)onAudioEffectFinished:(int)soundId;
    ParameterTypeDescription
    soundIdintThe ID assigned by the user to the sound effect file.
  • onVideoTextureCreated: the Texture callback for the subscription video.
    - (void)onVideoTextureCreated:(NSString *)uid videoTextureType:(AliRtcVideoTextureType)videoTextureType context:(void *)context;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    videoTextureTypeAliRtcVideoTextureTypeThe type of the texture.
    contextvoid *OpenGL context.
  • onVideoTextureDestory: the callback for the texture of the subscribed video to be destroyed.
    - (void)onVideoTextureDestory:(NSString *)uid videoTextureType:(AliRtcVideoTextureType)videoTextureType;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    videoTextureTypeAliRtcVideoTextureTypeThe type of the texture.
  • onVideoPixelBuffer: Subscribe to the callback for video collection data.
    - (void)onVideoPixelBuffer:(NSString *)uid videoSource:(AliRtcVideoSource)videoSource pixelBuffer:(CVPixelBufferRef)pixelBuffer;
    ParameterTypeDescription
    uidNSString *The ID of the user.
    videoSourceAliRtcVideoSourceThe type of the bare video data source.
    pixelBufferCVPixelBufferRefThe video texture buffer.
  • onSubscribeResult: the callback for subscribing to the media stream of the remote user.
    - (void)onSubscribeResult:(NSString *)uid result:(int)result audioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;
    ParameterTypeDescription
    uidNSString *The ID of the remote user.
    resultintThe subscription result. 0 indicates that the subscription is successful. An error code is returned if the subscription fails.
    audioTrackAliRtcAudioTrackSubscribe to a successful audio stream.
    videoTrackAliRtcAudioTrackSubscribe to a successful video stream.
  • onUnsubscribeResult: the callback for unsubscribing a media stream from a remote user.
    - (void)onUnsubscribeResult:(NSString *)uid result:(int)result;
    ParameterTypeDescription
    uidNSString *The ID of the remote user.
    resultintThe subscription result. 0 indicates that the subscription is canceled. An error code is returned if the subscription fails.