All Products
Search
Document Center

ApsaraVideo Live:AliRtcEngine Interface

Last Updated:Feb 08, 2026

This topic describes the interfaces provided by the ApsaraVideo Real-time Communication iOS SDK.

Directory

Basic methods

API

Description

sharedInstance

Creates an AliRtcEngine instance. This is a singleton method.

destroy[1/2]

Destroys an AliRtcEngine instance synchronously.

destroy[2/2]

Destroys an AliRtcEngine instance asynchronously.

setH5CompatibleMode

Specifies whether to enable the HTML5 compatibility mode.

getH5CompatibleMode

Check if the current environment is compatible with HTML5.

getSdkVersion

Gets the SDK version number.

Channel-related methods

API

Description

setChannelProfile

Sets the channel mode.

setAudioProfile

Sets the audio profile.

isAudioOnly

Queries whether the audio-only mode is enabled.

setAudioOnlyMode

Enables the audio-only mode or the audio-video mode.

joinChannel[1/3]

Joins a channel.

joinChannel[2/3]

Joins a channel.

joinChannel[3/3]

Joins a channel.

leaveChannel

Leaves a channel.

isInCall

Checks whether the user is in a channel.

setClientRole

Specifies the role of a user.

getCurrentClientRole

Queries the user role.

refreshAuthInfo

Refreshes the authentication information.

refreshAuthInfoWithToken

Refreshes the authentication information.

Publishing and subscription-related methods

API

Description

publishLocalAudioStream

Specifies whether to publish an audio track. By default, the audio track is published.

isLocalAudioStreamPublished

Queries whether an audio track is published.

setDefaultSubscribeAllRemoteAudioStreams

Specifies whether to subscribe to the audio tracks of remote users. By default, all remote audio tracks are subscribed to.

We recommend that you call this method before users join the channel.

subscribeRemoteAudioStream

Subscribes to or stops subscribing to the audio track of a specific remote user.

subscribeAllRemoteAudioStreams

Subscribes to or stops subscribing to the audio tracks of all remote users.

publishLocalVideoStream

Specifies whether to publish a video track.

isLocalVideoStreamPublished

Queries whether a video track is published.

setDefaultSubscribeAllRemoteVideoStreams

Specifies whether to subscribe to the video tracks of remote users. By default, all remote video tracks are subscribed to.

We recommend that you call this method before users join the channel.

subscribeRemoteVideoStream

Subscribes to or stops subscribing to the video track of a remote user.

subscribeAllRemoteVideoStreams

Subscribes to or stops subscribing to the video tracks of all remote users.

subscribeRemoteMediaStream[1/2]

You can stop or resume the media streams of specific remote users.

We recommend that you call this method when both the audio and video tracks are available and need to be managed.

subscribeRemoteMediaStream[2/2]

You can stop or resume the media stream for a specific remote user.

We recommend that you call this method when both audio and video tracks are available and need to be managed.

subscribeRemoteDestChannelStream

You can stop or resume the media stream of a specific remote user across channels.

subscribeRemoteDestChannelAllStream

Subscribes to the streams of all users in the target channel.

setRemoteAudioVolume

Sets the volume of a remote user's audio.

Methods related to audio device management

API

Description

muteLocalMic

Specifies whether to mute the local audio.

muteRemoteAudioPlaying

Specifies whether to stop the playback of the audio track of a specific remote user.

muteAllRemoteAudioPlaying

Specifies whether to stop the playback of the audio tracks of all remote users.

startAudioCapture[1/2]

Starts audio collection.

startAudioCapture[2/2]

Starts audio collection.

stopAudioCapture

Stops audio collection.

enableSpeakerphone

Sets the headset or speaker as the audio output device.

isEnableSpeakerphone

Queries whether the current audio output device is the headset or the speaker.

enableAudioVolumeIndication

Enables volume detection.

enableEarBack

Enables in-ear monitoring.

setEarBackVolume

Sets the volume for in-ear monitoring. This method applies only to iOS.

startAudioPlayer

Starts audio playback.

stopAudioPlayer

Stops audio playback.

setPlayoutVolume

Sets the playback volume.

setRecordingVolume

Sets the capture volume.

playAudioFileTest

Starts testing the audio playback device.

stopAudioFileTest

Stops testing the audio playback device.

startAudioCaptureTest

Starts testing the audio capture device.

stopAudioCaptureTest

Stops testing the audio capture device.

setDefaultAudioRoutetoSpeakerphone

Sets the default audio output device.

Methods related to voice change and reverberation

API

Description

setAudioEffectVoiceChangerMode

Sets the voice change mode.

setAudioEffectPitchValue

You can set the pitch adjustment parameters.

setAudioEffectReverbMode

Sets the reverberation mode.

setAudioEffectReverbParamType

Sets the parameters of the reverberation mode.

setAudioEffectBeautifyMode

Sets a predefined voice beautification effect mode.

setAudioEffectEqualizationParam

Sets audio equalizer (EQ) parameters to adjust gain at specified frequency bands.

Custom audio input

API

Description

addExternalAudioStream

Adds an external audio track.

pushExternalAudioStream

Imports external audio data.

setExternalAudioStream:publishVolume

Sets the volume of external audio for stream ingest.

getExternalAudioStreamPublishVolume

Queries the volume of external audio for stream ingest.

setExternalAudioStream:playoutVolume

Sets the playback volume of external audio.

getExternalAudioStreamPlayoutVolume

Queries the playback volume of external audio.

removeExternalAudioStream

Delete an external stream ingest.

Audio accompaniment

API

Description

getAudioFileInfo

Gets audio accompaniment file information.

startAudioAccompanyWithFile

Starts playing an accompaniment file.

stopAudioAccompany

Stops playing an accompaniment file.

setAudioAccompanyVolume

Sets the accompaniment volume.

setAudioAccompanyPublishVolume

Sets the volume for publishing the accompaniment file.

getAudioAccompanyPublishVolume

Gets the volume for publishing the accompaniment file.

setAudioAccompanyPlayoutVolume

Sets the playback volume of the accompaniment file.

getAudioAccompanyPlayoutVolume

Gets the playback volume of the accompaniment file.

pauseAudioAccompany

Pauses accompaniment playback.

resumeAudioAccompany

Resumes accompaniment playback.

getAudioAccompanyDuration

Gets the duration of the accompaniment file.

getAudioAccompanyCurrentPosition

Gets the current playback position of the accompaniment file.

setAudioAccompanyPosition

Sets the playback position of the accompaniment file.

Sound Effect Files

API

Description

preloadAudioEffectWithSoundId

Preloads a sound effect.

unloadAudioEffectWithSoundId

Deletes a preloaded sound effect.

playAudioEffectWithSoundId

Starts the playback of a sound effect.

stopAudioEffectWithSoundId

Stops the playback of a sound effect.

stopAllAudioEffects

Stops the playback of all sound effects.

pauseAudioEffectWithSoundId

Pauses the playback of a sound effect.

pauseAllAudioEffects

Pauses the playback of all sound effects.

resumeAudioEffectWithSoundId

Resumes the playback of a sound effect.

resumeAllAudioEffects

You can recover all sound effect files.

setAudioEffectPublishVolumeWithSoundId

Sets the volume of a sound effect for stream ingest.

getAudioEffectPublishVolumeWithSoundId

Queries the volume of a sound effect for stream ingest.

setAllAudioEffectsPublishVolume

Sets the volume of all sound effects for stream ingest.

setAudioEffectPlayoutVolumeWithSoundId

Sets the volume of a sound effect for local playback.

getAudioEffectPlayoutVolumeWithSoundId

Queries the volume of a sound effect for local playback.

setAllAudioEffectsPlayoutVolume

Sets the volume of all sound effects for local playback.

Record audio and video files

API

Description

startRecord

Records audio and video files in AAC, WAV, or MP4 format.

stopRecord

Stops recording audio and video files.

Methods related to video device management

API

Description

setLocalViewConfig

Sets the rendering view and drawing parameters for local preview.

setCameraCapturerConfiguration

Sets the collection preferences of the camera.

enableLocalVideo

Disables or re-enables local video collection.

muteLocalCamera

Specifies whether to stop publishing a local video track.

setRemoteViewConfig

Sets the rendering view and drawing parameters for the video track of a remote user.

isCameraOn

Queries whether the camera is turned on.

setVideoEncoderConfiguration

Sets video encoding properties.

setVideoDecoderConfiguration

Sets video decoding properties.

switchCamera

Switches between the front and rear cameras. By default, the front camera is used.

getCurrentCameraDirection

You can obtain the current camera direction.

startPreview

Starts a local preview.

stopPreview

Stops a local preview.

setCameraZoom

Sets camera zoom.

GetCameraMaxZoomFactor

Gets the maximum camera zoom factor.

GetCurrentZoom

Retrieve the camera’s maximum scaling ratio.

SetExposure

Sets camera exposure.

GetCurrentExposure

Gets camera exposure.

GetMinExposure

Gets the minimum camera exposure level.

GetMaxExposure

Gets the maximum camera exposure level.

setCameraFlash

Sets the camera flash mode.

isCameraFocusPointSupported

Queries whether manual focus is supported.

isCameraExposurePointSupported

Queries whether setting an exposure point is supported.

setCameraFocusPoint

Sets the manual focus point for the camera.

setCameraExposurePoint

Sets the camera exposure point.

isCameraAutoFocusFaceModeSupported

Queries whether face autofocus is supported.

setCameraAutoFocusFaceModeEnabled

Enables or disables face autofocus.

setVideoMirrorMode

Sets mirroring for local preview and stream ingest.

SetCapturePipelineScaleMode

Sets when scaling occurs in the video capture pipeline—either during capture or during encoding.

Configure video data callbacks

API

Description

registerVideoFrameWithObserver

Registers a video data callback.

unregisterVideoSampleWithObserver

Unregisters a video data callback.

registerLocalVideoTextureObserver

Registers a video texture callback.

unregisterLocalVideoTextureObserver

Unregisters a video texture callback.

snapshotVideo

Takes a snapshot of the camera feed.

registerVideoSampleObserver

Registers a callback for exporting video data.

unRegisterVideoSampleObserver

Unregisters a callback for exporting video data.

Configure audio data callbacks

API

Description

enableAudioFrameObserver

Configures audio callback settings.

registerAudioFrameObserver

Registers an audio callback.

Custom Video Input

API

Description

setExternalVideoSource

Specify whether to enable an external video source.

pushExternalVideoFrame

Input the video data.

Desktop Sharing Interface

API

Description

startScreenShare

Starts ingesting a screen-sharing stream.

startScreenShare

Starts ingesting a screen-sharing stream.

Note

The method will be phased out.

stopScreenShare

Stop the stream ingest for screen sharing.

setAudioShareAppVolume

Sets the volume of the shared audio stream.

isScreenSharePublished

Queries whether a screen-sharing stream is being published.

setScreenShareEncoderConfiguration

Configures screen sharing encoding parameters.

Live Streaming Bypass Interface

API

Description

startPublishLiveStreamWithURL

Starts relayed live streaming.

updatePublishLiveStreamWithURL

Updates the parameters for relayed live streaming.

stopPublishLiveStreamWithURL

Stops relayed live streaming.

GetPublishLiveStreamStateWithURL

Queries the status of relayed live streaming.

Network Quality Probe Interface

API

Description

startLastmileDetect

Starts network quality testing.

stopLastmileDetect

Stops network quality testing.

SEI

API

Description

sendMediaExtensionMsg

Sends SEI messages.

sendMediaExtensionMsgEx

Sends SEI messages (extended).

Other APIs

API

Description

setParameter

Sets custom parameters.

getParameter

Queries custom parameters.

setLogDirPath

Sets the path for storing the log files of the SDK.

setLogLevel

Sets the log level.

setAudioSessionOperationRestriction

Specifies whether the SDK has the permission to control AVAudioSession.

setDeviceOrientationMode

Sets the device orientation.

getNetworkTime

Gets the network timestamp.

sendDataChannelMessage

Sends a data channel message.

AliveEnv methods

API

Description

setGlobalEnvironment

Sets the global environment.

Callbacks

AliRtcEngineDelegate

API

Description

onConnectionStatusChange

The callback that is invoked when the network connection status changes. Pay attention to this callback.

onLocalDeviceException

The callback that is invoked when a local device exception occurs. Pay attention to this callback.

onAuthInfoWillExpire

The callback that is invoked when user authentication is about to expire. The authentication expires 30 seconds after you receive this callback. Pay attention to this callback.

onAuthInfoExpired

When you call an API that requires authentication, the server returns a message indicating that the authentication has expired.

onJoinChannelResult

The callback that is invoked to return the result of joining a channel.

onLeaveChannelResult

The callback that is invoked to return the result of leaving a channel.

onRemoteUserOffLineNotify

Offline notification for remote users.

onRemoteUserOnLineNotify

Notification that a remote user is online.

onRemoteTrackAvailableNotify

Notifications for remote stream ingest.

onBye

Message sent when you are disconnected by the server or the channel ends after the meeting concludes.

onAudioPublishStateChanged

Notification of audio stream ingest status.

onAudioSubscribeStateChanged

Status notifications for audio stream pulling.

onUserAudioMuted

Notification for remote user mute.

onUserAudioInterruptedBegin

Notification of an audio device interruption starting.

onUserAudioInterruptedEnded

The callback that is invoked when the interruption of an audio device ends.

onVideoPublishStateChanged

The callback that is invoked when the status of the stream ingest for a video track changes.

onVideoSubscribeStateChanged

The callback that is invoked when the status of subscription to a video track changes.

onUserVideoMuted

The callback that is invoked when a remote user sends black frames for the video track.

onUserVideoEnabled

The remote user stops sending the camera stream and sends a notification.

onUserWillResignActive

The remote user's application moves to the background.

onUserWillBecomeActive

The remote user's application returns to the foreground.

onAudioEffectFinished

The callback that is invoked when the local playback of a sound effect ends.

onAudioVolumeCallback

The subscribed audio volume, voice status, and UID.

onActiveSpeaker

The callback that is invoked when an active user is detected speaking.

onPublishLiveStreamStateChanged

The callback that is invoked when the status of relayed live streaming changes.

onPublishTaskStateChanged

The callback that is invoked when the status of a relayed live streaming task changes.

onNetworkQualityChanged

The callback that is invoked when the network quality changes.

onLastmileDetectResultWithQuality

The callback for network quality probing results.

onLastmileDetectResultWithBandWidth

The callback that is invoked to return network quality probing results.

onOccurError

The callback that is invoked when an error occurs in the engine. Use this callback to notify your app.

onFirstAudioPacketSentWithTimecost

The callback that is invoked when the first audio packet is sent.

onFirstVideoFrameReceivedWithUid

The callback that is invoked when the first video frame is received.

onFirstVideoPacketSentWithVideoTrack

The callback that is invoked when the first video packet is sent.

onFirstAudioPacketReceivedWithUid

The callback that is invoked when the first audio packet is received.

onFirstRemoteAudioDecodedWithUid

The callback that is invoked when the first remote audio frame is decoded.

onFirstRemoteVideoFrameDrawn

The callback that is invoked when the first video frame from a remote user is rendered.

onFirstLocalVideoFrameDrawn

The callback that is invoked when the first local video frame is rendered during preview.

onTestAudioVolumeCallback

The volume callback for audio capture testing before a call.

onAudioAccompanyStateChanged

The callback that is invoked when local accompaniment playback state changes.

onRemoteAudioAccompanyStarted

The callback that is invoked when a remote user starts playing accompaniment.

onRemoteAudioAccompanyFinished

The callback that is invoked when a remote user finishes playing accompaniment.

onRtcStats

The real-time statistics callback, triggered every two seconds.

onRtcLocalVideoStats

Local video performance statistics (triggered every 2 seconds).

onRtcRemoteVideoStats

Remote video performance statistics (triggered every 2 seconds).

onRtcLocalAudioStats

The local audio statistics callback, triggered every two seconds.

onRtcRemoteAudioStats

Provides remote audio statistics. This event is triggered every 2 seconds.

onMediaExtensionMsgReceived

The callback that is invoked when media extension messages are received.

onAudioRouteChanged

The callback that is invoked when the audio route changes.

onSnapshotComplete

The snapshot completion callback.

onLocalAudioStateChanged

The callback that is invoked when the local audio capture device state changes.

onLocalVideoStateChanged

The callback that is invoked when the local video capture device state changes.

onRemoteUserSubscribedDataChannel

The callback that is invoked when you can start sending data channel messages.

onDataChannelMessage

The data channel message callback.

onScreenSharePublishStateChanged

The callback that is invoked when screen sharing stream ingest status changes.

AliRtcAudioFrameDelegate

API

Description

onCapturedAudioFrame

The callback for raw captured audio data.

onProcessCapturedAudioFrame

The callback for audio data after 3A processing.

onPublishAudioFrame

Stream ingest data callback.

onPlaybackAudioFrame

The callback for audio playback data.

onRemoteUserAudioFrame

The callback for remote audio stream data.

AliRtcEngineDestroyDelegate

API

Description

onDestroyCompletion

The callback that is invoked when the engine is destroyed. The engine is fully released only after this callback completes.

AliRtcTextureDelegate

API

Description

onTextureCreate

The OpenGL context creation callback.

onTextureUpdate

The OpenGL texture update callback.

onTextureDestory

The OpenGL context destruction callback.

AliRtcVideoFrameDelegate

API

Description

onCaptureVideoSample

The callback for captured video frames.

onPreEncodeVideoSample

The callback for local video data before encoding.

onRemoteVideoSample

The callback for remote video data.

onGetVideoFormatPreference

The video data output format.

onGetVideoObservedFramePosition

The video data output position.

Details

sharedInstance

Creates an AliRtcEngine instance using the singleton pattern.

+ (instancetype _Nonnull )sharedInstance:(id<AliRtcEngineDelegate>_Nullable)delegate extras:(NSString *_Nullable)extras;

When to call

Call this method before calling any other ARTC SDK APIs to create an AliRtcEngine instance.

Limitations

  • This method is synchronous and must be called on the main thread.

  • The SDK supports only one AliRtcEngine instance per app.

Related callbacks

Implement the callbacks in AliRtcEngineDelegate based on your use case when creating the engine instance. If the SDK encounters an exception during operation, it first attempts internal retries to recover automatically. For errors that cannot be resolved internally, the SDK notifies your application through predefined callbacks. The following are key callbacks that require application-level handling:

Root cause

Callback and parameters

Solution

Notes

Authentication failure

The onJoinChannelResult callback returns AliRtcErrJoinBadToken.

Check whether the token is valid when this error occurs.

When users explicitly call an API and authentication fails, the error is returned in the API's callback.

Network connection failure

The onConnectionStatusChange callback returns AliRtcConnectionStatusFailed.

Rejoin the channel when this error occurs.

The SDK has built-in network recovery capability. However, if disconnection exceeds the preset timeout threshold, the SDK triggers a timeout and disconnects. In this case, check the network status and guide users to rejoin the channel.

Local device exception

onLocalDeviceException

Check permissions and hardware status when this error occurs.

ARTC supports device detection and diagnostics. When a local device exception occurs, ARTC notifies your application via callback. If the SDK cannot resolve the issue, your app must intervene to verify device health.

Kicked out of the channel

onBye

  • AliRtcOnByeUserReplaced: Check whether the user ID is duplicated when this error occurs.

  • AliRtcOnByeBeKickedOut: Indicates the user was kicked out by business logic. Rejoin the channel.

  • AliRtcOnByeChannelTerminated: Indicates the channel was terminated. Rejoin the channel.

ARTC provides administrators with the ability to actively remove participants.

Authentication about to expire

onWillAuthInfoExpire

When this exception occurs, the app should first reacquire the latest authentication information and then call refreshAuthInfo.

Authentication expiration occurs in two cases: when users call an API or during program execution. Therefore, errors are reported either in the API callback or through a dedicated error callback.

Authentication expired

onAuthInfoExpired

Rejoin the channel when this error occurs.

Authentication expiration occurs in two cases: when users call an API or during program execution. Therefore, errors are reported either in the API callback or through a dedicated error callback.

Parameters

Name

Type

Description

delegate

id<AliRtcEngineDelegate>_Nullable

The delegate that listens to callback events.

extras

NSString *_Nullable

Used to receive gray-scale release parameters from customers. Configures special SDK features using a JSON string. Can be an empty string.

destroy[1/2]

Destroys the AliRtcEngine instance.

+ (void)destroy;

Destroys the AliRtcEngine singleton object. After you invoke this method, all internally used resources are released. You cannot use any other AliRtcEngine methods or callbacks. To use AliRtcEngine again, you must invoke <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#2db21d4f16s77" id="96631a9306wq8">sharedInstance</a> to create a new instance.

This method and destroy[2/2] both destroy engine instances, but the difference is that destroy[2/2] lets you pass in a monitor object for completion of destruction.

Note
  • If you plan to recreate the AliRtcEngine instance, ensure this method completes before doing so.

  • After calling this method, set the engine object to nil.

When to call

Call this method to release the instance after real-time communication ends (that is, when you no longer need AliRtcEngine functionality). This reduces unnecessary resource usage.

Limitations

To avoid deadlocks, do not call this method from within any SDK callback.

destroy[2/2]

Destroys the AliRtcEngine instance.

+ (void)destroy:(id<AliRtcEngineDestroyDelegate>_Nullable)delegate;

Destroys the AliRtcEngine singleton object. After you invoke this method, all resources that the object uses internally are released. You can no longer use any other AliRtcEngine methods or any callbacks. To use AliRtcEngine again, you must invoke <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#2db21d4f16s77" id="115fd691743nx">sharedInstance</a> to create a new instance.

Note

Both destroy[1/2] and this method release the AliRtcEngine instance. However, this method is asynchronous and accepts an observer to monitor its completion. You can safely create a new instance only after onDestroyCompletion is invoked.

When to call

We recommend calling this method to release the instance after completing real-time communication.

Limitations

To avoid deadlocks, do not call this method from within any SDK callback.

Parameters

Name

Type

Description

delegate

AliRtcEngineDestroyDelegate

The observer that receives the completion callback.

setH5CompatibleMode

Specify whether to enable the HTML5 compatibility mode.

Important

You cannot modify the HTML5 compatibility settings for the current version after you create an AliRtcEngine instance. You must call this method before you create an AliRtcEngine instance.

+ (void)setH5CompatibleMode:(BOOL)comp;

Parameters

Name

Type

Description

comp

BOOL

A value of YES enables the HTML5 compatibility mode. A value of NO disables the HTML5 compatibility mode. Default value: NO.

getH5CompatibleMode

Queries whether the HTML5 compatibility mode is enabled.

+ (BOOL)getH5CompatibleMode;

Return Description

A value of YES indicates that the HTML5 compatibility mode is enabled. A value of NO indicates that the HTML5 compatibility mode is disabled.

getSdkVersion

Retrieves the SDK version number.

+ (NSString *_Nonnull)getSdkVersion;

Return value

The current SDK version number as a string, for example: "2.5.0.x".

Notes

This is a static method. You can call it at any time to retrieve the version number.

setChannelProfile

Sets the channel mode.

- (int)setChannelProfile:(AliRtcChannelProfile)profile;

This method sets the channel profile. Two primary profiles are available:

  • Communication profile: All users act as streamers and can both publish and subscribe streams.

  • Interactive live streaming profile: You must call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#892915dd4edcy" id="d88dccff391by">setClientRole</a> to set the client role. Set the role of users who ingest streams in the channel to streamer (AliRTCSdkInteractive). If a user only needs to pull streams and does not ingest streams, set their role to viewer (AliRTCSdkLive). This profile is recommended for RTC scenarios.

Note
  • We recommend the interactive live streaming profile for all RTC scenarios. Set the profile to AliRTCSdkInteractiveLive.

  • All users in the same channel must use the same channel profile.

When to call

You can call this method only before joining a channel. You cannot change the profile while in a channel. You can change it after leaving the channel.

Parameters

Name

Type

Description

profile

AliRtcChannelProfile

The channel type. For RTC scenarios, we recommend setting this to AliRtcChannelProfileInteractiveLive, which is interactive live streaming mode.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAudioProfile

Sets the audio profile.

- (int)setAudioProfile:(AliRtcAudioProfile)audio_profile audio_scene:(AliRtcAudioScenario)audio_scene;

This method configures audio encoding and audio scenario modes. For more information, see Common audio operations and configurations. By default, the ARTC SDK uses high-quality audio mode (AliRtcEngineHighQualityMode) and music scenario mode (AliRtcSceneMusicMode). If the defaults do not meet your needs, call this method to configure them.

When to call

You can call this method only before joining a channel. You cannot change it after joining. You can change it after leaving the channel.

Parameters

Name

Type

Description

audio_profile

AliRtcAudioProfile

Audio capture or encoding mode parameter. We recommend high-quality mode (AliRtcEngineHighQualityMode).

Note

For interoperability with Web clients, set the sample rate to 48 kHz.

  • AliRtcEngineLowQualityMode: Low-quality audio mode. Default sample rate: 8 kHz. Mono. Max bitrate: 12 kbps.

  • AliRtcEngineBasicQualityMode: Standard audio quality mode. Default sample rate: 16 kHz. Mono. Max bitrate: 24 kbps.

  • AliRtcEngineHighQualityMode: Default sample rate: 48 kHz. Mono. Max bitrate: 64 kbps.

  • AliRtcEngineStereoHighQualityMode: Stereo high-quality mode. Default sample rate: 48 kHz. Stereo. Max bitrate: 80 kbps.

  • AliRtcEngineSuperHighQualityMode: Super-high-quality mode. Default sample rate: 48 kHz. Mono. Max bitrate: 96 kbps.

  • AliRtcEngineStereoSuperHighQualityMode: Stereo super-high-quality mode. Default sample rate: 48 kHz. Stereo. Max bitrate: 128 kbps.

audio_scene

AliRtcAudioScenario

Audio scenario mode parameter. Options include the following:

  • AliRtcSceneMusicMode (recommended): Music scenario. Uses software-based 3A processing. Captures from the phone microphone for higher audio fidelity.

  • AliRtcSceneDefaultMode: Uses hardware-based 3A processing. Supports Bluetooth devices.

Note

Do not set this to chatroom mode (AliRtcSceneChatroomMode) for ARTC SDK v6.21 and later.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

isAudioOnly

Queries whether the audio-only mode is enabled.

- (BOOL)isAudioOnly;

Return description

A value of YES indicates that the audio-only mode is enabled. A value of NO indicates that the audio-video mode is enabled.

setAudioOnlyMode

Enables the audio-only mode or the audio-video mode.

- (int)setAudioOnlyMode:(BOOL)audioOnly;

Parameters

Name

Type

Description

audioOnly

BOOL

  • A value of YES enables the audio-only mode.

  • NO indicates that both audio and video are supported. This is the default value.

Return instructions

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

joinChannel[1/3]

Join a channel (that is, join the meeting).

- (int)joinChannel:(NSString *_Nonnull)token channelId:(NSString *_Nullable)channelId userId:(NSString *_Nullable)userId name:(NSString *_Nullable)userName onResultWithUserId:(void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed))onResult;

This method joins a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, along with joinChannel[2/3] and joinChannel[3/3], can be used to join a channel. The differences lie in authentication method and user information passed:

  • This is a single-parameter join method. Pass a token generated using Token authentication. We recommend this method for RTC scenarios.

  • joinChannel[2/3] is a multi-parameter join method. Pass a token generated using Token authentication, and also pass the user information used to generate the token.

  • joinChannel[3/3] is for AI real-time interaction scenarios. Pass a single-parameter token and set the user property capabilityProfile according to the scenario.

Note

By default, when you join a channel, you subscribe to the audio and video streams of all other users in the channel and push your audio and video streams to remote users. If you want to cancel the default subscription, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="2e9165006d7tz">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="96cf16cf8a4us">setDefaultSubscribeAllRemoteVideoStreams</a> before you call this API to disable the subscription to audio or video streams.

When to call

Call this method after creating the engine instance.

Limitations

  • After you successfully join a channel, to join another channel mid-session, you must first call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#449873b819cz2" id="37299758eavvg">leaveChannel</a> to leave the current channel and ensure that you receive the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="50039f328fdk7">onLeaveChannelResult</a> callback before you join a channel again.

  • This method supports joining only one channel at a time.

  • Apps with different App IDs cannot interoperate.

  • No need to call this method when retrying after a failed join.

Related callbacks

After successfully calling this method, the following callbacks are triggered:

  • The result of the local client joining a channel is notified through the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6d2a213d7sl2" id="903005c54be4d">onJoinChannelResult</a> callback.

  • After you successfully join the channel, the remote side triggers the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#634626babfq9x" id="4b11b846b1f4t">onRemoteUserOnLineNotify</a> callback.

Parameters

Parameter

Type

Description

token

String

The authentication information for single-parameter input.

channelId

String

The ID of the channel to join. The value must be the same as the channel ID that is used to generate the token.

userId

String

The ID of the user who wants to join the channel. The value must be the same as the user ID that is used to generate the token.

userName

String

The display name of the user. It is not the user ID.

onResultWithUserId

void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed)

This callback is invoked after the interface finishes executing.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

joinChannel[2/3]

Join a channel, which is a multi-participant session.

- (int)joinChannel:(AliRtcAuthInfo *_Nonnull)authInfo name:(NSString *_Nullable)userName onResultWithUserId:(void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed))onResult;

This method joins a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, along with joinChannel[1/3] and joinChannel[3/3], can be used to join a channel. The differences lie in authentication method and user information passed:

  • joinChannel[1/3] is a single-parameter join method. Pass a token generated using Token authentication. We recommend this method for RTC scenarios.

  • This is a multi-parameter join method. Pass a token generated using Token authentication, and also pass the user information used to generate the token.

  • joinChannel[3/3] is for AI real-time interaction scenarios. Pass a single-parameter token and set the user property capabilityProfile.

Note
  • By default, when you join a channel, you subscribe to audio and video streams from all other users in the channel and push your audio and video streams to remote users. To disable the default subscription, call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="fb54669796mxq">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="abb190b699jg7">setDefaultSubscribeAllRemoteVideoStreams</a> before calling this interface to disable subscription to audio streams or video streams.

  • Before calling this method, refer to Token authentication to generate a multi-parameter token.

Limitations

  • To switch channels after joining one, you must first call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#449873b819cz2" id="4283c6cc013bz">leaveChannel</a> to leave your current channel. You can join a new channel only after you receive the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="9e6478b2f0hen">onLeaveChannelResult</a> callback.

  • This method supports joining only one channel at a time.

  • Apps with different App IDs cannot interoperate.

Related callbacks

After successfully calling this method, the following callbacks are triggered:

  • The <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6d2a213d7sl2" id="df00346ea8928">onJoinChannelResult</a> callback returns the result of the local user joining the channel.

  • After you successfully join the channel, a remote user triggers the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#634626babfq9x" id="c3832e71e8vck">onRemoteUserOnLineNotify</a> callback.

Parameters

Name

Type

Description

authInfo

AliRtcAuthInfo

The authentication information.

userName

String

The display name of the user. It is not the user ID.

onResultWithUserId

void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed)

This callback is called when the interface finishes execution.

joinChannel[3/3]

Joins a channel.

- (int)joinChannel:(NSString *_Nonnull)token channelParam:(AliRtcChannelParam *_Nonnull)channelParam onResultWithUserId:(void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed))onResult;

This method joins a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, along with joinChannel[1/3] and joinChannel[2/3], can be used to join a channel. The differences lie in authentication method and user information passed:

  • joinChannel[1/3] is the RTC scenario single-parameter join method. Pass a token generated using Token authentication. We recommend this method for RTC scenarios.

  • joinChannel[2/3] is a multi-parameter join method. Pass a token generated using Token authentication, and also pass the user information used to generate the token.

  • This method is for AI real-time interaction scenarios. Pass a single-parameter token and set the user property capabilityProfile. When communicating with AI agents, set this to AliRtcCapabilityProfileAiHuman.

Note

If no special configuration is applied, when you join a channel, you subscribe to audio and video streams from all other users in the channel by default, and you push your audio and video streams to remote users by default. To disable the default subscription, call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="ce6cfa82f9xzc">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="e65b420fd5kj6">setDefaultSubscribeAllRemoteVideoStreams</a> before calling this interface to disable subscription to audio or video streams.

Limitations

  • After you successfully join a channel, to join another one, you must first call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#449873b819cz2" id="923190466431o">leaveChannel</a> to leave the current channel and ensure that you receive the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="dfd794c32covq">onLeaveChannelResult</a> callback before you can join another channel.

  • This method supports joining only one channel at a time.

  • Apps with different App IDs cannot interoperate.

  • No need to call this method when retrying after a failed join.

Related callbacks

After successfully calling this method, the following callbacks are triggered:

  • The result of the local user joining a channel is returned by the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6d2a213d7sl2" id="f83d0aff9btwh">onJoinChannelResult</a> callback.

  • After you successfully join the channel, remote users trigger the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#634626babfq9x" id="aeef817be3a0b">onRemoteUserOnLineNotify</a> callback.

Parameters

Name

Type

Description

token

NSString*

The authentication information obtained from the AppServer.

channelParam

AliRtcChannelParam

The parameters for joining the channel.

onResultWithUserId

void(^_Nullable)(NSInteger errCode,NSString * _Nonnull channel,NSInteger elapsed)

This callback is invoked after this interface executes.

leaveChannel

Leaves a channel.

- (int)leaveChannel;

After calling this method, the SDK terminates real-time communication and leaves the current channel.

Note
  • This method is an asynchronous operation. When successfully invoked, it does not immediately leave the channel. You must wait for the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="e7c0222bacrpa">onLeaveChannelResult</a> callback before the channel is actually left.

  • After calling leaveChannel, destroy the engine and set the engine reference to nil.

When to call

  • Call this method when you need to leave a channel after joining.

  • If you have joined a channel and need to join another channel, call this method first.

Related callbacks

  • Local user: After this method is called, the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="ea2e36a41csu0">onLeaveChannelResult</a> callback is triggered to report the result of leaving the channel.

  • Remote side: After you successfully call this operation, remote users trigger the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#34876c27d7zv7" id="a50f534f21mew">onRemoteUserOffLineNotify</a> callback.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

isInCall

Checks whether you are in a channel.

- (BOOL)isInCall;

Return description

A value of YES indicates that you are in the channel. A value of NO indicates that you are not in the channel.

setClientRole

Specifies the user role.

- (int)setClientRole:(AliRtcClientRole)role;

This method sets the user role as streamer or viewer.

In interactive mode, before joining a channel:

  • Set the user role to streamer: The SDK automatically publishes local audio and video streams and subscribes to other streamers' streams.

  • Set the user role to viewer: The SDK does not publish local audio or video streams, but subscribes to other streamers' streams.

When to call

You can call this method before or after joining a channel. You can set the role before joining or switch roles after joining.

Limitations

This method is effective only in interactive mode, that is, when you call the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#fc9626a99f5kj" id="cd8138c77fv4r">setChannelProfile</a> method and set the channel profile to AliRtcInteractivelive.

We recommend explicitly setting the user role before joining in interactive mode.

Parameters

Name

Type

Description

role

AliRtcClientRole

The user role. The default value is AliEngineClientRoleLive, which indicates a viewer. This parameter takes effect only in non-communication mode.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

getCurrentClientRole

Queries the role of a user. This method applies only to iOS.

- (AliRtcClientRole)getCurrentClientRole;

Return Value

The user role is returned.

refreshAuthInfo

Refreshes the authentication information.

- (int)refreshAuthInfo:(AliRtcAuthInfo *_Nonnull)authInfo;

This method updates authentication information. Tokens expire after a period, and the SDK will fail to connect to the server once expired.

Note

This method and refreshAuthInfoWithToken both refresh authentication information. This method refreshes multi-parameter tokens, while refreshAuthInfoWithToken refreshes single-parameter tokens. For token generation, see Token authentication.

When to call

In the following cases:

  • When you receive the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#6766cdfb40z1a" id="c1cc6cbddb22o">onAuthInfoWillExpire</a> callback indicating that your authentication information is about to expire, we recommend that you regenerate the token server-side and then call this method to pass in the new token.

  • If you do not update the token in time, the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#b04cd67880ptu" id="13c9ccb2b6ghh">onAuthInfoExpired</a> callback is triggered to indicate that authentication has expired. At this point, you must regenerate the token and then call joinChannel to rejoin the channel.

Parameters

Name

Type

Description

authInfo

AliRtcAuthInfo *_Nonnull

The authentication information.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

refreshAuthInfoWithToken

Refreshes the authentication information.

- (int)refreshAuthInfoWithToken:(NSString *_Nonnull)token;

This method updates the token. Tokens expire after a period, and the SDK will fail to connect to the server once expired.

Note
  • Both this API and <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6a4495191bmd" id="eb171f6dc0n9p">refreshAuthInfo</a> are used to update authentication information. This API updates the token for joining a channel with a single parameter, while refreshAuthInfo updates the token for joining a channel with multiple parameters. For more information about token generation, see Token Authentication.

  • If the token is not updated promptly, it triggers <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#b04cd67880ptu" id="3fd3c64767aq8">onAuthInfoExpired</a> to notify that authentication has expired, at which point you need to call joinChannel to rejoin the channel.

When to call

We recommend regenerating the token on your server and calling this method with the new token in the following case:

When you receive the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#6766cdfb40z1a" id="b1dbfcb71d5ys">onAuthInfoWillExpire</a> callback reporting that authentication information is about to expire.

Parameters

Name

Type

Description

token

NSString *_Nonnull

The authentication information for single-parameter input.

Return description

A value of 0 indicates that the call was successful. A value other than 0 indicates that the call failed.

publishLocalAudioStream

Specifies whether to publish an audio track.

- (int)publishLocalAudioStream:(BOOL)enable;

This method controls whether to publish locally captured audio. By default, the SDK publishes audio. If you do not want to publish audio by default, call publishLocalAudioStream(false) before joining the channel.

When to call

You can call this method before or after joining a channel. Calling it before joining modifies the default configuration and takes effect at join time.

Related callbacks

When the state of local audio stream ingest changes, the local client triggers the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#86b2d8735bm71" id="e5ef180ba6e2i">onAudioPublishStateChanged</a> callback to report the latest ingest state, and the remote client triggers the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#6da9cf330aoer" id="299ef35806ttb">onRemoteTrackAvailableNotify</a> callback to report changes to a remote user's audio and video streams.

Parameters

Name

Type

Description

enable

boolean

  • A value of YES specifies that the local audio track is published. This is the default value.

  • NO stops stream ingest, and YES is the default.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

isLocalAudioStreamPublished

Queries whether an audio track is published.

- (BOOL)isLocalAudioStreamPublished;

Return Description

YES indicates that push is allowed. NO indicates that push is not allowed.

setDefaultSubscribeAllRemoteAudioStreams

Set the default behavior for accepting audio streams.

- (int)setDefaultSubscribeAllRemoteAudioStreams:(BOOL)sub;

This method configures whether the system subscribes to remote users' audio tracks by default. This setting affects subscription behavior for users who join the channel later. Unless you have specific requirements, set this to true.

When to call

You can call this method before or after joining a channel.

  • Before joining:

    • The SDK subscribes to remote users' audio tracks by default when joining a channel. To change this behavior, call this method before joining.

  • After joining:

    • If you want to stop the default subscription, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="a467e60e4eyhk">setDefaultSubscribeAllRemoteAudioStreams</a>(false). The system will not subscribe to audio streams from users who join the channel later.

    • After you stop the default subscription, if you want to resume subscribing to the audio stream of a specified user, call the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#c8249fb568gms" id="9806dd9a750pf">subscribeRemoteAudioStream</a> API. If you want to resume subscribing for multiple users, call it multiple times.

    • After you stop the default subscription, calling <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="9507d6d3121uh">setDefaultSubscribeAllRemoteAudioStreams</a>(true) only resumes the audio streams of users who join the channel afterward, and does not subscribe to the audio streams of remote users who joined while the subscription was stopped.

Parameters

Name

Type

Description

sub

BOOL

  • YES indicates acceptance of the user's audio stream.

  • A value of NO indicates that the user's audio stream is no longer accepted. The default value is YES.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

subscribeRemoteAudioStream

Subscribes to or stops subscribing to the audio track of a specific remote user.

- (int)subscribeRemoteAudioStream:(NSString *_Nonnull)uid sub:(BOOL)sub;

Use this interface to stop or resume the audio stream from a specific remote user. For most scenarios, set this parameter to true.

Note

The SDK subscribes by default to audio streams from all remote users when you join a session. To modify this behavior, you can call <a baseurl="t2309850_v10_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="044cc0f710rfg">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before you join a session to cancel this default configuration.

Parameters

Name

Type

Description

uid

NSString *_Nonnull

The ID of the remote user.

sub

BOOL

  • YES indicates that you accept the audio stream from the specified user.

  • A value of NO specifies that the audio track of the specified user is not subscribed to.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

subscribeAllRemoteAudioStreams

Subscribes to or stops subscribing to the audio tracks of all remote users.

- (int)subscribeAllRemoteAudioStreams:(BOOL)sub;

This method is the master switch for subscribing to remote audio tracks. We recommend setting it to YES. Setting it to NO causes the following:

  • Remote audio tracks in the current session are no longer subscribed.

  • New users who join later are not subscribed.

  • You cannot use <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#c8249fb568gms" id="846b0dd501epf">subscribeRemoteAudioStream</a> to individually control the audio stream of a specified user.

To resume the subscription, call this method again with the sub parameter set to YES.

Note

By default, the SDK subscribes to audio streams from all remote users when you join a session. To modify this behavior, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="86e8c09213k9y">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before you join a session to disable this default configuration.

Parameters

Name

Type

Description

sub

BOOL

  • A value of YES specifies that the audio tracks of all remote users are subscribed to. This is the default value.

  • A value of NO specifies that the audio tracks of all remote users are not subscribed to.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

publishLocalVideoStream

Specifies whether to publish a video track.

- (int)publishLocalVideoStream:(BOOL)enable;

This method controls the publishing of the video that is captured locally.

Note

By default, the SDK publishes the local video stream. To disable this feature, call publishLocalVideoStream(false) before you join the channel.

When to call

You can call this method before or after joining a channel.

If you call this method before joining a channel, it modifies the default configuration, and the setting takes effect when you join the channel.

Related callbacks

When the state of the local audio stream ingest changes, the local client triggers the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#bd67711e63tnk" id="f966292202q3d">onVideoPublishStateChanged</a> callback to report the latest audio stream ingest state. The remote client triggers the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#6da9cf330aoer" id="2fdc208ccczr1">onRemoteTrackAvailableNotify</a> callback to report changes to the remote user’s audio and video streams.

Parameters

Name

Type

Description

enable

boolean

  • YES indicates that video is being sent.

  • NO disables sending. The default setting is YES.

isLocalVideoStreamPublished

Queries whether a video track is published.

- (BOOL)isLocalVideoStreamPublished;

Return description

A value of YES indicates that the video track is published. A value of NO indicates that the video track is not published.

setDefaultSubscribeAllRemoteVideoStreams

You can set whether to accept video streams by default.

- (int)setDefaultSubscribeAllRemoteVideoStreams:(BOOL)sub;

By default, the SDK subscribes to remote users’ video tracks. Use this method to change that behavior.

Note

The SDK subscribes to remote users’ audio and video tracks by default when joining a channel. To change this behavior, call this method before joining the channel.

When to call

You can call this method before or after joining a channel.

  • Before joining:

    • You can use this method to disable the default subscription.

  • After joining:

    • To disable the default subscription, call setDefaultSubscribeAllRemoteVideoStreams(false). You will also no longer automatically subscribe to the audio streams of users who join the channel later.

    • After you stop the default subscription, you can call the subscribeRemoteVideoStream interface to resume subscribing to the audio stream of a specific user. To resume subscribing to multiple users, call this interface once for each user.

    • After you stop the default subscription, calling setDefaultSubscribeAllRemoteVideoStreams(false) restores only the audio streams for users who join the channel afterward.

Parameters

Name

Type

Description

sub

boolean

  • YES indicates the user's video stream is accepted.

  • A value of NO specifies that the video tracks of remote users are not subscribed to.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

subscribeRemoteVideoStream

Stop or resume subscribing to video streams from remote users.

- (int)subscribeRemoteVideoStream:(NSString *_Nonnull)uid track:(AliRtcVideoTrack)track sub:(BOOL)sub;

You can subscribe to or unsubscribe from the video stream of a specified user.

Note

By default, the SDK subscribes to video streams from all remote users when you join a meeting. To disable this default configuration, call <a baseurl="t2309850_v10_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="97d89be88bvan">setDefaultSubscribeAllRemoteVideoStreams</a>(false) before you join the meeting.

When to call

You can call this method before or after joining a channel.

Description

Name

Type

Description

uid

NSString *

The user ID, assigned uniquely by the AppServer.

track

AliRtcVideoTrack

The video stream type.

sub

BOOL

Whether to subscribe.

subscribeAllRemoteVideoStreams

Subscribes to or stops subscribing to the video tracks of all remote users.

Note

This method acts as the master switch for subscription to remote video streams. If set to NO, it stops subscribing to all remote video streams in the current session and prevents new users who join later from being subscribed to—even if setDefaultSubscribeAllRemoteVideoStreams:YES is set.

- (int)subscribeAllRemoteVideoStreams:(BOOL)sub;

This method serves as the master switch for subscribing to remote video streams. Setting sub to false causes:

  • All remote video streams in the current session to stop being subscribed to.

  • New users who join later will not be subscribed either (even if the default subscription setting <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="0464849a17dks">setDefaultSubscribeAllRemoteVideoStreams</a> is enabled).

  • You cannot use <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#1cc7ef76fdawz" id="498e782f414zz">subscribeRemoteVideoStream</a> to individually control the audio stream for a specific user.

To resume subscription, call this method again with sub set to true.

Note

By default, the SDK subscribes to the video streams of all remote users when you join a meeting. To change this behavior, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="317fa38ecf6ya">setDefaultSubscribeAllRemoteVideoStreams</a> before you join the meeting to disable this default configuration.

Parameters

Name

Type

Description

sub

BOOL

  • A value of YES specifies that the video tracks of all remote users are subscribed to. This is the default value.

  • NO indicates that no video streams will be accepted. The default value is YES.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

subscribeRemoteMediaStream[1/2]

Stop or resume the media stream from a specific remote user.

- (int)subscribeRemoteMediaStream:(NSString *_Nonnull)uid videoTrack:(AliRtcVideoTrack)videoTrack subVideo:(BOOL)subVideo subAudio:(BOOL)subAudio;

This interface merges subscribed remote audio and video streams.

Related API operations

Unlike subscribeRemoteMediaStream[2/2], this interface uses two Boolean parameters—subVideo and subAudio—to control whether to subscribe to remote video and audio streams, and the videoTrack parameter specifies which video stream to pull.

Note: In this API, the AliRtcVideoTrackNo of AliRtcVideoTrack is invalid, and setting it has no effect.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

videoTrack

AliRtcVideoTrack

The type of video stream.

subVideo

boolean

Specifies whether to subscribe to the video track of the remote user. Valid values:

  • true (default): resume

  • false: The operation stops.

subAudio

boolean

Specifies whether to subscribe to the audio track of the remote user. Valid values:

  • true (default): resume

  • false: Stops the operation.

Response description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

subscribeRemoteMediaStream[2/2]

You can stop or resume the media stream from a specific remote user.

- (int)subscribeRemoteMediaStream:(NSString *_Nonnull)uid videoTrack:(AliRtcVideoTrack)videoTrack audioTrack:(AliRtcAudioTrack)audioTrack;

This interface merges subscribed remote audio and video streams.

Note

This operation uses videoTrack and audioTrack to communicate the desired state to the software development kit.

Related APIs

Unlike subscribeRemoteMediaStream[1/2], this interface uses the videoTrack and audioTrack parameters to specify the desired subscription state to the SDK in a single call. For example:

  • To subscribe to camera and microphone streams, set videoTrack to AliRtcVideoTrackCamera and audioTrack to AliRtcAudioTrackMic when you invoke the method.

  • If you want to unsubscribe from the camera stream but keep the microphone, set AliRtcVideoTrackNo and AliRtcAudioTrackMic to the videoTrack and audioTrack parameters, respectively, when you invoke the method again.

  • If you want to cancel all tracks, set videoTrack and audioTrack to AliRtcVideoTrackNo and AliRtcAudioTrackNo, respectively, when you invoke it again.

  • To subscribe to both camera and screen sharing streams, set videoTrack to AliRtcVideoTrackBoth. Audio works similarly.

Parameters

Parameter

Type

Description

uid

NSString *

The remote user ID.

videoTrack

AliRtcVideoTrack

The video stream type.

audioTrack

AliRtcAudioTrack

The audio stream type.

Return description

A return value of 0 indicates success. Any other value indicates failure.

subscribeRemoteDestChannelStream

Subscribes to or stops subscribing to the media stream of a specific remote user across channels.

- (int)subscribeRemoteDestChannelStream:(NSString *_Nonnull)channelId uid:(NSString *_Nonnull)uid track:(AliRtcVideoTrack)track subAudio:(BOOL)subAudio sub:(BOOL)sub;

Parameters

Parameter

Type

Description

channelId

String

The ID of the remote channel.

uid

String

The ID of the remote user.

track

AliRtcVideoTrack

The video track to which you want to subscribe.

sub_audio

boolean

Specifies whether to subscribe to the audio track of the remote user. Valid values:

  • true (default): recover.

  • false: The operation stops.

sub

boolean

Stops or resumes the cross-channel subscription to the stream of a specified user.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

subscribeRemoteDestChannelAllStream

Subscribes to all user streams in the target channel.

- (int)subscribeRemoteDestChannelAllStream:(NSString *_Nonnull)channelId track:(AliRtcVideoTrack)track subAudio:(BOOL)subAudio sub:(BOOL)sub;

Parameters

Name

Type

Description

channelId

NSString *

The target channel.

videotrack

AliRtcVideoTrack

The video stream type.

audioTrack

AliRtcAudioTrack

The audio stream type.

subAudio

BOOL

Whether to subscribe to the audio stream.

sub

BOOL

Whether to subscribe to the video stream of users in the remote channel.

Return value

0 indicates success. Any other value indicates failure.

setRemoteAudioVolume

You can set the volume of remote audio.

- (int)setRemoteAudioVolume:(NSString *_Nonnull)uid volume:(NSInteger)volume;
Note

The UID must be set after the user joins the channel. Otherwise, the operation will fail.

Parameters

Name

Type

Description

uid

NSString *

The user ID, assigned uniquely by the AppServer.

volume

NSInteger

The playback volume. Valid range: [0, 100]. 0 means mute. 100 means original volume.

Return value

A value of 0 indicates success. A non-zero value indicates failure.

muteLocalMic

Stop or resume the transmission of local audio data.

- (int)muteLocalMic:(BOOL)mute mode:(AliRtcMuteLocalAudioMode)mode;
Note

Muting sends silent audio frames. Audio capture and encoding continue to run.

When to call

You can call this method before or after joining a channel.

Related callbacks

After the call succeeds, the remote user triggers the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3189c59d9fipb" id="1579c3523779c">onUserAudioMuted</a> callback to indicate whether the user is muted.

Parameters

Name

Type

Description

mute

BOOL

  • YES indicates that the local audio sends empty frames.

  • NO indicates that normal operation resumes. The default value is NO.

mode

AliRtcMuteLocalAudioMode

The mute mode. Default: mute all.

  • AliRtcMuteAudioModeDefault: Mutes all audio, including microphone and external input.

  • AliRtcMuteAllAudioMode: Mutes all audio, including microphone and external input.

  • AliRtcMuteOnlyMicAudioMode: mutes only the microphone.

Return values

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

muteRemoteAudioPlaying

You can stop or resume remote audio playback.

- (int)muteRemoteAudioPlaying:(NSString *_Nonnull)uid mute:(BOOL)mute;- (int)muteRemoteAudioPlaying:(NSString *_Nonnull)uid mute:(BOOL)mute;- (int)muteRemoteAudioPlaying:(NSString *_Nonnull)uid mute:(BOOL)mute;

This API stops or resumes playback of audio from a specified remote user but does not affect stream pulling or decoding of the remote audio. To unsubscribe from a user’s audio stream, call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#c8249fb568gms" id="dd9dbbad0bkni">subscribeRemoteAudioStream</a>.

When to call

You can call this method before or after joining a channel.

Parameters

Name

Type

Description

uid

NSString *_Nonnull

The ID of the remote user.

mute

BOOL

  • A value of YES specifies that the playback is stopped.

  • NO indicates that playback does not resume. The default value is NO.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

muteAllRemoteAudioPlaying

You can stop or resume all remote audio playback.

- (int)muteAllRemoteAudioPlaying:(BOOL)mute;

This API stops or resumes playback of all remote audio.

Note

This method stops playback only. Stream pulling and decoding are unaffected.

When to call

You can configure this setting before or after you join a channel.

Parameters

Name

Type

Description

mute

BOOL

  • A value of YES specifies that the playback is stopped.

  • A value of NO specifies that the playback is resumed. This is the default value.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

startAudioCapture[1/2]

Starts audio collection.

- (void)startAudioCapture;

This method starts audio capture. You can call this method before joining a channel to start audio capture in advance. If you do not call this method, the SDK automatically manages the audio capture device. After you call stopAudioCapture to stop audio capture, you can call this method again to restart it.

When to call

You can call this method before or after joining a channel.

Related methods

startAudioCapture[2/2] API controls whether the audio capture device remains enabled after you leave the meeting, based on the specified parameters.

Related callbacks

After you call this method, the SDK triggers the onLocalAudioStateChanged callback to report changes in the local audio capture state.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

startAudioCapture[2/2]

Starts audio collection.

- (void)startAudioCapture:(BOOL)keepAlive;

Disables microphone capture after muting.

This method starts audio capture. You can call it before joining a channel to begin audio capture early. If you do not call this method, the SDK automatically manages the audio capture device.

When to call

You can call this method before or after joining a channel.

Related methods

Compared with startAudioCapture[1/2], this method lets you control whether the capture device remains active after leaving the channel using the keepAlive parameter.

Related callbacks

After calling this method to change the local audio capture status, you can obtain status updates through the onLocalAudioStateChanged callback.

Parameters

Parameter

Type

Description

keepAlive

boolean

The status of the audio collection device after you leave a channel. Valid values:

  • true: The audio collection device remains on after you leave a channel.

  • false (default): The audio collection device is turned off after you leave a channel.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

stopAudioCapture

Stops audio collection.

- (void)stopAudioCapture;

After you call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3103c368bexf8" id="ddef64f9b93zq">startAudioCapture</a> to enable audio capture from an audio device, you can call this method to stop audio capture.

Related callbacks

After calling this method to modify the local audio capture status, you can retrieve status changes via the onLocalAudioStateChanged callback.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

enableSpeakerphone

Sets the headset or speaker as the audio output device. This method applies only to iOS.

- (int)enableSpeakerphone:(BOOL)enable;

This method sets the audio playback device to either the speaker or headset after you join a channel. If you do not call this method, the SDK uses the default audio route.

The SDK defines an internal priority order for audio routing and automatically switches based on connected peripherals: Wired headset > Bluetooth headset > User setting > Default setting. Therefore, this method has no effect when peripherals are connected. For more information, see Audio routing settings.

When to call

You can call this method before or after joining a channel.

Related methods

The <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#83be8cc066qqq" id="f8de149ef8so0">setDefaultAudioRoutetoSpeakerphone</a> method modifies the default audio routing settings and sets the current audio output device.

Parameters

Name

Type

Description

enable

BOOL

  • YES indicates speaker mode.

  • NO indicates earpiece mode. The default value is YES.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

isEnableSpeakerphone

Queries whether the current audio output device is the headset or the speaker. This method applies only to iOS.

- (BOOL)isEnableSpeakerphone;

Return Description

A value of YES indicates that the current audio output device is the speaker. A value of NO indicates that the current audio output device is the headset.

enableAudioVolumeIndication

Set the volume callback interval and smoothing factor.

- (int)enableAudioVolumeIndication:(NSInteger)interval smooth:(NSInteger)smooth reportVad:(NSInteger)reportVad;

This method enables the SDK to periodically report volume information for local publishing users and the remote user with the highest instantaneous volume.

When to call

You can call this method before or after joining a channel.

Related callbacks

After you successfully call this method, if there are publishing users in the channel, the SDK triggers the following callbacks at the configured interval:

  • The SDK reports the volume for speaking users through the onAudioVolumeCallback callback. The callback frequency depends on the interval parameter.

  • For voice activity detection, when an active speaker is detected, the SDK reports their UID through the onActiveSpeaker callback.

Parameters

Name

Type

Description

interval

NSInteger

The interval at which volume detection is performed. Unit: milliseconds. The value must be greater than or equal to 10. We recommend that you set this parameter to a value from 300 to 500. If the value is less than or equal to 0, the indicators for indicating the volume and the person who speaks are disabled.

smooth

NSInteger

The smoothing factor. Valid values: 0 to 9. A larger value indicates a higher smoothing degree. A smaller value indicates a lower smoothing degree but better real-time performance. We recommend that you set the value to 3.

reportVad

NSInteger

The switch used to detect the person who speaks. Valid values:

  • 1: turns on the switch. You can invoke the onAudioVolumeCallback callback to obtain the status of each person who speaks.

  • 0: turns off the switch.

Return value

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

enableEarBack

You can enable in-ear monitoring.

- (int)enableEarBack:(BOOL)enable;

This method enables or disables in-ear monitoring. For optimal results, we recommend enabling in-ear monitoring when using wired or Bluetooth headphones.

When to call

You can call this method before or after joining a channel.

Parameter description

Name

Type

Description

enable

BOOL

  • A value of YES enables in-ear monitoring.

  • A value of NO disables in-ear monitoring. This is the default value.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setEarBackVolume

Sets the in-ear monitoring volume.

- (int)setEarBackVolume:(NSInteger)volume;

This interface sets the in-ear monitoring volume. It takes effect only after you enable in-ear monitoring by calling <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#bd665d0f894ux" id="b0fa866c9bcuq">enableEarBack</a>.

When to call

You can call this method before or after joining a channel.

Parameters

Name

Type

Description

volume

NSInteger

The value must be in the range of 0 to 100. The default is 100.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

startAudioPlayer

Starts audio playback.

- (void)startAudioPlayer;
Note

You can call this method to start audio playback in advance. If you do not call this method, the SDK automatically starts playback after you subscribe to an audio stream.

stopAudioPlayer

Stops audio playback.

- (void)stopAudioPlayer;
Note

Call this method to stop audio playback.

setPlayoutVolume

Sets the playback volume.

- (int)setPlayoutVolume:(NSInteger)volume;

Parameters

Name

Type

Description

volume

Volume

Range: [0..400]. [0..100] is the original volume range. [100..400] amplifies volume.

Return value

A return value of 0 indicates success, while any other value indicates failure.

setRecordingVolume

Sets the recording volume.

- (int)setRecordingVolume:(NSInteger)volume;

Parameters

Name

Type

Description

volume

NSInteger

Range: [0..400]. [0..100] is the original volume. [100..400] amplifies volume.

Return value

A return value of 0 indicates success. Any other value indicates failure.

playAudioFileTest

Plays an audio file.

- (int)playAudioFileTest:(NSString *_Nonnull)filePath;
Note

You can call this method before joining a channel.

Parameters

Parameter

Type

Description

filePath

NSString *_Nonnull

The path to the audio file to play.

Return value

A return value of 0 indicates success. Any other value indicates failure.

stopAudioFileTest

Stops playback of an audio file.

- (int)stopAudioFileTest;
Note

You should call this method before calling joinChannel.

Return value

A return value of 0 indicates success. Any other value indicates failure.

startAudioCaptureTest

Enable audio capture device detection before a call.

- (void)startAudioCaptureTest;
Note

You can call this method only before joinChannel. Any attempts to call it afterward will fail.

stopAudioCaptureTest

Detect the audio collection device before terminating the call.

- (void)stopAudioCaptureTest;
Note

You must call this method before calling joinChannel. Otherwise, the method call fails.

setDefaultAudioRoutetoSpeakerphone

Sets the default audio output to the speaker. By default, audio plays through the speaker.

- (int)setDefaultAudioRouteToSpeakerphone:(BOOL)defaultToSpeakerphone;

This method configures the default audio route device before you join a channel. You can route audio to either the headset or the speaker. The SDK uses the speaker by default. To change this behavior, call this method before joining the channel.

The SDK defines a fixed priority order for audio routing and performs automatic switchover based on the current peripheral connection status. The priority order is as follows: wired headset > Bluetooth headset > user settings > default settings. Therefore, if no peripherals are connected and you have not configured audio routing through <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#f7d0d8b64fzkz" id="30798b686b5qk">enableSpeakerphone</a>, the SDK applies the default settings.

For more information about audio routing, see Audio routing settings.

Mobile devices typically support two audio routes: headset and speaker:

  • When using the headset, sound is quieter and requires holding the phone close to your ear. This provides better privacy and is suitable for phone calls.

  • When using the speaker, sound is louder and audible without holding the phone to your ear. This enables hands-free operation.

Related methods

This API modifies the default audio routing settings. The <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#f7d0d8b64fzkz" id="6001aa98ebapw">enableSpeakerphone</a> API sets the current audio routing device.

When to call

You can call this method before or after joining a channel.

Parameters

Name

Type

Description

defaultToSpeakerphone

BOOL

Whether to route audio to the speaker. YES for speaker. NO for headset.

Return value

A return value of 0 indicates success. Any other value indicates failure.

setAudioEffectVoiceChangerMode

Sets the voice change mode.

- (int)setAudioEffectVoiceChangerMode:(AliRtcAudioEffectVoiceChangerMode)mode;

Parameters

Name

Type

Description

mode

AliRtcAudioEffectVoiceChangerMode

The voice change mode. Default value: AliRtcSdk_AudioEffect_Voice_Changer_OFF.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAudioEffectPitchValue

Sets the audio pitch.

- (int)setAudioEffectPitchValue:(double)value;

Parameters

Name

Type

Description

value

double

The pitch value. Valid values: 0.5 to 2.0. The default value is 1.0, which indicates that the pitch remains the same.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAudioEffectReverbMode

Sets the reverberation mode.

- (int)setAudioEffectReverbMode:(AliRtcAudioEffectReverbMode)mode;

Parameters

Name

Type

Description

mode

AliRtcAudioEffectReverbMode

The reverberation mode. Default value: AliRtcAudioEffectReverb_Off.

Response description

A value of 0 indicates that the call was successful. A value other than 0 indicates that the call failed.

setAudioEffectReverbParamType

You can set the reverb effect type and specific parameters.

- (int)setAudioEffectReverbParamType:(AliRtcAudioEffectReverbParamType)type value:(float)value;

Parameters

Name

Type

Description

type

AliRtcAudioEffectReverbParamType

Reverb pattern for sound effects.

value

float

Specifies the parameter values.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAudioEffectBeautifyMode

Sets a predefined voice beautification effect mode.

- (int)setAudioEffectBeautifyMode:(AliRtcAudioEffectBeautifyMode)mode;

This method configures built-in voice beautification modes in the SDK. It is suitable for scenarios such as voice live streaming, karaoke, and voice-based social apps where voice quality enhancement is required. Selecting different beautification modes alters the perceived vocal characteristics—for example, enhancing richness or clarity—to improve the listening experience for remote users.

When to call

You can call this method before or after joining a channel.

Parameters

Parameter

Type

Description

mode

AliRtcAudioEffectBeatifyMode

The voice beautification effect mode. See the enumeration definition for details.

Return Description

  • 0: Success.

  • Non-zero: Failure.

setAudioEffectEqualizationParam

Sets audio equalizer (EQ) parameters to adjust the gain for specified frequency bands.

- (int)setAudioEffectEqualizationParam:(AliRtcAudioEffectEqualizationBandFrequency)bandIndex gain:(float)gain;

This method applies graphic equalizer adjustments to locally captured voice or audio signals. You can adjust the gain in decibels (dB) for ten fixed frequency bands to customize the tonal quality. This method is suitable for optimizing speech clarity, enhancing voice quality, and reducing noise.

The equalizer supports full-spectrum adjustments from 31 Hz to 16 kHz across ten standard frequency bands. The gain for each band can be adjusted independently from -15 dB to 15 dB. The default gain is 0 dB, which indicates no boost or attenuation.

Limitations

  • You must enable voice beautification by calling setAudioEffectBeautifyMode before using the equalizer.

Parameters

Parameter

Type

Description

bandIndex

AliRtcAudioEffectEqualizationBandFrequency

The frequency band index, corresponding to a center frequency (31 Hz to 16 kHz).

gain

float

The gain value in dB. Valid range: [-15, 15].

Return description

0: Success.

Non-zero: Failure.

addExternalAudioStream

Adds an external audio track.

- (int)addExternalAudioStream:(AliRtcExternalAudioStreamConfig *_Nonnull)config;

To add an external audio stream, follow these steps:

  1. Call the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#d71bbfd2f242b" id="c310321e9eu35">addExternalAudioStream</a> interface to add the external audio stream and retrieve its ID.

  2. Call pushExternalAudioStream to feed audio data into the stream.

  3. When the call ends, call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#282d70095duaw" id="16f621608d94x">removeExternalAudioStream</a> to remove the external audio stream.

To publish custom-captured audio in a channel, see Custom audio capture.

Parameters

Name

Type

Description

config

AliRtcExternalAudioStreamConfig

The configuration of the external audio track.

Return description

A value greater than 0 indicates that the call is successful and is the ID of the external audio track. A value less than or equal to 0 indicates that the call fails.

pushExternalAudioStream

Imports external audio data.

- (int)pushExternalAudioStream:(int)streamId rawData:(AliRtcAudioFrame * _Nonnull)audioFrame;

This method feeds audio data into a specified stream. Follow these steps:

  1. Call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#d71bbfd2f242b" id="0a353f7272shu">addExternalAudioStream</a> to add an external audio stream and obtain the external audio stream ID.

  2. Call this method to feed audio data into the created stream.

  3. When the call ends, you need to call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#282d70095duaw" id="a9ebc8d599dz4">removeExternalAudioStream</a> to remove the external audio stream.

To publish custom-captured audio in a channel, see Custom audio capture.

Parameters

Name

Type

Description

streamId

int

The ID of the external audio track.

audioFrame

AliRtcAudioFrame

The audio data.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setExternalAudioStream:publishVolume

Set the volume for external audio stream ingest.

- (int)setExternalAudioStream:(int)streamId
                publishVolume:(int)publishVolume;

Parameters

Name

Type

Description

streamId

int

The ID of the external audio track.

publishVolume

int

The volume of the external audio for stream ingest.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

getExternalAudioStreamPublishVolume

Queries the volume of external audio for stream ingest.

- (int)getExternalAudioStreamPublishVolume:(int)streamId;

Parameters

Name

Type

Description

streamId

int

The ID of the external audio track.

Return Description

The valid values of the volume range from 0 to 100. A value less than 0 indicates that the call fails.

setExternalAudioStream:playoutVolume

Sets the playback volume of external audio.

- (int)setExternalAudioStream:(int)streamId
                playoutVolume:(int)playoutVolume;

Parameters

Name

Type

Description

streamId

int

The ID of the external audio track.

playoutVolume

int

The playback volume.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

getExternalAudioStreamPlayoutVolume

Queries the playback volume of external audio.

- (int)getExternalAudioStreamPlayoutVolume:(int)streamId;

Parameters

Name

Type

Description

streamId

int

The ID of the external audio track.

Response description

The valid values of the volume range from 0 to 100. A value less than 0 indicates that the call fails.

removeExternalAudioStream

Delete the external (audio stream).

- (int)removeExternalAudioStream:(int)streamId;

This method removes the external audio stream for the specified streamId and is the counterpart to the addExternalAudioStream method.

When to call

To use the custom audio input feature, call the addExternalAudioStream method to add an audio stream and obtain the external audio stream ID, and then call the pushExternalAudioStream interface to push your audio data to the SDK. When you want to stop custom audio input, call the corresponding method to remove the external audio stream and release resources.

Parameters

Name

Type

Description

streamId

int

The external audio stream ID.

Return value

0 indicates success. Any other value indicates failure.

getAudioFileInfo

Retrieves audio file information.

- (int)getAudioFileInfo:(NSString *_Nonnull)filePath;
Note

An asynchronous interface. You can retrieve audio file information using {@link onAudioFileInfo:errorCode:}.

Parameters

Name

Type

Description

filePath

NSString *

The file path.

startAudioAccompanyWithFile

You can start accompaniment mixing.

- (int)startAudioAccompanyWithFile:(NSString *_Nonnull)filePath config:(AliRtcAudioAccompanyConfig *_Nonnull)config;
Note

This method is asynchronous. To monitor player status, use the onAudioAccompanyStateChanged callback.

Parameters

Name

Type

Description

filePath

NSString *

The file path.

config

AliRtcAudioAccompanyConfig *

The accompaniment configuration.

Return value

0 indicates success. Other values indicate failure.

stopAudioAccompany

Stops audio accompaniment mixing.

- (int)stopAudioAccompany;

Return value

A return value of 0 indicates success. Any other value indicates failure.

setAudioAccompanyVolume

Set the accompaniment volume.

- (int)setAudioAccompanyVolume:(NSInteger)volume;
Note

You can set both local playback volume and stream ingest volume for accompaniment.

Parameters

Name

Type

Description

volume

NSInteger

The accompaniment volume. Valid range: [0, 100].

Return value

0 succeeded; the rest failed.

setAudioAccompanyPublishVolume

Sets the publishing volume of the audio accompaniment.

- (int)setAudioAccompanyPublishVolume:(NSInteger)volume;
Note

This method sets the volume of published streams.

Parameters

Name

Type

Description

volume

NSInteger

The accompaniment volume. Valid range: [0, 100].

Return value

Returns 0 on success. An error code is returned on failure.

getAudioAccompanyPublishVolume

You can retrieve the volume level for publishing the audio accompaniment.

- (int)getAudioAccompanyPublishVolume;

Return value

A value in the range [0, 100] indicates success. Any other value indicates failure.

setAudioAccompanyPlayoutVolume

Sets the local playback volume for the accompaniment.

- (int)setAudioAccompanyPlayoutVolume:(NSInteger)volume;

Parameters

Name

Type

Description

volume

NSInteger

The accompaniment volume. Valid range: [0, 100].

Return value

A return value of 0 indicates success. Any other value indicates failure.

getAudioAccompanyPlayoutVolume

You can retrieve the local playback volume of the accompaniment.

- (int)getAudioAccompanyPlayoutVolume;

Return value

A value in the range of 0 to 100 indicates success, while any other value indicates failure.

pauseAudioAccompany

Pauses audio accompaniment mixing.

- (int)pauseAudioAccompany;

Return value

A return value of 0 indicates success. Any other value indicates failure.

resumeAudioAccompany

Resumes audio accompaniment mixing.

- (int)resumeAudioAccompany;

Return value

0 indicates success. Other values indicate failure.

getAudioAccompanyDuration

Retrieves the duration of the accompaniment file in milliseconds.

- (int)getAudioAccompanyDuration;

Return value

Returns the accompaniment file duration in milliseconds if successful (>= 0). Returns a value less than 0 if the operation fails.

getAudioAccompanyCurrentPosition

Retrieve the playback progress of the accompaniment file in milliseconds.

- (int)getAudioAccompanyCurrentPosition;

Return value

A value of 0 or greater indicates the current playback position in milliseconds. A negative value indicates a failure.

setAudioAccompanyPosition

Sets the playback position of the accompaniment file.

- (int)setAudioAccompanyPosition:(int)pos;

Parameters

Name

Type

Description

pos

int

The progress bar position in milliseconds.

Return value

A return value of 0 indicates success. Any other value indicates failure.

preloadAudioEffectWithSoundId

Preloads a sound effect.

- (int)preloadAudioEffectWithSoundId:(NSInteger)soundId filePath:(NSString *_Nonnull)filePath;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

filePath

NSString *_Nonnull

The path of the sound effect.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

unloadAudioEffectWithSoundId

Deletes a preloaded sound effect.

- (int)unloadAudioEffectWithSoundId:(NSInteger)soundId;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

playAudioEffectWithSoundId

Starts the playback of a sound effect.

- (int)playAudioEffectWithSoundId:(NSInteger)soundId filePath:(NSString *_Nonnull)filePath cycles:(NSInteger)cycles publish:(BOOL)publish;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

filePath

NSString *_Nonnull

The path of the sound effect.

cycles

NSInteger

The number of playback loops. You can set this parameter to -1 or a positive integer.

publish

BOOL

Publish?

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

stopAudioEffectWithSoundId

Stops the playback of a sound effect.

- (int)stopAudioEffectWithSoundId:(NSInteger)soundId;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

stopAllAudioEffects

Stops the playback of all sound effects.

- (int)stopAllAudioEffects;

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

pauseAudioEffectWithSoundId

Pauses the playback of a sound effect.

- (int)pauseAudioEffectWithSoundId:(NSInteger)soundId;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

pauseAllAudioEffects

Pauses the playback of all sound effects.

- (int)pauseAllAudioEffects;

Response description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

resumeAudioEffectWithSoundId

Resumes the playback of a sound effect.

- (int)resumeAudioEffectWithSoundId:(NSInteger)soundId;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

resumeAllAudioEffects

Resumes the playback of all sound effects.

- (int)resumeAllAudioEffects;

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAudioEffectPublishVolumeWithSoundId

Sets the volume of a sound effect for stream ingest.

- (int)setAudioEffectPublishVolumeWithSoundId:(NSInteger)soundId volume:(NSInteger)volume;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

volume

NSInteger

The volume of the mixed audio. Valid values: 0 to 100. Default value: 50.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

getAudioEffectPublishVolumeWithSoundId

Queries the volume of a sound effect for stream ingest.

- (int)getAudioEffectPublishVolumeWithSoundId:(NSInteger)soundId;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAllAudioEffectsPublishVolume

Sets the volume for mixing all sound effects into the stream ingest.

- (int)setAllAudioEffectsPublishVolume:(NSInteger)volume;

Parameters

Name

Type

Description

volume

NSInteger

The volume of the mixed audio. Valid values: 0 to 100. Default value: 50.

Response description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAudioEffectPlayoutVolumeWithSoundId

Sets the volume of a sound effect for local playback.

- (int)setAaudioEffectPlayoutVolumeWithSoundId:(NSInteger)soundId volume:(NSInteger)volume;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

volume

NSInteger

The volume of the mixed audio. Valid values: 0 to 100. Default value: 50.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

getAudioEffectPlayoutVolumeWithSoundId

Queries the volume of a sound effect for local playback.

- (int)getAudioEffectPlayoutVolumeWithSoundId:(NSInteger)soundId;

Parameters

Name

Type

Description

soundId

NSInteger

The ID that is assigned by the user to the sound effect.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setAllAudioEffectsPlayoutVolume

You can set the local playback volume of all sound effects.

- (int)setAllAudioEffectsPlayoutVolume:(NSInteger)volume;

Parameters

Name

Type

Description

volume

NSInteger

The volume of the mixed audio. Valid values: 0 to 100. Default value: 50.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

startRecord

Starts recording media files.

- (BOOL)startRecord:(AliRtcRecordType)recordType recordFormat:(AliRtcRecordFormat)recordFormat filePath:(NSString*)filePath audioConfig:(AliRtcRecordAudioConfig*)audioConfig videoConfig:(AliRtcRecordVideoConfig*)videoConfig;

Parameters

Parameter

Type

Description

recordType

AliRtcRecordType

The recording type.

recordFormat

AliRtcRecordFormat

The recording format.

filePath

NSString *

The file name and path for recording.

audioConfig

AliRtcRecordAudioConfig *

The audio configuration.

videoConfig

AliRtcRecordVideoConfig *

The video configuration.

Return description

A value of TRUE indicates success. Any other value indicates failure.

Note
  • When recording video streams, call this method only after stream ingest succeeds (onVideoPublishStateChanged). This method records locally encoded video streams and saves them to the device.

  • When recording audio streams, it records the mix of local and remote audio.

stopRecord

Stops the recording of media files.

- (void)stopRecord 

Parameters

None.

setLocalViewConfig

Sets the rendering view and drawing parameters for local preview.

- (int)setLocalViewConfig:(AliVideoCanvas *_Nullable)viewConfig forTrack:(AliRtcVideoTrack)track;

This method sets the local preview view. When you call it, the local video stream is bound to the display view and the rendering mode, mirroring mode, and rotation angle for the local user’s view are configured. It affects only the local preview—not stream ingest. To configure remote users’ views, call setRemoteViewConfig.

Note
  • If the view parameter in AliVideoCanvas: rendering canvas is empty, rendering stops.

  • To reset the renderMode parameter of AliVideoCanvas: rendering canvas during playback, modify only the renderMode parameter and keep all other parameters unchanged.

  • To reset the mirrorMode parameter of AliVideoCanvas: rendering canvas during playback, modify only the mirrorMode parameter and keep all other parameters unchanged.

  • We recommend explicitly calling startPreview() to start the local preview.

When to call

You can call this method before or after you join a channel.

Parameter description

Name

Type

Description

viewConfig

AliVideoCanvas

*_Nullable

The rendering configuration, including the rendering view and rendering mode.

track

AliRtcVideoTrack

The video track type.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setCameraCapturerConfiguration

Sets the collection preferences of the camera.

- (int)setCameraCapturerConfiguration:(AliRtcCameraCapturerConfiguration* _Nonnull)config;

This method configures camera capture preferences, such as camera direction and frame rate.

When to call

You must set this before turning on the camera. For example, before:

  • startPreview

  • joinChannel (Join Channel)

Parameters

Name

Type

Description

config

AliRtcCameraCapturerConfiguration

* _Nonnull

The collection preferences of the camera. Default values of related properties:

  • preference: 0

  • cameraDirection: 0

  • fps: 0

  • cameraCaptureProfile: 0

  • disableVideoCaptureReverse: -1

  • enableCameraMacroFocus: -1

  • captureObserverOriginal: -1

  • nativeBufferObserver: -1

  • captureCallbackCvpixelbufferToRaw: -1

"-1" indicates using the default settings of the SDK.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

enableLocalVideo

Disables or re-enables local video collection.

- (int)enableLocalVideo:(BOOL)enable;

This method enables or disables local video capture. When disabled, local preview and stream ingest display no video. However, receiving remote video remains unaffected. If you disable local camera capture, local preview and stream ingest freeze on the last frame.

Note

Local video capture is enabled by default in the SDK.

When to call

You can call this method before or after joining a channel.

Related callbacks

  • After you successfully call this method, the onUserVideoEnabled callback notifies remote users.

Parameters

Name

Type

Description

enable

BOOL

A value of YES re-enables local video collection. A value of NO disables local video collection. Default value: YES.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

muteLocalCamera

Stop or resume transmitting local video data.

- (int)muteLocalCamera:(BOOL)mute forTrack:(AliRtcVideoTrack)track;

Call this method to send black frames while publishing. The local preview continues to display normally. The capture, encoding, and transmission modules remain active, sending only black frames.

Note

This method only controls whether black frames are sent on a specified video track. It does not stop video capture or data transmission. To disable capture, use the enableLocalVideo method. To stop video data transmission, use the publishLocalVideoStream method.

Parameter Description

Name

Type

Description

mute

BOOL

YES sends black frames for the video data. NO, the default value, resumes normal operation.

track

AliRtcVideoTrack

The video track type whose publishing state you want to change.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setRemoteViewConfig

Sets the rendering view and drawing parameters for the video track of a remote user.

- (int)setRemoteViewConfig:(AliVideoCanvas *_Nullable)canvas uid:(NSString *_Nonnull)uid forTrack:(AliRtcVideoTrack)track;

This method attaches the display view for a specified remote user's video stream and sets properties for its local display, such as the rendering mode, mirror mode, and rotation angle. This affects only the video image seen by the local user. To set the local preview view, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#fea843803078q" id="b6f22fe87a2es">setLocalViewConfig</a>.

When to call

We recommend calling this method when you receive the onRemoteTrackAvailableNotify callback, which is triggered when a remote user's video becomes available.

Parameters

Name

Type

Description

canvas

AliVideoCanvas

*_Nullable

The rendering configuration, including the rendering view and rendering mode.

uid

NSString *_Nonnull

User ID.

track

AliRtcVideoTrack

The type of video track to configure.

Response description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

isCameraOn

Queries whether the camera is turned on.

- (BOOL)isCameraOn;

Response description

A value of YES indicates that the camera is turned on. A value of NO indicates that the camera is turned off.

setVideoEncoderConfiguration

Sets video encoding properties.

- (void)setVideoEncoderConfiguration:(AliRtcVideoEncoderConfiguration* _Nonnull)config;

This method sets video stream encoding parameters, such as resolution, frame rate, bitrate, and orientation. We recommend calling this method for all video scenarios.

Note

All configured parameters have valid ranges. If you specify an invalid value, the SDK automatically adjusts it.

When to call

You can call this method before or after joining a channel. To set camera stream encoding properties once per session, we recommend calling it before joining.

Limitations

Both this method and setVideoMirrorMode control video stream mirroring. We recommend using only one. Using both may cause overlapping mirror effects, leading to incorrect behavior.

Parameters

Name

Type

Description

config

AliRtcVideoEncoderConfiguration

* _Nonnull

The predefined encoding properties. Default values:

  • dimensions: [640, 480]

  • frameRate: 15

  • bitrate: 0

  • mirrorMode: 0

  • keyFrameInterval: The keyframe interval in milliseconds. Default value: 0, meaning the SDK controls it internally.

  • forceStrictKeyFrameInterval: Whether to force the encoder to strictly follow the configured keyframe interval. Default value: false.

  • orientationMode: 0

  • rotation: 0

  • codecType: AliRtcVideoCodecTypeDefault

  • encoderType: AliRtcVideoEncodeCodecTypeDefault

  • seiForceFrontIFrame: -1

  • enableDynamicEncode: -1

  • disableDipenseResolutionChange: -1

  • enableDowngrade: -1

  • enableH264BFrame: -1

  • enableHevcBFrame: -1

  • backgroundHardwareToSoftware: -1

-1 means using SDK internal defaults.

setVideoDecoderConfiguration

Sets video decoding properties.

- (void)setVideoDecoderConfiguration:(AliRtcVideoDecoderConfiguration* _Nonnull)config;

This method sets the video decoding parameters for the camera stream.

When to call

You can call this method before joining the meeting.

Parameters

Name

Type

Description

config

AliRtcVideoDecoderConfiguration

* _Nonnull

The pre-defined decoding properties. Default values:

  • codecType: AliRtcVideoCodecTypeDefault

  • enableDecoderBframe: -1

  • backgroundHardwareToSoftware: -1

"-1" indicates using the default settings of the SDK.

switchCamera

Switches between the front and rear cameras. By default, the front camera is used. This method applies only to iOS.

- (int)switchCamera;

This method controls whether the front or rear camera is used. You can dynamically switch cameras during app runtime based on available hardware without restarting the video stream or reconfiguring the video source.

When to call

You can call this method only after the camera has been successfully turned on.

Limitations

This method is supported only on iOS and Android platforms.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

getCurrentCameraDirection

Queries the current camera type. By default, the front camera is used. This method applies only to iOS.

- (AliRtcCameraDirection)getCurrentCameraDirection;

Return description

Returns a camera direction enumeration.

startPreview

Starts a local preview. The camera is automatically turned on.

- (int)startPreview;

This API enables local video preview and automatically opens the camera. To stop the local preview, call the `stopPreview` API.

Note

leaveChannel leaves the channel and automatically stops the local preview. If you are not pushing a camera stream, the camera is automatically shut down.

When to call

  • Before calling this method, you can set the preview view using setLocalViewConfig. Otherwise, the preview fails—but stream ingest remains unaffected.

  • You can call this method before joinChannel to start the preview early. The camera starts automatically.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

stopPreview

Stops a local preview.

- (int)stopPreview;

This method stops the local video preview and disables the camera. After stopping, the local preview freezes on the last frame. Stream ingestion is unaffected.

Note

leaveChannel automatically stops the local preview. If you are not publishing the camera stream, the camera is also automatically turned off.

When to call

You can call this method to stop the preview.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setCameraZoom

Sets the camera zoom.

 - (int)setCameraZoom:(float)zoom;

Parameters

Name

Type

Description

zoom

float

The zoom level. Range: from 1 to the maximum zoom factor supported by the camera.

Return value

Returns 0 on success. Other values indicate failure.

GetCameraMaxZoomFactor

Retrieves the maximum camera zoom factor.

 - (float)GetCameraMaxZoomFactor;

Return value

The maximum camera zoom factor.

GetCurrentZoom

Obtains the current camera zoom level.

- (float)GetCurrentZoom;

Return value

The current camera zoom level.

SetExposure

You can set the camera exposure level.

- (int)SetExposure:(float)exposure;

Parameters

Name

Type

Description

exposure

float

The exposure level.

Return value

0 indicates success. Any other value indicates failure.

GetCurrentExposure

You can obtain camera exposure.

- (float)GetCurrentExposure;

Return value

The exposure level of the camera.

GetMinExposure

Obtain the minimum camera exposure

- (float)GetMinExposure;

return value

The minimum exposure level for the camera.

GetMaxExposure

Retrieves the maximum camera exposure level.

- (float)GetMaxExposure;

Return value

The maximum camera exposure level.

setCameraFlash

You can set the camera flash toggle.

- (int)setCameraFlash:(BOOL)flash;

Parameters

Name

Type

Description

flash

BOOL

Whether to enable the flash.

Return value

A return value of 0 indicates success. Any other value indicates failure.

isCameraFocusPointSupported

Checks whether manual focus is supported.

- (BOOL)isCameraFocusPointSupported;

Return value

Returns TRUE if manual focus is supported, and FALSE otherwise.

isCameraExposurePointSupported

Does the camera support setting an exposure point?

- (BOOL)isCameraExposurePointSupported;

Return value

TRUE indicates that setting an exposure point is supported. FALSE indicates that it is not supported.

setCameraFocusPoint

Sets the manual focus point for the camera.

- (int)setCameraFocusPoint:(CGPoint)point;

Parameters

Name

Type

Description

point

CGPoint

The focus point coordinate. Remains active until changed.

Return value

Returns 0 on success. Any other value indicates a failure.

setCameraExposurePoint

Set the exposure value at the specified point.

- (int)setCameraExposurePoint:(CGPoint)point;

Parameters

Name

Type

Description

point

CGPoint

The focus point coordinate. Remains active until changed.

Return value

A return value of 0 indicates success. Any other value indicates failure.

isCameraAutoFocusFaceModeSupported

Does the camera support face focus?

- (BOOL)isCameraAutoFocusFaceModeSupported;

Return value

A value of TRUE indicates that face autofocus is supported, and a value of FALSE indicates that it is not.

setCameraAutoFocusFaceModeEnabled

You can enable or disable face autofocus.

- (BOOL)setCameraAutoFocusFaceModeEnabled:(BOOL)enable;

Parameters

Name

Type

Description

point

CGPoint

The focus point coordinate. Remains active until changed.

Return value

A return value of TRUE indicates success. A return value of FALSE indicates failure.

setVideoMirrorMode

Set the video mirroring mode.

- (int)setVideoMirrorMode:(AliRtcVideoPipelineMirrorMode)mirrorMode;

Sets whether to apply mirroring to the local preview and published video streams.

Note

This method takes precedence over setLocalViewConfig and setVideoEncoderConfiguration, and we recommend using it to configure mirroring.

When to call

You can call this method dynamically before or after joining a channel. The SDK stores the state and applies mirroring during preview or encoding (stream ingest).

Limitations

This method overlaps with setLocalViewConfig and setVideoEncoderConfiguration, both of which support the mirrorMode parameter. We recommend using only this method.

Parameters

Name

Type

Description

mirrorMode

AliRtcVideoPipelineMirrorMode

The mirroring type.

SetCapturePipelineScaleMode

You can set the scaling mode for the video link.

-(void)setCapturePipelineScaleMode:(AliRtcCapturePipelineScaleMode)mode;

Specifies whether video data is scaled during capture or during encoding. For example, if the capture resolution differs from the encoding resolution, this setting determines whether the preview data matches the stream ingest data.

Note

The default scaling mode is immediate scaling during capture. You must set this API before camera activation—before startPreview or joinChannel.

When to Call

You must set this method before starting the camera—for example, before calling startPreview or joinChannel.

Parameters

Name

Type

Description

mode

AliRtcCapturePipelineScaleMode

The scaling type.

Return value

A value of 0 indicates success. Any other value indicates failure.

registerVideoFrameWithObserver

Registers a video data output observer.

- (void)registerVideoFrameWithObserver:(id<AliRtcVideoFrameDelegate> _Nullable)observer;

You can use this method to register an object that exports video data. To unregister, call unregisterVideoSampleWithObserver.

When to call

To obtain raw video data (such as YUV or RGBA format) at various stages, you can call this interface to register a video data monitor.

Related callbacks

After you successfully register a video data output observer, the SDK triggers your implemented callbacks when it captures each video frame. Implement the following callbacks as needed:

Parameters

Name

Type

Description

observer

AliRtcVideoFrameDelegate

The video data output observer.

unregisterVideoSampleWithObserver

You can cancel the video data output object.

- (void)unregisterVideoSampleWithObserver:(id<AliRtcVideoFrameDelegate> _Nullable)observer;

This interface corresponds to the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#9a3437ab16j1w" id="f524bad30a6ys">registerVideoSampleObserver</a> interface and unregisters the video data output object.

Parameters

Name

Type

Description

observer

AliRtcVideoFrameDelegate

The output object for video data.

registerLocalVideoTextureObserver

Registers an OpenGL texture observer for local camera video.

- (void)registerLocalVideoTextureObserver:(id<AliRtcTextureDelegate> _Nullable)observer;

To retrieve raw video data, call registerVideoSampleObserver. To retrieve internal texture data, call this method. To unregister the observer, call unRegisterLocalVideoTextureObserver.

Note

Related callbacks

After you successfully register an OpenGL texture observer for local camera video, the SDK triggers the callbacks that you implemented in AliRtcTextureObserver each time a video frame is captured. You can implement the following callbacks as needed:

  • onTextureCreate: This callback is triggered when the SDK creates its internal OpenGL context.

  • onTextureUpdate: This callback is triggered after each video frame is uploaded to the OpenGL texture. When an external texture observer is registered, you can process the texture and return the updated texture ID. The return value must be a valid texture ID. If no processing is performed, return the input textureId.

  • onTextureDestroy: This callback is triggered when the SDK destroys its internal OpenGL context.

Parameters

Name

Type

Description

observer

AliRtcTextureDelegate

The OpenGL texture observer.

unregisterLocalVideoTextureObserver

Unregisters the OpenGL texture observer for the local camera video.

- (void)unregisterLocalVideoTextureObserver:(id<AliRtcTextureDelegate> _Nullable)observer;

This method corresponds to registerLocalVideoTextureObserver and handles its unregistration.

Parameters

Name

Type

Description

observer

AliRtcTextureDelegate

The OpenGL texture observer.

snapshotVideo

Takes a snapshot of the video.

- (int)snapshotVideo:(NSString*_Nullable)userId type:(AliRtcVideoTrack)type;

Parameters

Name

Type

Description

userId

NSString *

The user ID. A value of nil or "" represents the local user.

type

AliRtcVideoTrack

The video stream type supports only {@link AliRtcVideoTrack::AliRtcVideoTrackCamera} and {@link AliRtcVideoTrack::AliRtcVideoTrackScreen}.

Return value

A return value of 0 indicates success. Any other value indicates failure.

setExternalVideoSource

Specifies whether to enable an external video source.

- (int)setExternalVideoSource:(BOOL)enable sourceType:(AliRtcVideoSource)type renderMode:(AliRtcRenderMode)renderMode;

Parameters

Name

Type

Description

enable

BOOL

YES indicates that the feature is enabled. NO indicates that the feature is disabled.

type

AliRtcVideoSource

Stream type

renderMode

AliRtcRenderMode

The rendering mode.

pushExternalVideoFrame

Imports external video data.

- (int)pushExternalVideoFrame:(AliRtcVideoDataSample *_Nonnull)frame sourceType:(AliRtcVideoSource)type;

Parameters

Name

Type

Description

frame

AliRtcVideoDataSample

*_Nonnull

Frame data

type

AliRtcVideoSource

Stream type

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

startPublishLiveStreamWithURL

Starts relayed live streaming.

- (int)startPublishLiveStreamWithURL:(NSString *_Nonnull)streamURL liveTranscoding:(AliRtcLiveTranscodingParam *_Nonnull)trancoding;

Parameters

Name

Type

Description

streamUrl

NSString *

The ingest URL.

transcoding

AliRtcLiveTranscodingParam

*

The parameters for relayed live streaming.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

updatePublishLiveStreamWithURL

Updates the parameters for relayed live streaming.

- (int)updatePublishLiveStreamWithURL:(NSString *_Nonnull)streamURL liveTranscoding:(AliRtcLiveTranscodingParam *_Nonnull)trancoding;

Parameters

Name

Type

Description

streamUrl

NSString *

The ingest URL.

transcoding

AliRtcLiveTranscodingParam

*

The parameters for relayed live streaming.

Return Value

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

stopPublishLiveStreamWithURL

Stop the live streaming bypass.

- (int)stopPublishLiveStreamWithURL:(NSString *_Nonnull)streamURL;

Parameters

Name

Type

Description

streamUrl

NSString *_Nonnull

The ingest URL.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

GetPublishLiveStreamStateWithURL

Queries the status of relayed live streaming.

- (AliRtcLiveTranscodingState)GetPublishLiveStreamStateWithURL:(NSString *_Nonnull)streamURL;

Parameters

Parameter

Type

Description

streamURL

NSString *

The ingest URL.

Return description

The status of relayed live streaming is returned.

startLastmileDetect

Starts network quality testing.

- (int)startLastmileDetect:(AliRtcNetworkQualityProbeConfig *_Nonnull)config;

Parameters

Parameter

Type

Description

config

AliRtcNetworkQualityProbeConfig

Probe configuration parameters

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

stopLastmileDetect

Stops network quality testing.

- (int)stopLastmileDetect;

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

sendMediaExtensionMsg

Sets the parameters of the reverberation mode.

- (int)sendMediaExtensionMsg:(NSData *_Nonnull)data repeatCount:(int)repeatCount delay:(int)delay isKeyFrame:(bool)isKeyFrame;

The SDK supports sending and receiving media extension messages. It sends messages using the Supplemental Enhancement Information (SEI) protocol. Receivers can obtain messages by listening to the onMediaExtensionMsgReceived callback.

Common use cases include the following:

  • You can use media extension messages to transmit timestamps for calculating end-to-end network latency or for synchronizing with other business logic.

  • You can use media extension messages to transmit descriptive information, with a payload of up to 4 KB. For small payloads, use JSON or plain strings.

When to call

Call this method after stream ingest begins.

Limitations

Media extension messages reuse the audio-video data channel. Therefore, you must control message frequency and size. The following limitations apply:

  • The maximum number of messages per second equals the frames per second (FPS) setting in the profile. Because SEI messages are embedded in H.264 or H.265 streams, video frame encoding is required to attach extension data.

  • To avoid affecting media transmission quality, the message body size is limited to 4 KB. This limit is suitable for small payloads.

  • You can use the sendMediaExtensionMsg function. The repeatCount parameter specifies custom message redundancy. If this parameter is greater than 1, the message is sent multiple times.

  • To prevent packet loss from causing message loss, other users in the channel also receive duplicate messages. You must deduplicate them.

  • Subscribers in relayed live streaming sessions also receive custom messages.

  • Only one MediaExtensionMsg can be transmitted at a time. Multiple calls to sendMediaExtensionMsg cause the data from a new call to overwrite the data from the previous call.

Related callbacks

When the publisher sends media extension messages, subscribers receive them through the onMediaExtensionMsgReceived callback.

Parameter Description

Name

Type

Description

data

NSData *

The extension message content. Maximum length: 4 KB.

repeatCount

int

The number of repetitions. Used for redundancy to prevent message loss due to packet loss. -1 means infinite retries unless another sendMediaExtensionMsg is called.

delay

int

The delay in milliseconds before sending. Actual delay may be slightly longer because SEI is attached to encoded H.264/H.265 streams.

isKeyFrame

bool

Whether to attach SEI only to keyframes. Set to true to attach SEI only to keyframes.

Return value

A return value of 0 indicates success. Any other value indicates failure.

sendMediaExtensionMsgEx

Media extension information is transmitted and implemented at the underlying layer using SEI.

- (int)sendMediaExtensionMsgEx:(NSData *_Nonnull)data repeatCount:(int)repeatCount delay:(int)delay isKeyFrame:(bool)isKeyFrame payloadType:(int)payloadType;

The SDK supports sending and receiving media extension messages. This method sends messages using the Supplemental Enhancement Information (SEI) protocol. Receivers can obtain messages by listening to the onMediaExtensionMsgReceived callback. If payloadType is 5, this method functions identically to sendMediaExtensionMsg.

Common use cases include the following:

  • You can use media extension messages to transmit timestamps for end-to-end network latency calculation or to synchronize with other business logic.

  • You can use media extension messages to transmit descriptive information. Up to 4 KB of data can be sent. For small payloads, use JSON or plain strings.

When to call

You can call after starting stream ingest.

Call Limits

Media extension messages reuse the audio-video data channel. Therefore, you must control the frequency and size of these messages. The limitations are:

  • The maximum number of messages per second equals the frames per second (FPS) setting in the profile. Because SEI messages are embedded in H.264 or H.265 streams, video frame encoding is required to attach extension data.

  • To avoid affecting media transmission quality, the message body size is limited to 4 KB. This limit is suitable for small payloads.

  • The repeatCount parameter of the sendMediaExtensionMsg function defines message redundancy. Values greater than 1 trigger multiple transmissions.

  • To prevent packet loss from causing message loss, other users in the channel also receive duplicate messages. You must deduplicate them.

  • Subscribers in relayed live streaming sessions also receive custom messages.

  • Only one MediaExtensionMsg can be transmitted at a time. Multiple calls to sendMediaExtensionMsg overwrite previous data.

Parameters

Name

Type

Description

data

NSData *

The extension message content. Maximum length: 4 KB.

repeatCount

int

The number of repetitions. Used for redundancy to prevent message loss due to packet loss. -1 means infinite retries unless another sendMediaExtensionMsg is called.

delay

int

The delay in milliseconds before sending. Actual delay may be slightly longer because SEI is attached to encoded H.264/H.265 streams.

isKeyFrame

bool

Whether to attach SEI only to keyframes. Set to true to attach SEI only to keyframes.

payloadType

int

The type. Use 5 for UUID-based payloads. Valid range: [5, 100..254].

Return Description

  • 0: Success.

  • < 0: Failure. Returns an error code.

    • ERR_INNER (-1): Internal SDK error. Possible causes: The SDK was not initialized or was destroyed before the call.

onConnectionStatusChange

The callback that is invoked when the network connection status changes.

- (void)onConnectionStatusChange:(AliRtcConnectionStatus)status reason:(AliRtcConnectionStatusChangeReason)reason;

Parameters

Parameter

Type

Description

status

AliRtcConnectionStatus

The current status.

reason

AliRtcConnectionStatusChangeReason

The specific reason for the status change.

onLocalDeviceException

The callback that is invoked when a local device exception occurs. Pay attention to this callback.

- (void)onLocalDeviceException:(AliRtcLocalDeviceType)deviceType exceptionType:(AliRtcLocalDeviceExceptionType)exceptionType message:(NSString *_Nullable)msg;

Parameters

Parameter

Type

Description

deviceType

AliRtcLocalDeviceType

The device type.

exceptionType

AliRtcLocalDeviceExceptionType

The type of the device exception.

msg

NSString

The information carried in the exception.

onAuthInfoWillExpire

The callback that is invoked when user authentication is about to expire. The authentication expires 30 seconds after you receive this callback. Pay attention to this callback.

- (void)onAuthInfoWillExpire;

This callback indicates that user authentication will soon expire. Upon receiving it, authentication expires in 30 seconds. You must generate a new token and update authentication using one of the following methods:

  • Call the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6a4495191bmd" id="918ba91977wi6">refreshAuthInfo</a> API to update authentication information.

  • Call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#449873b819cz2" id="ad8235d30dprb">leaveChannel</a> to leave the current channel, and then call joinChannel to rejoin the channel.

Trigger Condition

The SDK triggers this callback 30 seconds before authentication expires. After you receive it, update authentication promptly.

onAuthInfoExpired

A user calls an authenticated API, and the server returns a response that has expired.

- (void)onAuthInfoExpired;

This callback indicates that user authentication has expired. To continue the session, generate a new token on your server and update authentication using one of the following methods:

  • Call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#449873b819cz2" id="21390e77a1307">leaveChannel</a> to leave the current channel, and then call joinChannel to rejoin the channel.

When triggered

This callback is triggered when user authentication expires.

onJoinChannelResult

This callback reports the result of joining a channel. It is functionally equivalent to the joinChannel method’s blocking operation. You can use either approach to handle the event that occurs after joining the channel.

- (void)onJoinChannelResult:(int)result channel:(NSString *_Nonnull)channel elapsed:(int) elapsed;

Trigger condition

This callback is triggered when your app calls the joinChannel method. It reports whether the operation succeeded or failed and returns related information, including join latency.

Parameters

Parameter

Type

Description

result

int

The result of the request to join the channel. A value of 0 indicates that the request is successful. A value other than 0 indicates the request failed and the error code is returned.

channel

NSString *_Nonnull

The ID of the channel.

elapsed

int

The amount of time consumed for joining the channel.

onLeaveChannelResult

This callback is invoked after you call leaveChannel. If you call destroy immediately after leaveChannel, this callback is not triggered.

- (void)onLeaveChannelResult:(int)result stats:(AliRtcStats)stats;

Parameters

Parameter

Type

Description

result

int

The result of the request to leave the channel. A value of 0 indicates that the request is successful. A value other than 0 indicates the request failed and the error code is returned.

stats

AliRtcStats

The statistics on the session in the channel.

onRemoteUserOffLineNotify

The callback that is invoked when a remote user goes offline.

- (void)onRemoteUserOffLineNotify:(NSString *_Nonnull)uid offlineReason:(AliRtcUserOfflineReason)reason;

This callback notifies local users when a remote user leaves the channel for any reason. It is triggered when a remote user goes offline.

Trigger condition

  • This callback is triggered when a remote user leaves the channel.

  • A remote streamer invokes <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#892915dd4edcy" id="78b1952ad5lwp">setClientRole</a> to switch to the viewer role (AliRtcClientRoleLive), and the callback is triggered.

  • The system detects that no data has been received from a remote streamer for an extended period and considers them offline.

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The unique user ID that is assigned by the AppServer.

reason

AliRtcUserOfflineReason

The reason why the remote user goes offline.

onRemoteUserOnLineNotify

The callback that is invoked when a remote user goes online.

- (void)onRemoteUserOnLineNotify:(NSString *_Nonnull)uid elapsed:(int)elapsed;

This method is triggered when a remote user joins the channel.

Trigger conditions

  • A remote user successfully joins the channel.

  • After the local user joins the channel, they receive join callbacks for users who were already in the channel to display previously joined users.

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The unique user ID that is assigned by the AppServer.

elapsed

int

The amount of time consumed for the remote user to join the channel.

onRemoteTrackAvailableNotify

The callback that is invoked when the stream of a remote user changes.

- (void)onRemoteTrackAvailableNotify:(NSString *_Nonnull)uid audioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;

This callback is triggered when a remote user’s publishing status changes. You can use it to monitor whether remote users are publishing audio and video streams and update the UI accordingly by showing or hiding their media.

Note

This callback reports the publishing status of remote users. To identify which stream stopped, compare the state before and after the callback is triggered.

Trigger conditions

This callback is triggered in the following cases:

  • A remote user transitions from not publishing to publishing audio and/or video.

  • A remote user transitions from publishing to not publishing audio and/or video.

  • In interactive mode, a remote user calls setClientRole to switch from viewer to streamer while publishing streams.

For example, this callback is not triggered if a remote user disables video stream ingest:

  • If a remote user starts publishing camera video (publishing status: no video → camera only), this callback returns AliRtcVideoTrackCamera, indicating that the remote user’s camera stream is available.

  • If the same user later publishes screen sharing as well (publishing status: camera only → camera + screen sharing), this callback returns AliRtcVideoTrackBoth, indicating that both camera and screen sharing streams are available.

  • If the user stops publishing camera video but continues screen sharing (publishing status: camera + screen sharing → screen sharing only), this callback returns AliRtcVideoTrackScreen, indicating that only the screen sharing stream is available.

  • If the user stops publishing screen sharing (publishing status: screen sharing only → no video), this callback returns AliRtcVideoTrackNo, indicating that no video stream is available.

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The unique user ID that is assigned by the AppServer.

audioTrack

AliRtcAudioTrack

The audio stream is updated following remote user changes.

videoTrack

AliRtcVideoTrack

The video stream updates after a remote user makes changes.

onBye

The callback that is invoked when a user is forced to leave a channel.

- (void)onBye:(int)code;

This callback is triggered when a user disconnects or the session ends. Developers can use the code parameter to identify the cause and handle it appropriately.

Trigger Conditions

  • The user is disconnected by the server.

  • The session ends (the server terminates the channel).

  • The user is passively disconnected. Clients should attempt session recovery or reconnection.

Parameters

Parameter

Type

Description

code

int

Message type. Valid values:

  • 1: The user is kicked out from the channel by the server.

  • 2: The channel is closed.

  • 3: The user is removed from the channel by the server because the same user ID is used to join the channel from another device.

onAudioPublishStateChanged

The callback that is invoked when the status of stream ingest for an audio track changes.

- (void)onAudioPublishStateChanged:(AliRtcPublishState)oldState newState:(AliRtcPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;

This callback monitors changes in the local user's audio publishing status.

Trigger conditions

This callback is triggered when the user's audio publishing status changes—for example:

  • Stop stream ingest.

  • You can invoke <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#892915dd4edcy" id="81771ef0798we">setClientRole</a> to switch to a viewer.

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

Previous stream ingest status.

newStat

AliRtcPublishState

Current stream ingest status.

elapseSinceLastState

NSInteger

The time elapsed for the change. Unit: milliseconds.

channel

NSString *_Nonnull

The ID of the channel.

onAudioSubscribeStateChanged

The callback that is invoked when the status of subscription to an audio track changes.

- (void)onAudioSubscribeStateChanged:(NSString *_Nonnull)uid oldState:(AliRtcSubscribeState)oldState newState:(AliRtcSubscribeState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;

This callback notifies local users when the subscription status for a remote user's audio stream changes. You can use it to track subscription status changes for a specific remote user's camera stream and the time interval between states.

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user for whom the subscription status changes.

oldState

AliRtcSubscribeState

The previous subscription state.

newState

AliRtcSubscribeState

The current subscription state.

elapseSinceLastState

NSInteger

The time elapsed for the change. Unit: milliseconds.

channel

NSString *_Nonnull

The ID of the channel.

onUserAudioMuted

The callback that is invoked when a user mutes the audio track.

- (void)onUserAudioMuted:(NSString *_Nonnull)uid audioMuted:(BOOL)isMute;

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who mutes the audio track.

isMute

BOOL

A value of YES indicates that the audio track is muted. A value of NO indicates that the audio track is not muted.

onUserAudioInterruptedBegin

The callback that is invoked when the audio track of a user is interrupted. For example, the audio track may be preempted when the user makes a phone call.

- (void)onUserAudioInterruptedBegin:(NSString *_Nonnull)uid;

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user whose audio track is interrupted.

onUserAudioInterruptedEnded

The callback that is invoked when the audio track interruption for a user ends. This callback is paired with the onUserAudioInterruptedBegin callback.

- (void)onUserAudioInterruptedEnded:(NSString *_Nonnull)uid;

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user whose audio track is interrupted.

onVideoPublishStateChanged

The callback that is invoked when the status of the stream ingest for a video track changes.

- (void)onVideoPublishStateChanged:(AliRtcPublishState)oldState newState:(AliRtcPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;

This callback monitors changes to the local user’s video publishing status.

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

Previous status of the stream ingest.

newState

AliRtcPublishState

Current stream ingest status.

elapseSinceLastState

NSInteger

The time elapsed for the change. Unit: milliseconds.

channel

NSString *_Nonnull

The ID of the channel.

onVideoSubscribeStateChanged

The callback that is invoked when the status of subscription to a video track changes.

- (void)onVideoSubscribeStateChanged:(NSString *_Nonnull)uid oldState:(AliRtcSubscribeState)oldState newState:(AliRtcSubscribeState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;

This callback notifies the local user of changes in the subscription status of a remote user's camera stream. It provides the new subscription status and the time elapsed between state changes.

Related callbacks

Video streams include camera streams and screen sharing streams. This callback is triggered by subscription changes to camera streams. Subscription changes to screen sharing streams trigger the onScreenShareSubscribeStateChanged callback.

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user for whom the subscription status changes.

oldState

AliRtcSubscribeState

The previous subscription state.

newState

AliRtcSubscribeState

The current subscription state.

elapseSinceLastState

NSInteger

The time elapsed for the change. Unit: milliseconds.

channel

NSString *_Nonnull

The ID of the channel.

onUserVideoMuted

User video mute notification.

- (void)onUserVideoMuted:(NSString *_Nonnull)uid videoMuted:(BOOL)isMute;

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who executed muteVideo.

isMute

BOOL

A value of YES indicates that black frames are sent for the video track. A value of NO indicates that the video track is normally published.

onUserVideoEnabled

A notification is sent when local video capture is disabled or re-enabled.

- (void)onUserVideoEnabled:(NSString *_Nullable)uid videoEnabled:(BOOL)isEnable;

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who performs the operation.

isMute

BOOL

A value of YES indicates that camera track capturing is enabled. A value of NO indicates that camera track capturing is disabled.

onUserWillResignActive

The callback that is invoked when a remote user switches the application to the background.

- (void)onUserWillResignActive:(NSString *_Nonnull)uid;

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who switches the app to the background.

onUserWillBecomeActive

The callback that is invoked when a remote user switches the application back to the foreground.

- (void)onUserWillBecomeActive:(NSString *_Nonnull)uid;

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who switches the app back to the foreground.

onRtcStats

The callback for real-time statistics. This callback is invoked every two seconds.

- (void)onRtcStats:(AliRtcStats)stats;

Parameters

Parameter

Type

Description

stats

AliRtcStats

Data callbacks

onRtcLocalVideoStats

Local video performance statistics (updates triggered every 2 seconds).

- (void)onRtcLocalVideoStats:(AliRtcLocalVideoStats *_Nonnull)localVideoStats;

Parameters

Parameter

Type

Description

localVideoStats

AliRtcLocalVideoStats

The local video statistics.

onRtcRemoteVideoStats

Remote video performance statistics, which are triggered every 2 s.

- (void)onRtcRemoteVideoStats:(AliRtcRemoteVideoStats *_Nonnull)remoteVideoStats;

Parameters

Parameter

Type

Description

remoteVideoStats

AliRtcRemoteVideoStats

The remote video statistics.

onRtcLocalAudioStats

Local audio statistics (triggered every 2 seconds).

- (void)onRtcLocalAudioStats:(AliRtcLocalAudioStats *_Nonnull)localAudioStats;

Parameters

Parameter

Type

Description

localAudioStats

AliRtcLocalAudioStats

The local audio statistics.

onRtcRemoteAudioStats

This callback provides remote audio statistics and is triggered every two seconds.

- (void)onRtcRemoteAudioStats:(AliRtcRemoteAudioStats *_Nonnull)remoteAudioStats;

Parameters

Parameter

Type

Description

remoteAudioStats

AliRtcRemoteAudioStats

The remote audio statistics.

onMediaExtensionMsgReceived

You have received a callback containing media extension information.

- (void)onMediaExtensionMsgReceived:(NSString *_Nonnull)uid payloadType:(int)payloadType message:(NSData *_Nonnull)data;

After one participant sends media extension messages using the sendMediaExtensionMsg method, other participants receive the data through this callback.

Parameters

Parameter

Type

Description

uid

NSString

The user ID.

payloadType

int

The payload type.

message

NSData *

The media extension message.

onAudioRouteChanged

This callback is invoked when the audio route changes and applies only to Android and iOS.

- (void)onAudioRouteChanged:(AliRtcAudioRouteType)routing;

Parameters

Parameter

Type

Description

routing

AliRtcAudioRouteType

The routing type.

onSnapshotComplete

A callback that is invoked when the snapshot operation completes.

- (void)onSnapshotComplete:(NSString*_Nullable)uid videoTrack:(AliRtcVideoTrack)videoTrack image:(UIImage* _Nullable)image success:(BOOL)success;

Parameters

Parameter

Type

Description

image

UIImage *

The image type.

success

BOOL

Whether the operation succeeded.

onLocalAudioStateChanged

Occurs when the state of the local audio capture device changes.

- (void)onLocalAudioStateChanged:(AliRtcLocalAudioStateType)state message:(NSString *_Nullable)msg;
Note

This callback reports the result of calling startAudioCapture and stopAudioCapture.

Parameters

Parameter

Type

Description

state

AliRtcLocalAudioStateType

The device state, of type AliRtcLocalAudioStateType.

msg

NSString *

The description of the device state change.

onLocalVideoStateChanged

Callback for the status of the local video capture device.

- (void)onLocalVideoStateChanged:(AliRtcLocalVideoStateType)state message:(NSString *_Nullable)msg;

Parameters

Parameter

Type

Description

state

AliRtcLocalVideoStateType

The device state, of type AliRtcLocalVideoStateType.

msg

NSString *

The description of the device state change.

onRemoteUserSubscribedDataChannel

The callback that is invoked when you can start sending Data Channel messages.

- (void)onRemoteUserSubscribedDataChannel:(NSString *_Nonnull)uid;

This callback is triggered when a remote user subscribes to the Data Channel. It notifies the local user that the specified remote user is ready to receive custom messages. You can safely call sendDataChannelMessage to send data at this point. This callback is critical for reliable message delivery because it prevents packet loss or failures that occur when messages are sent before the target user subscribes to the Data Channel.

Note

This callback is triggered only in AI scenarios.

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

onDataChannelMessage

This callback handles data channel messages.

- (void)onDataChannelMessage:(NSString *_Nonnull)uid controlMsg:(AliRtcDataChannelMsg*_Nonnull)controlMsg;

The ARTC SDK supports sending and receiving custom messages alongside audio and video data. This callback receives those custom messages. For usage details, see Custom message sending and receiving.

Note
  • In interactive scenarios, streamers can send and receive messages, whereas viewers can only receive messages.

  • This feature is disabled by default. To enable it, call setParameter after creating the engine to set {"data":{"enablePubDataChannel":true,"enableSubDataChannel":true}}.

When triggered

This callback is triggered after the sender calls sendDataChannelMessage to send a custom message and the receiver has enabled the data channel.

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

controlMsg

AliRtcDataChannelMsg

The data channel message.

onScreenSharePublishStateChanged

This callback is invoked when the status of stream ingest for screen sharing changes.

- (void)onScreenSharePublishStateChanged:(AliRtcPublishState)oldState newState:(AliRtcPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

The probing result. 0 means success. -1 means failure due to poor network quality.

newState

AliRtcPublishState

The previous publishing state.

newState

AliRtcPublishState

The new publishing state.

elapseSinceLastState

NSInteger

The time interval between state changes, in milliseconds.

channel

NSString *

The current channel ID.

onCapturedAudioFrame

Callback for raw data collection.

- (BOOL)onCapturedAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;

This callback retrieves raw audio data captured by the current device. It is disabled by default. To receive this data:

  • You can enable this callback using enableAudioFrameObserver(true, audioSource, config). The config parameter lets you set the sample rate, number of sound channels, and read/write mode.

  • You can call registerAudioFrameObserver to register the audio data receiver.

Note
  • This interface supports setting the sample rate, number of sound channels, and read/write mode.

  • You can avoid audio anomalies by not performing time-consuming operations in this callback.

  • This interface supports setting the sample rate and number of sound channels.

  • This interface supports read/write mode.

Limitations

Do not perform time-consuming operations in this callback. Doing so may cause audio anomalies.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

The video frame.

Return value

true: The operation succeeded.

onProcessCapturedAudioFrame

This callback delivers audio data after 3A processing.

- (BOOL)onProcessCapturedAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;

You can retrieve audio data after 3A processing using this callback. It is disabled by default. To enable it:

Note
  • This interface supports setting the sample rate, number of sound channels, and read/write mode.

  • Do not perform time-consuming operations in this callback because doing so may cause audio anomalies.

  • This interface supports setting the sample rate and number of sound channels.

  • This interface supports read/write mode.

Limitations

Do not perform time-consuming operations in this callback because doing so may cause audio anomalies.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

The video frame.

Return value

true: Success.

onPublishAudioFrame

Stream ingest data callback.

- (BOOL)onPublishAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;

This callback retrieves the audio data that is being published. It is disabled by default. To retrieve this data:

  • You can enable this callback using enableAudioFrameObserver(true, audioSource, config). The config parameter lets you set the sample rate, number of sound channels, and read/write mode.

  • You can call registerAudioFrameObserver to register the audio data receiver.

Note
  • This interface supports configuring the sample rate and number of sound channels, but only in read-only mode.

  • You should not perform time-consuming operations in this callback because doing so may cause audio anomalies.

  • This interface supports configuring the sample rate and number of sound channels.

  • This interface supports read/write mode.

Limitations

Avoid performing time-consuming operations in this callback. This may cause audio anomalies.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

The video frame.

Return value

true: The operation was successful.

onPlaybackAudioFrame

The callback for audio playback data.

- (BOOL)onPlaybackAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;

This callback retrieves audio playback data. It is disabled by default. To obtain this data:

Note
  • This interface supports setting the sample rate, number of sound channels, and read/write mode.

  • Do not perform time-consuming operations in this callback. Doing so may cause audio anomalies.

  • This interface supports setting the sample rate and number of sound channels.

  • This interface supports read/write mode.

Limitations

Do not perform time-consuming operations in this callback. Doing so may cause audio anomalies.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

The video frame.

Return value

true: Success.

onRemoteUserAudioFrame

This callback delivers audio data from a remote user’s audio stream.

- (BOOL)onRemoteUserAudioFrame:(NSString *_Nullable)uid frame:(AliRtcAudioFrame* _Nonnull)frame;

This callback is disabled by default. To retrieve remote user audio data:

  • Enable the callback by calling enableAudioFrameObserver(true, audioSource, config). The config parameter lets you specify the sample rate, number of sound channels, and read/write mode.

  • Call registerAudioFrameObserver to register the audio data receiver.

Note
  • This interface does not support setting the sample rate or number of sound channels, but it does support configuring the read/write mode.

  • Avoid performing time-consuming operations in this callback because doing so may cause audio anomalies.

  • This interface does not support setting the sample rate or number of sound channels.

  • This interface supports configuring the read/write mode.

Limitations

Avoid performing time-consuming operations in this callback because doing so may cause audio anomalies.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

The video frame.

Return value

true: The operation succeeded.

onDestroyCompletion

The callback that releases the DPI engine. The engine release completes only after this callback executes.

- (void)onDestroyCompletion;

This callback indicates that the SDK engine instance has been destroyed, and you can create a new instance.

Note

Wait for the onDestroyCompletion callback before calling other methods. This prevents the main thread from blocking.

Trigger Conditions

When a user calls destroy[2/2], this callback is triggered after the engine's destruction is complete.

onTextureCreate

Callback for OpenGL context creation.

- (void)onTextureCreate:(void *_Nullable)context;
Note

The SDK triggers this callback upon creating its internal OpenGL context.

Trigger conditions

This callback is triggered when the SDK creates its internal OpenGL context. You can initialize related resources in this callback.

Parameters

Parameter

Type

Description

context

void *

The OpenGL context.

onTextureUpdate

The OpenGL texture update callback.

- (int)onTextureUpdate:(int)textureId width:(int)width height:(int)height videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;
Note
  • This callback is triggered after each video frame is uploaded to the OpenGL texture. When an external OpenGL texture observer is registered, you can process the texture and return the processed texture ID.

  • The callback must return a valid texture ID. If no processing occurs, return the input textureId.

Trigger condition

This callback is triggered after each video frame is uploaded to the OpenGL texture. When an external OpenGL texture observer is registered, you can process the texture and return the processed texture ID.

Parameters

Parameter

Type

Description

textureId

int

The OpenGL context.

width

int

The video width.

height

int

The video height.

videoSample

AliRtcVideoDataSample

The video frame data.

Return value

Returns the new texture ID or the original texture ID. Returning a negative value indicates no texture ID update.

onTextureDestory

Destroy callback for the OpenGL context.

- (void)onTextureDestory;
Note

This callback is triggered when the SDK destroys its internal OpenGL context.

Trigger Condition

This callback is triggered when the SDK destroys its internal OpenGL context. You can clean up related resources here.

onCaptureVideoSample

This callback reports captured video frames.

- (BOOL)onCaptureVideoSample:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;

This callback retrieves raw video frames, such as YUV data, from the local camera. You can use this callback to implement custom video processing logic, such as adding filters, watermarks, or transcoding. You can then decide whether to send the processed data back to the SDK for encoding and rendering. Return true to write the processed video data back to the SDK.

When triggered

After you call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#9a3437ab16j1w" id="6c93b9cf8e771">registerVideoSampleObserver</a> to register the video data observer, the SDK captures the corresponding video frame.

Parameters

Parameter

Type

Description

videoSource

AliRtcVideoSource

The video stream type.

videoSample

AliRtcVideoDataSample

The raw video data.

Return value

Yes, you can write the processed video data back to the SDK, but this is supported only for I420 and CVPixelBuffer on iOS and macOS.

No: Do not write back to the SDK.

onPreEncodeVideoSample

This callback is triggered before local video data is encoded.

- (BOOL)onPreEncodeVideoSample:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;

This callback lets you retrieve raw video data, such as data in the YUV format, before the SDK encodes the video frames. You can use this data to implement custom processing logic, such as adding watermarks, adjusting colors, or transcoding. You can then decide whether to return the processed data to the SDK for subsequent encoding.

Parameters

Parameter

Type

Description

videoSource

AliRtcVideoSource

The video stream type.

videoSample

AliRtcVideoDataSample

The raw video data.

Return value

YES: The processed video data is returned to the SDK. This is effective only for data in the I420 and CVPixelBuffer formats on iOS and macOS.

No, you do not need to write back to the SDK.

onRemoteVideoSample

The callback for remote video data.

- (BOOL)onRemoteVideoSample:(NSString *_Nonnull)uid videoSource:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;

This callback retrieves raw video frame data (such as YUV format) from remote users. You can use it to implement custom processing logic—for example, adding filters, watermarks, or transcoding—and decide whether to return the processed data to the SDK for rendering.

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

videoSource

AliRtcVideoSource

The video stream type.

videoSample

AliRtcVideoDataSample

The raw video data.

Return value

YES: Write the processed video data back to the SDK (only effective for I420 and CVPixelBuffer on iOS/macOS).

NO: Do not write back to the SDK.

onGetVideoFormatPreference

The video data output format.

- (AliRtcVideoFormat)onGetVideoFormatPreference;
Note

Applications can return the preferred video data format. The default value is AliRtcYUV420.

Return value

The preferred video output format.

onGetVideoObservedFramePosition

The position at which video data is output.

- (NSInteger)onGetVideoObservedFramePosition;

Return value

The preferred video output position. For more information, see AliRtcVideoObserPosition.

onAudioEffectFinished

The callback that is invoked when the local playback of a sound effect ends.

- (void)onAudioEffectFinished:(int)soundId;

Parameters

Parameter

Type

Description

soundId

int

The ID of the sound effect.

onAudioVolumeCallback

Reports the audio volume, voice state, and UID of a subscribed user.

- (void)onAudioVolumeCallback:(NSArray <AliRtcUserVolumeInfo *> *_Nullable)array totalVolume:(int)totalVolume;

This callback retrieves remote user video frame data. You can use this callback to implement custom processing logic, such as adding filters or watermarks, and decide whether to return the processed data to the SDK for rendering.

Parameters

Parameter

Type

Description

array

NSArray <AliRtcUserVolumeInfo

*> *_Nullable

An array containing volume information for each user, including UID, speech status, and volume:

  • A UID value of 0 indicates the local speaker.

  • A UID value of 1 indicates the mixed volume of all remote users.

  • Other values indicate volume information for a specific remote user by UID.

totalVolume

int

The volume after the audio is mixed. Valid values: 0 to 255. If this callback is returned to a local user, the value of this parameter indicates the volume after the audio of the local user is mixed. If this callback is returned to a remote user, the value of this parameter indicates the volume after the audio from all speakers is mixed.

onActiveSpeaker

The callback that is invoked when a user speaks.

- (void)onActiveSpeaker:(NSString *_Nonnull)uid;

After you successfully invoke <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#85b41ef251dg0" id="a41de41e279og">enableAudioVolumeIndication</a>, the SDK continuously monitors the remote user with the highest audio volume, tracking the number of times that user is identified as having the highest audio volume. During the current time period, the remote user with the highest count is considered the most active user.

Trigger Condition

This callback is triggered when a channel contains two or more users and at least one remote user is actively speaking.

  • If the most active remote user remains the same, the SDK does not trigger the onActiveSpeaker callback again.

  • If the most active remote speaker changes, the SDK triggers this callback again and reports the new active speaker's UID.

Parameters

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who is speaking.

onPublishLiveStreamStateChanged

The callback that is invoked when the status of relayed live streaming changes.

- (void)onPublishLiveStreamStateChanged:(NSString *_Nonnull)streamURL state:(AliRtcLiveTranscodingState)state errCode:(AliRtcTrascodingLiveStreamErrorCode)errCode;

Parameters

Parameter

Type

Description

streamURL

NSString *

The ingest URL.

state

AliRtcLiveTranscodingState

The status.

errCode

AliRtcTrascodingLiveStreamErrorCode

The error code.

onPublishTaskStateChanged

The callback that is invoked when the status of a relayed live streaming task changes.

- (void)onPublishTaskStateChanged:(NSString *_Nonnull)streamURL state:(AliRtcTrascodingLiveTaskStatus)state;

Parameters

Parameter

Type

Description

streamURL

NSString *

The ingest URL.

state

AliRtcTrascodingLiveTaskStatus

The status.

onNetworkQualityChanged

The callback that is invoked when the network quality changes.

- (void)onNetworkQualityChanged:(NSString *_Nonnull)uid
               upNetworkQuality:(AliRtcNetworkQuality)upQuality
             downNetworkQuality:(AliRtcNetworkQuality)downQuality;

Parameters

Parameter

Type

Description

uid

NSString*

The user ID. An empty value for this parameter indicates the local user.

upQuality

AliRtcNetworkQuality

The upstream network status.

downQuality

AliRtcNetworkQuality

The downstream network status.

onLastmileDetectResultWithQuality

The callback for the result of network quality testing.

- (void)onLastmileDetectResultWithQuality:(AliRtcNetworkQuality)networkQuality;

Parameters

Parameter

Type

Description

networkQuality

AliRtcNetworkQuality

The network quality.

onLastmileDetectResultWithBandWidth

The callback that is invoked to return the result of network quality testing.

- (void)onLastmileDetectResultWithBandWidth:(int)code result:(AliRtcNetworkQualityProbeResult* _Nonnull)result;

Parameters

Parameter

Type

Description

code

int

A value of 0 indicates that the test is successful. A value of -1 indicates that the test failed and the network is poor.

result

AliRtcNetworkQualityProbeResult

The network quality.

onOccurError

If an error occurs in the engine, the app is notified through this callback.

- (void)onOccurError:(int)error  message:(NSString *_Nonnull)message;

Parameters

Parameter

Type

Description

error

int

The error type. See AliRtcErrorCode.

message

NSString *

The error description.

onFirstAudioPacketSentWithTimecost

Invoked when the first audio packet is sent.

- (void)onFirstAudioPacketSentWithTimecost:(AliRtcAudioTrack)track timeCost:(int)timeCost;

Parameters

Parameter

Type

Description

track

AliRtcAudioTrack

That track.

timeCost

int

The time taken to send the packet.

onFirstVideoFrameReceivedWithUid

This callback is invoked when the first video frame is received.

- (void)onFirstVideoFrameReceivedWithUid:(NSString *_Nonnull)uid
                      videoTrack:(AliRtcVideoTrack)videoTrack
                        timeCost:(int)timeCost;

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

videoTrack

AliRtcVideoTrack

The video stream label.

timeCost

int

The time cost in milliseconds.

onFirstVideoPacketSentWithVideoTrack

Callback for the first video packet sent.

- (void)onFirstVideoPacketSentWithVideoTrack:(AliRtcVideoTrack)videoTrack
                                    timeCost:(int)timeCost;

Parameters

Parameter

Type

Description

videoTrack

AliRtcVideoTrack

The video stream label.

timeCost

int

The time cost in milliseconds.

onFirstAudioPacketReceivedWithUid

This callback is invoked when the first audio packet is received.

- (void)onFirstAudioPacketReceivedWithUid:(NSString *_Nonnull)uid
                                 track:(AliRtcAudioTrack)track
                                 timeCost:(int)timeCost;

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

videoTrack

AliRtcAudioTrack

The audio stream label.

timeCost

int

The time cost in milliseconds.

onFirstRemoteAudioDecodedWithUid

Occurs when the first remote audio frame is decoded.

- (void)onFirstRemoteAudioDecodedWithUid:(NSString *_Nonnull)uid track:(AliRtcAudioTrack)track elapsed:(int)elapsed;

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

track

AliRtcAudioTrack

The audio stream label.

elapsed

int

The time cost in milliseconds.

onFirstRemoteVideoFrameDrawn

This callback is invoked when the first video frame from a remote user is rendered.

- (void)onFirstRemoteVideoFrameDrawn:(NSString *_Nonnull)uid videoTrack:(AliRtcVideoTrack)videoTrack width:(int)width height:(int)height elapsed:(int)elapsed;

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

videoTrack

AliRtcVideoTrack

The audio stream label.

width

int

The width.

height

int

The height.

elapsed

int

The total latency in milliseconds between the local user joining the channel and this callback firing.

onFirstLocalVideoFrameDrawn

This message is triggered when the preview begins displaying the first video frame.

- (void)onFirstLocalVideoFrameDrawn:(int)width height:(int)height elapsed:(int)elapsed;

Parameters

Parameter

Type

Description

width

int

The local preview video width.

height

int

The local preview video height.

elapsed

int

The total latency in milliseconds between the local user joining the channel and this callback firing.

onTestAudioVolumeCallback

This callback reports the audio volume during capture testing before a call.

- (void)onTestAudioVolumeCallback:(int)volume;

Parameters

Parameter

Type

Description

volume

int

The volume. Range: [0..100].

onAudioAccompanyStateChanged

The callback that is invoked when the local accompaniment playback state changes.

- (void)onAudioAccompanyStateChanged:(AliRtcAudioAccompanyStateCode)playState
                           errorCode:(AliRtcAudioAccompanyErrorCode)errorCode;

Parameters

Parameter

Type

Description

playState

AliRtcAudioAccompanyStateCode

The accompaniment playback state.

errorCode

AliRtcAudioAccompanyErrorCode

The error code.

onRemoteAudioAccompanyStarted

This callback is triggered when a remote user begins playback of the music accompaniment.

- (void)onRemoteAudioAccompanyStarted:(NSString *_Nonnull)uid;

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

onRemoteAudioAccompanyFinished

This callback is invoked when a remote user finishes playing audio accompaniment.

- (void)onRemoteAudioAccompanyFinished:(NSString *_Nonnull)uid;

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

setParameter

Sets custom parameters.

- (int)setParameter:(NSString * _Nonnull)param;

Parameters

Parameter

Type

Description

param

String

The custom parameter.

getParameter

Queries custom parameters.

- (NSString * _Nonnull)getParameter:(NSString * _Nonnull)param;

Parameters

Parameter

Type

Description

param

String

The custom parameter.

enableAudioFrameObserver

Configures audio callback settings.

- (int)enableAudioFrameObserver:(bool)enable audioSource: (AliRtcAudioSource)audioSource config:(AliRtcAudioFrameObserverConfig*_Nullable)config;

This method enables or disables callbacks for specified types of audio data, allowing developers to retrieve raw and encoded audio frames. By default, these callbacks are disabled. To enable them, call this method.

Note

To enable audio data callbacks for a specific AliRtcAudioSource, you must also call registerAudioFrameObserver to specify the audio data receiver.

When to call

You can call this method to enable audio frame retrieval.

Parameters

Parameter

Type

Description

enable

bool

Specifies whether to allow callbacks.

audioSource

AliRtcAudioSource

The type of the callback data source.

config

AliRtcAudioFrameObserverConfig

Callback parameter settings.

registerAudioFrameObserver

Registers an audio callback.

- (int)registerAudioFrameObserver:(id<AliRtcAudioFrameDelegate> _Nullable)observer;

This method registers the object that receives audio callback data.

When to call

You can call this method when your app needs the SDK to trigger the onCapturedAudioFrame, onProcessCapturedAudioFrame, onPublishAudioFrame, onPlaybackAudioFrame, or onRemoteUserAudioFrame callbacks to retrieve audio data. To unregister, call this method again with nil.

Limitations

You must call enableAudioFrameObserver to enable callbacks for the specific AliRtcAudioSource. Otherwise, the provided observer will not receive data.

Parameters

Parameter

Type

Description

observer

AliRtcAudioFrameDelegate

The audio callback.

registerVideoSampleObserver

Registers an object that is used to export video data.

- (void)registerVideoSampleObserver;

unRegisterVideoSampleObserver

You can cancel the registration of video data output.

- (void)unregisterVideoSampleObserver;

setLogDirPath

Sets the path for storing the log files of the SDK.

Important

We recommend that you call this method before you call all other methods to avoid log loss. Before you call this method, make sure that the path specified by the logDirPath parameter exists and log files can be written to the path.

+ (int)setLogDirPath:(NSString *_Nullable)logDirPath;

Parameters

Name

Type

Description

logDirPath

NSString *_Nullable

The absolute path for storing the log files of the SDK.

  • By default, the log files of ARTC SDK for iOS are stored in the Library/Caches/Ali_RTC_Log path,

  • The default path for macOS logs is /Users/xxx/Documents/Ali_RTC_Log.

Return Description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setLogLevel

Sets the log level.

- (void)setLogLevel:(AliRtcLogLevel)logLevel;

Parameters

Name

Type

Description

logLevel

AliRtcLogLevel

The log level. Default value: AliRtcLogLevelInfo.

setAudioSessionOperationRestriction

Specifies whether the SDK has the permission to control AVAudioSession.

- (int)setAudioSessionOperationRestriction:(AliRtcAudioSessionOperationRestriction)restriction;

Parameters

Name

Type

Description

restriction

AliRtcAudioSessionOperationRestriction

The control permission of the SDK. Default value: AliRtcAudioSessionOperationRestrictionNone.

setDeviceOrientationMode

You can set the device orientation.

- (int)setDeviceOrientationMode:(AliRtcOrientationMode)mode;

Parameters

Name

Type

Description

mode

AliRtcOrientationMode

The device orientation.

Return value

A return value of 0 indicates success. Any other value indicates failure.

getNetworkTime

Retrieves the timeline timestamp.

-(long long)getNetworkTime;

Return value

The timestamp.

sendDataChannelMessage

-(int) sendDataChannelMessage:(AliRtcDataChannelMsg* _Nonnull)controlMsg;

The ARTC SDK supports sending and receiving custom messages along with audio and video data. This interface lets you send real-time messages—such as control instructions, synchronization data, or business messages—while transmitting audio and video. For more information, see Custom message sending and receiving.

Note
  • The custom message channel is disabled by default. To use this feature, you can call the setParameter API to enable the custom message channel by setting {"data":{"enablePubDataChannel":true,"enableSubDataChannel":true}}. You can enable it before or after joining the channel.

  • Messages can be any data—such as text.

Related callbacks

  • After the sender successfully enables the custom message channel, they can call this method to send messages. Receivers receive messages through the onDataChannelMessage callback.

Limitations

  • Streamers can send and receive messages. Viewers can only receive messages.

  • You must call setParameter to enable the custom message channel.

  • Data transmission limits are:

    • Maximum bitrate: 30 KB/s.

    • A maximum of 60 packets per second. Each packet is limited to 1 KB.

Parameters

Name

Type

Description

controlMsg

AliRtcDataChannelMsg *

The accompaniment control message.

Return value

0 indicates success. Other values indicate failure.

startScreenShare

You can start sharing the screen and audio stream.

- (int)startScreenShare:(NSString * _Nonnull)appGroup
mode:(AliRtcScreenShareMode)mode;

Parameters

Name

Description

appGroup

The app package name. Example: @"group.com.aliyun.rtc.demo"

mode

The screen sharing type. For more information, see AliRtcScreenShareMode.

Return Description

A value of 0 indicates that the call was successful. A value other than 0 indicates that the call failed.

startScreenShare

You can start sharing the screen video stream.

Important

The method will be phased out. We recommend using startScreenShare (new).

- (int)startScreenShare;

Return description

A value of 0 indicates that the call was successful. A value other than 0 indicates that the call failed.

stopScreenShare

Stops the screen sharing stream and the associated audio stream.

- (int)stopScreenShare;

Return Description

A value of 0 indicates that the call was successful. A value other than 0 indicates that the call failed.

isScreenSharePublished

Queries whether a screen-sharing stream is being ingested.

- (BOOL)isScreenSharePublished;

Return Description

true: A screen-sharing stream is being ingested. false: No screen-sharing streams are being ingested.

setScreenShareEncoderConfiguration

Sets the screen sharing encoder configuration.

- (void)setScreenShareEncoderConfiguration:(AliRtcScreenShareEncoderConfiguration* _Nonnull)config;
Note

This method configures video encoding properties for screen sharing, such as resolution, frame rate, bitrate, and orientation. All parameters have valid ranges. If you specify invalid values, the SDK automatically adjusts them to valid values. You can call this method before or after joining a channel. To configure screen sharing encoding once per session, you can call it before joining.

Parameters

Name

Type

Description

config

AliRtcScreenShareEncoderConfiguration

Screen sharing video encoding parameters, such as resolution, frame rate, bitrate, and orientation. All parameters have valid ranges. If you specify invalid values, the SDK automatically adjusts them.

setAudioShareAppVolume

Sets the volume of the shared audio stream.

- (int)setAudioShareAppVolume:(int)volume;

Parameters

Name

Description

volume

The volume. Valid values: 0 to 100. Default value: 50.

Return description

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

setGlobalEnvironment

You can set the global environment.

- (BOOL) setGlobalEnvironment:(AlivcGlobalEnv)env;

This method specifies the SDK’s global runtime environment and primarily determines where logs and instrumentation data are sent.

  • If set to Chinese mainland, logs and instrumentation are sent to Chinese mainland data centers.

  • If set to outside China, data is routed to overseas data centers (such as Singapore).

When to call

We recommend calling this early in the app initialization.

Limitations

  • This setting applies globally and requires only one call.

  • Multiple calls overwrite previous environment settings. Changing the environment dynamically can affect existing connections or sessions, so do not change it while a process is running.

Call Example

var sdkEnv: AlivcGlobalEnv = .DEFAULT
let sdkEnvResult = AlivcBase.environmentManager.setGlobalEnvironment(self.sdkEnv)
"Set RTC environment to: \(sdkEnv) result: \(sdkEnvResult)".printLog()
AlivcGlobalEnv env = AlivcGlobalEnv_DEFAULT;
AlivcBase.EnvironmentManager.globalEnvironment = env;

Parameters

Parameter

Type

Description

env

AlivcGlobalEnv

Specifies the global environment. It supports the following enumeration values:
ENV_DEFAULT: environment inside China.
ENV_SEA: environment outside China, such as Singapore.




Return value
Returns an int result code.

  • 0: The operation succeeded.

  • Values other than 0 indicate failure.