All Products
Search
Document Center

Intelligent Media Services:AliRtcEngine class

Last Updated:Dec 12, 2025

This topic describes the methods of the AliRtcEngine class provided by the ApsaraVideo Real-time Communication (ARTC) SDK for iOS.

Contents

Basic methods

API

Description

sharedInstance

Creates an AliRtcEngine instance in singleton pattern.

destroy[1/2]

Destroys an AliRtcEngine instance synchronously.

destroy[2/2]

Destroys an AliRtcEngine instance asynchronously.

setH5CompatibleMode

Sets the H5 compatibility mode.

getH5CompatibleMode

Checks whether the current mode is H5-compatible.

getSdkVersion

Gets the SDK version number.

Channel-related methods

API

Description

setChannelProfile

Sets the channel profile.

setAudioProfile

Sets the audio profile.

isAudioOnly

Queries whether the current mode is audio-only.

setAudioOnlyMode

Sets the mode to audio-only or audio and video.

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

Sets the user role.

getCurrentClientRole

Gets the user role.

refreshAuthInfo

Refreshes the authentication information.

refreshAuthInfoWithToken

Refreshes the authentication information.

Methods related to publishing and subscribing

API

Description

publishLocalAudioStream

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

isLocalAudioStreamPublished

Queries whether the audio stream is being published.

setDefaultSubscribeAllRemoteAudioStreams

Specifies whether to subscribe to remote audio streams by default. By default, all remote audio streams are subscribed.

We recommend that you call this method before you join a channel.

subscribeRemoteAudioStream

Stops or resumes pulling the audio stream of a specific remote user.

subscribeAllRemoteAudioStreams

Stops or resumes receiving all remote audio streams.

publishLocalVideoStream

Specifies whether to publish the video stream.

isLocalVideoStreamPublished

Queries whether the video stream is published.

setDefaultSubscribeAllRemoteVideoStreams

Specifies whether to subscribe to remote video streams by default. By default, all remote video streams are subscribed.

We recommend that you call this method before you join a channel.

subscribeRemoteVideoStream

Stops or resumes subscribing to the video stream of a remote user.

subscribeAllRemoteVideoStreams

Stops or resumes receiving all remote video streams.

subscribeRemoteMediaStream[1/2]

Stops or resumes the media stream of a specific remote user.

We recommend that you call this method when both audio and video streams exist and need to be controlled.

subscribeRemoteMediaStream[2/2]

Stops or resumes the media stream of a specific remote user.

We recommend that you call this method when both audio and video streams exist and need to be controlled.

subscribeRemoteDestChannelStream

Stops or resumes the media stream of a specific remote user across channels.

subscribeRemoteDestChannelAllStream

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

setRemoteAudioVolume

Sets the volume of remote audio.

Methods related to audio device management

API

Description

muteLocalMic

Specifies whether to stop publishing local audio.

muteRemoteAudioPlaying

Specifies whether to stop playing a remote audio stream.

muteAllRemoteAudioPlaying

Stops or resumes the playback of all remote audio.

startAudioCapture[1/2]

Starts audio collection.

startAudioCapture[2/2]

Starts audio collection.

stopAudioCapture

Stops audio collection.

enableSpeakerphone

Sets the audio output to the earpiece or speaker.

isEnableSpeakerphone

Gets the current audio output device, either earpiece or speaker.

enableAudioVolumeIndication

Enables the volume detection feature.

enableEarBack

Enables in-ear monitoring.

setEarBackVolume

Sets the in-ear monitoring volume (iOS only).

startAudioPlayer

Starts audio playback.

stopAudioPlayer

Stops audio playback.

setPlayoutVolume

Sets the playback volume.

setRecordingVolume

Sets the collection volume.

playAudioFileTest

Starts testing the audio playback device.

stopAudioFileTest

Stops testing the audio playback device.

startAudioCaptureTest

Starts testing the audio collection device.

stopAudioCaptureTest

Stops testing the audio collection device.

setDefaultAudioRoutetoSpeakerphone

Sets the default output device.

Voice changing and reverberation

API

Description

setAudioEffectVoiceChangerMode

Sets the voice changer mode.

setAudioEffectPitchValue

Sets the pitch parameter.

setAudioEffectReverbMode

Sets the reverberation mode.

setAudioEffectReverbParamType

Sets the reverberation type and specific parameters.

Custom audio input

API

Description

addExternalAudioStream

Adds an external audio stream.

pushExternalAudioStream

Inputs external audio stream data.

setExternalAudioStream:publishVolume

Sets the stream ingest volume.

getExternalAudioStreamPublishVolume

Gets the stream ingest volume.

setExternalAudioStream:playoutVolume

Sets the playback volume of an external audio stream.

getExternalAudioStreamPlayoutVolume

Gets the playback volume of an external audio stream.

removeExternalAudioStream

Deletes an external stream ingest.

Audio accompaniment

API

Description

getAudioFileInfo

Gets information about an audio accompaniment file.

startAudioAccompanyWithFile

Starts playing an accompaniment file.

stopAudioAccompany

Stops playing an accompaniment file.

setAudioAccompanyVolume

Sets the accompaniment volume.

setAudioAccompanyPublishVolume

Sets the stream ingest volume of an accompaniment file.

getAudioAccompanyPublishVolume

Gets the stream ingest volume of an accompaniment file.

setAudioAccompanyPlayoutVolume

Sets the playback volume of an accompaniment file.

getAudioAccompanyPlayoutVolume

Gets the playback volume of an accompaniment file.

pauseAudioAccompany

Pauses the playback of an accompaniment.

resumeAudioAccompany

Resumes the playback of an accompaniment.

getAudioAccompanyDuration

Gets the duration of an accompaniment file.

getAudioAccompanyCurrentPosition

Gets the current playback position of an accompaniment.

setAudioAccompanyPosition

Sets the playback position of an accompaniment.

Sound effects

API

Description

preloadAudioEffectWithSoundId

Preloads a sound effect file.

unloadAudioEffectWithSoundId

Deletes a preloaded sound effect file.

playAudioEffectWithSoundId

Starts playing a sound effect.

stopAudioEffectWithSoundId

Stops playing a sound effect.

stopAllAudioEffects

Stops playing all sound effects.

pauseAudioEffectWithSoundId

Pauses a sound effect.

pauseAllAudioEffects

Pauses all sound effects.

resumeAudioEffectWithSoundId

Resumes a specified sound effect file.

resumeAllAudioEffects

Resumes all sound effect files.

setAudioEffectPublishVolumeWithSoundId

Sets the stream ingest volume of a mixed sound effect.

getAudioEffectPublishVolumeWithSoundId

Gets the stream ingest volume of a mixed sound effect.

setAllAudioEffectsPublishVolume

Sets the stream ingest volume of all mixed sound effects.

setAudioEffectPlayoutVolumeWithSoundId

Sets the local playback volume of a sound effect.

getAudioEffectPlayoutVolumeWithSoundId

Gets the local playback volume of a sound effect.

setAllAudioEffectsPlayoutVolume

Sets the local playback volume of all sound effects.

Record audio and video files

API

Description

startRecord

Records audio and video files (AAC, WAV, or MP4).

stopRecord

Stops recording audio and video files.

Methods related to video device management

API

Description

setLocalViewConfig

Sets the rendering window and drawing parameters for local preview.

setCameraCapturerConfiguration

Sets the camera capture preferences.

enableLocalVideo

Disables or re-enables local video collection.

muteLocalCamera

Specifies whether to stop publishing the local video stream.

setRemoteViewConfig

Sets the rendering window and drawing parameters for a remote video.

isCameraOn

Checks whether the camera is on.

setVideoEncoderConfiguration

Sets the video encoding properties.

setVideoDecoderConfiguration

Sets the video decoding properties.

switchCamera

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

getCurrentCameraDirection

Gets the current camera direction.

startPreview

Starts a local preview.

stopPreview

Stops a local preview.

setCameraZoom

Sets the camera zoom.

GetCameraMaxZoomFactor

Gets the maximum zoom factor of the camera.

GetCurrentZoom

Gets the maximum zoom factor of the camera.

SetExposure

Sets the camera exposure.

GetCurrentExposure

Gets the camera exposure.

GetMinExposure

Gets the minimum camera exposure.

GetMaxExposure

Gets the maximum camera exposure.

setCameraFlash

Sets the camera flash on or off.

isCameraFocusPointSupported

Queries whether the camera supports manual focus.

isCameraExposurePointSupported

Queries whether the camera supports setting an exposure point.

setCameraFocusPoint

Sets the manual focus point for the camera.

setCameraExposurePoint

Sets the exposure point for the camera.

isCameraAutoFocusFaceModeSupported

Queries whether the camera supports face-autofocus.

setCameraAutoFocusFaceModeEnabled

Enables or disables face-autofocus for the camera.

setVideoMirrorMode

Sets the mirror mode for preview and stream ingest.

SetCapturePipelineScaleMode

Sets the timing for capture scaling to determine whether video data is scaled immediately upon capture or during encoding.

Configure video data callbacks

API

Description

registerVideoFrameWithObserver

Registers a video data callback.

unregisterVideoSampleWithObserver

Deregisters a video data callback.

registerLocalVideoTextureObserver

Registers a video texture callback.

unregisterLocalVideoTextureObserver

Deregisters a video texture callback.

snapshotVideo

Takes a snapshot of the camera view.

registerVideoSampleObserver

Registers a video data output callback.

unRegisterVideoSampleObserver

Deregisters a video data output callback.

Configure audio data callbacks

API

Description

enableAudioFrameObserver

Sets audio callback parameters.

registerAudioFrameObserver

Registers an audio data callback.

Custom video input

API

Description

setExternalVideoSource

Enables an external video source.

pushExternalVideoFrame

Inputs video data.

Screen sharing methods

API

Description

startScreenShare

Starts screen sharing stream ingest.

startScreenShare

Starts screen sharing stream ingest.

Note

This method is to be deprecated.

stopScreenShare

Stops screen sharing stream ingest.

setAudioShareAppVolume

Sets the volume of the shared audio stream.

isScreenSharePublished

Queries whether screen sharing is being published.

setScreenShareEncoderConfiguration

Configures screen sharing encoding parameters.

Bypass live streaming methods

API

Description

startPublishLiveStreamWithURL

Starts bypass live streaming.

updatePublishLiveStreamWithURL

Updates parameters for bypass live streaming.

stopPublishLiveStreamWithURL

Stops bypass live streaming.

GetPublishLiveStreamStateWithURL

Gets the status of bypass live streaming.

Network quality probing methods

API

Description

startLastmileDetect

Starts network quality probing.

stopLastmileDetect

Stops network quality probing.

SEI

API

Description

sendMediaExtensionMsg

Pushes an SEI stream.

sendMediaExtensionMsgEx

Pushes an SEI stream (extended).

Other methods

API

Description

setParameter

Sets custom parameters.

getParameter

Gets custom parameters.

setLogDirPath

Sets the path to store SDK log files.

setLogLevel

Sets the log level.

setAudioSessionOperationRestriction

Sets the SDK's control permissions for AVAudioSession.

setDeviceOrientationMode

Sets the device orientation.

getNetworkTime

Gets the network timestamp.

sendDataChannelMessage

Sends a data channel message.

Callbacks

AliRtcEngineDelegate

API

Description

onConnectionStatusChange

The callback for the network connection status. You need to pay attention to this callback.

onLocalDeviceException

The callback for a local device exception. You need to pay attention to this callback.

onAuthInfoWillExpire

The callback that is invoked when the user authentication is about to expire. The authentication expires 30 seconds after this callback is received. You need to pay attention to this callback.

onAuthInfoExpired

The callback that is invoked when you call an API that requires authentication and the server returns a message indicating that the authentication has expired.

onJoinChannelResult

The callback for the result of joining a channel.

onLeaveChannelResult

The callback for the result of leaving a channel.

onRemoteUserOffLineNotify

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

onRemoteUserOnLineNotify

Notifications for remote users coming online.

onRemoteTrackAvailableNotify

The callback for remote stream publishing information.

onBye

This message is sent when you are kicked out of the channel by the server or when the meeting ends.

onAudioPublishStateChanged

The callback for the audio stream publishing state.

onAudioSubscribeStateChanged

The callback for the audio stream subscription state.

onUserAudioMuted

Notification that a remote user is muted.

onUserAudioInterruptedBegin

The callback that is invoked when an audio device interruption starts.

onUserAudioInterruptedEnded

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

onVideoPublishStateChanged

The callback for a change in the video publishing state.

onVideoSubscribeStateChanged

The callback for a change in the camera stream subscription state.

onUserVideoMuted

The callback that is invoked when a remote user starts or stops sending black frames.

onUserVideoEnabled

The callback that is invoked when a remote user disables or enables camera stream collection.

onUserWillResignActive

The remote user's application enters the background.

onUserWillBecomeActive

The remote user's application returns to the foreground.

onAudioEffectFinished

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

onAudioVolumeCallback

The volume and state of the subscribed audio, and the user ID (UID).

onActiveSpeaker

The callback for the active speaker, triggered by voice activity detection.

onPublishLiveStreamStateChanged

The callback for a change in the bypass live streaming state.

onPublishTaskStateChanged

The callback for a change in the bypass task state.

onNetworkQualityChanged

The callback for a change in network quality.

onLastmileDetectResultWithQuality

The callback for the network quality probe.

onLastmileDetectResultWithBandWidth

The callback for the network quality probe result.

onOccurError

The callback that is invoked to notify the application when an engine error occurs.

onFirstAudioPacketSentWithTimecost

The callback for the first audio packet sent.

onFirstVideoFrameReceivedWithUid

The callback for the first video frame received.

onFirstVideoPacketSentWithVideoTrack

The callback for the first video packet sent.

onFirstAudioPacketReceivedWithUid

The callback for the first audio packet received.

onFirstRemoteAudioDecodedWithUid

The callback for the first decoded remote audio frame.

onFirstRemoteVideoFrameDrawn

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

onFirstLocalVideoFrameDrawn

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

onTestAudioVolumeCallback

The callback for the volume from the pre-call audio collection test.

onAudioAccompanyStateChanged

The callback for the local audio accompaniment playback state.

onRemoteAudioAccompanyStarted

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

onRemoteAudioAccompanyFinished

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

onRtcStats

The callback for real-time data, triggered every 2 seconds.

onRtcLocalVideoStats

The callback for local video statistics, triggered every 2 seconds.

onRtcRemoteVideoStats

The callback for remote video statistics, triggered every 2 seconds.

onRtcLocalAudioStats

The callback for local audio statistics, triggered every 2 seconds.

onRtcRemoteAudioStats

The callback for remote audio statistics, triggered every 2 seconds.

onMediaExtensionMsgReceived

The callback that is invoked when a media extension message is received.

onAudioRouteChanged

The callback for a change in the audio route.

onSnapshotComplete

The callback for a snapshot.

onLocalAudioStateChanged

The callback for the state of the local audio collection device.

onLocalVideoStateChanged

The callback for the state of the local video collection device.

onRemoteUserSubscribedDataChannel

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

onDataChannelMessage

The callback for data channel messages.

onScreenSharePublishStateChanged

The callback for a change in the screen sharing publishing state.

AliRtcAudioFrameDelegate

API

Description

onCapturedAudioFrame

The callback for captured raw data.

onProcessCapturedAudioFrame

The callback for data after 3A processing.

onPublishAudioFrame

The callback for stream publishing data.

onPlaybackAudioFrame

The callback for playback data.

onRemoteUserAudioFrame

The callback for remote stream pulling data.

AliRtcEngineDestroyDelegate

API

Description

onDestroyCompletion

The callback that is invoked when the engine is released. The engine is released only after this callback is executed.

AliRtcTextureDelegate

API

Description

onTextureCreate

The callback that is invoked when the OpenGL context is created.

onTextureUpdate

The callback that is invoked when the OpenGL texture is updated.

onTextureDestory

The callback that is invoked when the OpenGL context is destroyed.

AliRtcVideoFrameDelegate

API

Description

onCaptureVideoSample

The callback for captured video frames.

onPreEncodeVideoSample

The callback for subscribed local video data before encoding.

onRemoteVideoSample

The callback for subscribed remote video data.

onGetVideoFormatPreference

The output format of the video data.

onGetVideoObservedFramePosition

The output position of the video data.

Method details

sharedInstance

Creates an AliRtcEngine instance using the singleton pattern.

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

When to call

You must call this method to create an AliRtcEngine instance before calling any other ARTC SDK APIs.

Call restrictions

  • This method is a synchronous call and can only be invoked on the main thread.

  • The SDK supports only one AliRtcEngine instance per application.

Related callbacks

After creating an engine instance, implement the callbacks in AliRtcEngineDelegate based on your business scenario. If the SDK encounters an exception during operation, it first attempts automatic recovery using an internal retry mechanism. For errors that cannot be resolved internally, the SDK notifies your application through predefined callback interfaces. The following are key callbacks that the SDK cannot handle and must be monitored and responded to by the application layer:

Cause of exception

Callback and parameters

Solution

Description

Authentication failed

The result parameter in the onJoinChannelResult callback returns AliRtcErrJoinBadToken.

If this error occurs, check whether the token is valid in the application.

If authentication fails when a user calls an API, the system returns an error message that indicates the authentication failure in the API callback.

Network connection exception

The onConnectionStatusChange callback returns AliRtcConnectionStatusFailed.

If this exception occurs, the application needs to rejoin the channel.

The SDK can automatically recover from a network disconnection within a certain period. However, if the disconnection time exceeds the preset threshold, a timeout is triggered and the connection is broken. In this case, the application should check the network status and guide the user to rejoin the meeting.

Local device exception

onLocalDeviceException

If this exception occurs, check whether the permissions and device hardware are normal in the application.

The ARTC service supports device detection and exception diagnosis. When a local device exception occurs, the ARTC service notifies the customer through a callback. If the SDK cannot resolve the issue, the application needs to intervene to check whether the device is normal.

Kicked offline

onBye

  • AliRtcOnByeUserReplaced: If this exception occurs, check whether the user IDs are the same.

  • AliRtcOnByeBeKickedOut: If this exception occurs, it indicates that the user was kicked offline by the service and needs to rejoin the channel.

  • AliRtcOnByeChannelTerminated: If this exception occurs, it indicates that the channel was destroyed and the user needs to rejoin the channel.

The ARTC service provides a feature for administrators to actively remove participants.

Authentication is about to expire

onWillAuthInfoExpire

If this exception occurs, the application needs to get the latest authentication information and then call refreshAuthInfo to refresh the authentication information.

An authentication expiration error occurs in two situations: when a user calls an API or during program execution. Therefore, the error feedback is sent through an API callback or an independent error callback.

Authentication has expired

onAuthInfoExpired

If this exception occurs, the application needs to rejoin the channel.

An authentication expiration error occurs in two situations: when a user calls an API or during program execution. Therefore, the error feedback is sent through an API callback or an independent error callback.

Parameter description

Name

Type

Description

delegate

id<AliRtcEngineDelegate>_Nullable

The delegate that listens for callbacks.

extras

NSString *_Nullable

Used to receive parameters from customer grayscale releases. Configure special SDK features through JSON Configurations. This can be an empty string.

destroy[1/2]

Destroys the AliRtcEngine instance.

+ (void)destroy;

Destroys the AliRtcEngine singleton object and releases all internal resources. After this call, you can no longer use other methods of AliRtcEngine or receive any callbacks. To use the engine again, you must call <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.

Both this method and destroy[2/2] can destroy the engine instance. The difference is that destroy[2/2] lets you pass a listener object to monitor the completion of the destruction process.

Note
  • To create an AliRtcEngine instance again after destruction, ensure that you do so only after this method has completed execution.

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

When to call

Call this method when Real-Time Communication ends and you no longer need AliRtcEngine features to release the instance and reduce unnecessary resource usage.

Call restrictions

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

destroy[2/2]

Destroys an AliRtcEngine instance.

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

This method destroys the AliRtcEngine singleton object. After you call this method, all internal resources are released, and you can no longer use other methods of AliRtcEngine or receive any callbacks. To use the engine again, you must create a new instance by calling <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#2db21d4f16s77" id="115fd691743nx">sharedInstance</a>.

Note

Both this method and destroy[1/2] can release the AliRtcEngine instance. The difference is that this method performs an asynchronous invocation and lets you pass an observer to monitor when the destroy process completes. You can create another instance only after onDestroyCompletion completes.

When to call

Call this method to release the instance after completing Real-Time Communication.

Call restrictions

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

Parameter description

Name

Type

Description

delegate

AliRtcEngineDestroyDelegate

The callback object after release.

setH5CompatibleMode

Specifies whether to enable H5 compatibility mode.

Important

You cannot change the H5 compatibility mode after creating an AliRtcEngine instance. You must call this method before creating the instance.

+ (void)setH5CompatibleMode:(BOOL)comp;

Parameter description

Name

Type

Description

comp

BOOL

YES enables H5 compatibility. NO disables H5 compatibility. The default is NO.

getH5CompatibleMode

Checks whether H5 compatibility mode is enabled.

+ (BOOL)getH5CompatibleMode;

Return description

YES indicates H5 compatibility is enabled. NO indicates it is disabled.

getSdkVersion

Gets the SDK version number.

+ (NSString *_Nonnull)getSdkVersion;

Return value

The current SDK version number in string format, such as "2.5.0.x".

Description

This is a static method and can be called at any time to retrieve the version number.

setChannelProfile

Sets the channel profile.

- (int)setChannelProfile:(AliRtcChannelProfile)profile;

This method sets the channel profile. It provides two main scenarios: video call and interactive stream.

  • Video call profile: All users are streamers and can publish and subscribe to streams.

  • Interactive live streaming mode: 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 role. Users who ingest streams in the channel must set their role to streamer (AliRTCSdkInteractive). If a user only needs to pull streams and does not ingest streams, their role must be set to viewer (AliRTCSdkLive). This mode is recommended for RTC scenarios.

Note
  • We recommend using the interactive stream profile for all RTC scenarios. To do this, call this method and set the profile to AliRTCSdkInteractiveLive.

  • 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 the channel, but you can change it after leaving the channel.

Parameter description

Name

Type

Description

profile

AliRtcChannelProfile

The channel type. For RTC scenarios, we recommend setting this to AliRtcChannelProfileInteractiveLive, which is the interactive stream profile.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAudioProfile

Sets the audio profile.

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

This method sets the audio encoding mode and audio scene mode. For more information, see Common audio operations and configurations. The ARTC SDK uses the high-quality mode (AliRtcEngineHighQualityMode) and music scene mode (AliRtcSceneMusicMode) by default. If the default settings do not meet your needs, call this method to configure them.

When to call

This method can only be called before joining a channel. It cannot be reconfigured after joining a channel, but it can be reconfigured after leaving the channel.

Parameter description

Name

Type

Description

audio_profile

AliRtcAudioProfile

The audio collection or encoding mode parameter. We recommend using the high-quality mode (AliRtcEngineHighQualityMode).

Note

To interoperate with the web, set the sample rate to 48k.

  • AliRtcEngineLowQualityMode: Low audio quality mode. Default sample rate is 8000 Hz, mono, with a maximum encoding bitrate of 12 kbps.

  • AliRtcEngineBasicQualityMode: Standard audio quality mode. Default sample rate is 16000 Hz, mono, with a maximum encoding bitrate of 24 kbps.

  • AliRtcEngineHighQualityMode: Default sample rate is 48000 Hz, mono, with a maximum encoding bitrate of 64 kbps.

  • AliRtcEngineStereoHighQualityMode: Stereo high-quality mode. Default sample rate is 48000 Hz, dual-channel, with a maximum encoding bitrate of 80 kbps.

  • AliRtcEngineSuperHighQualityMode: Super high-quality mode. Default sample rate is 48000 Hz, mono, with a maximum encoding bitrate of 96 kbps.

  • AliRtcEngineStereoSuperHighQualityMode: Stereo super high-quality mode. Default sample rate is 48000 Hz, dual-channel, with a maximum encoding bitrate of 128 kbps.

audio_scene

AliRtcAudioScenario

The audio scene mode parameter. It mainly includes:

  • AliRtcSceneMusicMode (recommended): Music scene. Uses software 3A and collects from the mobile phone for higher audio quality.

  • AliRtcSceneDefaultMode: Uses hardware 3A and can collect from Bluetooth devices.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

isAudioOnly

Checks whether the current mode is audio-only.

- (BOOL)isAudioOnly;

Return description

YES indicates audio-only mode. NO indicates audio and video mode.

setAudioOnlyMode

Sets the mode to audio-only or audio and video.

- (int)setAudioOnlyMode:(BOOL)audioOnly;

Parameter description

Name

Type

Description

audioOnly

BOOL

  • YES indicates only audio stream ingest and pulling.

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

Return description

0 indicates that the method call succeeded. Other values indicate failure.

joinChannel[1/3]

Joins a channel with a single parameter.

- (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 by 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], lets you join a channel. They differ in authentication method and user information passed:

  • This method is for single-parameter entry. Pass the token generated for single-parameter entry using Token-based authentication to join the channel. We recommend this method for RTC scenarios.

  • joinChannel[2/3] is for multi-parameter entry. It requires the token generated for multi-parameter entry using Token-based authentication, along with the user information used to generate the token.

  • joinChannel[3/3] is for AI real-time interaction scenarios. Pass a single-parameter entry token and set the user attribute capabilityProfile based on 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 own audio and video streams to remote users. If you want to disable 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 method to disable the subscription to audio or video streams.

When to call

Call this method after creating the engine.

Call restrictions

  • After successfully joining a channel, to join another channel, 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 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 calling this method again.

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

  • Applications with different App IDs cannot communicate with each other.

  • Do not call this method when retrying after a failed attempt to join a channel.

Related callbacks

After you successfully call this method, the following callbacks are triggered:

  • The result of the local user joining the channel will be 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 successfully joining the channel, the remote end will trigger the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#634626babfq9x" id="4b11b846b1f4t">onRemoteUserOnLineNotify</a> callback.

Parameter description

Parameter

Type

Description

token

String

The authentication information for single-parameter entry.

channelId

String

The channel to join. This must be the same as the value used to generate the token.

userId

String

The user ID for joining the channel. This must be the same as the value used to generate the token.

userName

String

The display name of the user, not the user ID.

onResultWithUserId

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

This callback is invoked after this method is executed.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

joinChannel[2/3]

Joins a channel with multiple parameters.

- (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 by 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], lets you join a channel. They differ in authentication method and user information passed:

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

  • This method is for multi-parameter entry. It requires the token generated for multi-parameter entry using Token-based authentication, along with the user information used to generate the token.

  • joinChannel[3/3] is for AI real-time interaction scenarios. Pass a single-parameter entry token and set the user attribute capabilityProfile based on 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. To cancel this 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 method to disable the subscription to audio or video streams.

  • This method joins a channel using multiple parameters. Before calling this method, refer to Token Authentication to generate a token for joining with multiple parameters.

Call restrictions

  • After successfully joining a channel, 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 the current channel before joining another one. You can call the join method again 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 only supports joining one channel at a time.

  • Apps with different App IDs cannot communicate with each other.

Related callbacks

After successfully calling this method, the following callbacks will be triggered:

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

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

Parameter description

Name

Type

Description

authInfo

AliRtcAuthInfo

Authentication information.

userName

String

The display name of the user (not the user ID).

onResultWithUserId

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

The callback that is invoked after the method finishes executing.

joinChannel[3/3]

You can join the 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, along with joinChannel[1/3] and joinChannel[2/3], lets you join a channel. ARTC organizes users into channels, and you must join a channel to publish or subscribe to audio and video streams. These methods differ in the authentication method and the user information that is passed, as follows:

  • joinChannel[1/3] is a single-parameter method for joining a channel in Real-Time Communication (RTC) scenarios. To use this method, pass the token generated by Token authentication. We recommend using this method for joining channels in RTC scenarios.

  • joinChannel[2/3] is a multi-parameter method for joining a channel. To use this method, pass the multi-parameter token generated by Token authentication and the user information that was used to generate the token.

  • This method is used for AI real-time interaction scenarios. To use this method, pass a single-parameter joining token and set the capabilityProfile user property according to the scenario. To communicate with an AI agent, set this property to AliRtcCapabilityProfileAiHuman.

Note

By default, when you join a channel, you subscribe to all audio and video streams of other users in the channel and publish your audio and video streams to remote users. To disable the default subscription to audio or video streams, you can 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 you call this method.

Call restrictions

  • After you successfully join a channel, you must 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 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 only supports joining one channel at a time.

  • Apps with different App IDs cannot communicate with each other.

  • Do not call this method again to retry a failed channel join.

Related Callbacks

A successful call to this method triggers the following callbacks:

  • The result of joining the channel is returned in 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, the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#634626babfq9x" id="aeef817be3a0b">onRemoteUserOnLineNotify</a> callback is triggered.

Description

Name

Type

Description

token

NSString*

The authentication information obtained from the app server.

channelParam

AliRtcChannelParam

The parameters for joining the channel.

onResultWithUserId

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

The callback that is invoked after this method is executed.

leaveChannel

You can leave the channel.

- (int)leaveChannel;

After calling this method, the SDK will terminate audio and video interaction and leave the current channel.

Note
  • This method is an asynchronous operation. A successful call does not mean that you have left the channel. You have only truly left the channel after the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="e7c0222bacrpa">onLeaveChannelResult</a> callback is received.

  • After the leaveChannel call completes, destroy the engine and set it to null.

Invocation Timing

  • Call this method to leave a channel.

  • If you are already in a channel, you must call this API to leave the current channel before joining another channel.

Related callbacks

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

  • Remote: After successfully calling this interface, remote users will receive 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 succeeded. A value other than 0 indicates failure.

isInCall

Checks whether you are in a channel.

- (BOOL)isInCall;

Return description

YES indicates that you are in the channel. NO indicates that you are not in the channel.

setClientRole

Sets 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 receives audio and video streams from other streamers by default.

  • Set the user role to viewer: The SDK does not publish local audio and video streams, but receives audio and video streams from other streamers.

When to call

This method can be called both before and after joining a channel. You can set the user role before joining a meeting, or call it after joining to switch user roles.

Call restrictions

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

In interactive mode, we recommend explicitly setting the user role before joining the meeting.

Parameter description

Name

Type

Description

role

AliRtcClientRole

The user role. The default value is AliRtcClientRolelive (viewer). This parameter is effective only in non-communication mode.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

getCurrentClientRole

Gets the user role (iOS only).

- (AliRtcClientRole)getCurrentClientRole;

Return description

Returns the current user role.

refreshAuthInfo

Refreshes the authentication information.

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

This method updates the authentication information. The token expires after a certain period, at which point the SDK can no longer connect to the server.

Note

This method and refreshAuthInfoWithToken both update authentication information. This method updates the token for multi-parameter channel joining, while refreshAuthInfoWithToken updates the token for single-parameter channel joining. For information about token generation, see Token-based authentication.

When to call

In the following situations:

  • 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 the authentication information is about to expire, we recommend that you regenerate the Token on your 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 notify you that the authentication has expired. In this case, you need to regenerate the Token and then call joinChannel to rejoin the channel.

Parameter description

Name

Type

Description

authInfo

AliRtcAuthInfo *_Nonnull

The authentication information.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

refreshAuthInfoWithToken

Refreshes the authentication information.

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

This method updates the token. The token expires after a certain period, at which point the SDK can no longer connect to the server.

Note
  • This interface and <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6a4495191bmd" id="eb171f6dc0n9p">refreshAuthInfo</a> both function to update authentication information. The difference is that this interface is used to update the Token for single-parameter channel joining, while refreshAuthInfo is used to update the Token for multi-parameter channel joining. For information about Token generation, see Token Authentication.

  • If the Token is not updated in time, the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#b04cd67880ptu" id="3fd3c64767aq8">onAuthInfoExpired</a> callback will be triggered to notify that the authentication has expired. In this case, you need to call joinChannel to rejoin the channel.

When to call

In the following situation, regenerate a token on your server and then call this method to pass in the new token:

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 the authentication information is about to expire.

Parameter description

Name

Type

Description

token

NSString *_Nonnull

The authentication information for single-parameter entry.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

publishLocalAudioStream

Specifies whether to publish the audio stream.

- (int)publishLocalAudioStream:(BOOL)enable;

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

When to call

You can call this method before or after joining a channel. When called before joining a channel, it modifies the default configuration, which takes effect when you join the channel.

Related callbacks

When the local audio publishing status 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 provide the latest audio publishing status, 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 notify that the remote user's audio and video streams have changed.

Parameter description

Name

Type

Description

enable

boolean

  • YES sends the local audio stream.

  • NO stops the stream ingest. The default is YES.

Return value

If the returned value is 0, the method call is successful. Otherwise, the method call failed.

isLocalAudioStreamPublished

Checks whether the local audio stream is published.

- (BOOL)isLocalAudioStreamPublished;

Return value

YES allows pushing. NO disallows pushing.

setDefaultSubscribeAllRemoteAudioStreams

Determines whether to subscribe to remote audio streams by default.

- (int)setDefaultSubscribeAllRemoteAudioStreams:(BOOL)sub;

This method configures the default subscription setting for remote audio streams. This setting affects the audio stream subscription behavior for new users who join the channel. We recommend setting this parameter to true unless you have specific requirements.

When to call

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

  • Before joining a channel:

    • By default, the SDK subscribes to the audio streams of remote users when joining a channel. To change this behavior, you can call this method before joining the channel.

  • After joining a channel:

    • 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) to stop automatically subscribing to the audio streams of users who subsequently join the channel.

    • After stopping the default subscription, you can call the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#c8249fb568gms" id="9806dd9a750pf">subscribeRemoteAudioStream</a> method to resume subscribing to a specific user's audio stream. To resume subscribing to multiple users, call this method 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) resumes the audio streams of only the users who subsequently join the channel. The SDK does not resume the audio streams of remote users who joined while the subscription was stopped.

Parameter descriptions

Name

Type

Description

sub

BOOL

  • YES receives the user's audio stream.

  • NO stops receiving the user's audio stream. The default value is YES.

Return description

A return value of 0 indicates a successful method call. Any other value indicates that the call failed.

subscribeRemoteAudioStream

Stops or resumes pulling the audio stream of a specific remote user.

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

This method stops or resumes subscribing to the audio stream of a specific remote user. We recommend setting this to true unless you have specific requirements.

Note

By default, the SDK subscribes to the audio streams of all remote users when you join a meeting. To disable this default behavior, 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 the meeting.

Parameter description

Name

Type

Description

uid

NSString *_Nonnull

The ID of the remote user.

sub

BOOL

  • YES receives the specified user's audio stream.

  • NO stops receiving the specified user's audio stream. The default value is YES.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

subscribeAllRemoteAudioStreams

Stops or resumes receiving all remote audio streams.

- (int)subscribeAllRemoteAudioStreams:(BOOL)sub;

This method is the master switch for subscribing to remote audio streams. We recommend setting it to YES. If set to NO, it will result in:

  • All remote audio in the current meeting will stop being subscribed to.

  • New users who join later will not be subscribed to.

  • 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 specific user.

To subscribe again, call this API again and set it to YES to resume the subscription.

Note

By default, the SDK subscribes to the audio streams of all remote users when you join a meeting. If you want to change 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 joining the meeting to cancel this default subscription.

Parameter description

Name

Type

Description

sub

BOOL

  • YES: Subscribes to the audio streams of all users.

  • NO: Unsubscribes from the audio streams of all users. The default value is YES.

Return description

A value of 0 indicates that the call succeeded. A value other than 0 indicates failure.

publishLocalVideoStream

Specifies whether to publish the camera stream.

- (int)publishLocalVideoStream:(BOOL)enable;

This method controls whether to publish the locally captured video stream.

Note

The SDK publishes the video stream by default. To disable video stream publishing, call publishLocalVideoStream(false) before joining the channel.

When to call

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

Calling this method before joining a channel modifies the default configuration, which takes effect when you join the channel.

Related callbacks

When the local video stream ingest status 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 status, and remote clients trigger 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 that a remote user's audio and video streams have changed.

Parameter description

Name

Type

Description

enable

boolean

  • YES sends the video.

  • NO stops sending. The default is YES.

isLocalVideoStreamPublished

Queries whether a video stream is allowed to be published.

- (BOOL)isLocalVideoStreamPublished;

Return description

YES indicates that the camera stream is published. NO indicates that the camera stream is not published.

setDefaultSubscribeAllRemoteVideoStreams

Specifies whether to subscribe to remote video streams by default.

- (int)setDefaultSubscribeAllRemoteVideoStreams:(BOOL)sub;

This method specifies whether to subscribe to video streams by default. The SDK subscribes by default.

Note

By default, the SDK subscribes to the audio and video streams of remote users when joining a channel. To modify this behavior, you can call this method before joining a channel.

When to call

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

  • Before joining a channel:

    • You can call this method to cancel the default subscription setting.

  • After joining a channel:

    • To stop the default subscription, you can call setDefaultSubscribeAllRemoteVideoStreams(false). This prevents subscription to the video streams of users who join the channel later.

    • After stopping the default subscription, to resume subscribing to a specific user's video stream, call the subscribeRemoteVideoStream method. To resume for multiple users, call this method multiple times.

    • After you stop the default subscription, calling setDefaultSubscribeAllRemoteVideoStreams(false) resumes only the audio streams of users who subsequently join the channel.

Parameter description

Name

Type

Description

sub

boolean

  • YES receives the user's video stream.

  • NO does not receive the user's video stream. The default value is YES.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

subscribeRemoteVideoStream

Stops or resumes subscribing to the video stream of a remote user.

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

Performs subscription and unsubscription operations for the video stream of a specified user.

Note

By default, the SDK subscribes to the video streams of all remote users when joining a channel. If you want to modify this behavior, you can 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 joining the channel to cancel this default configuration.

When to call

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

Parameter description

Name

Type

Description

uid

NSString *

The unique user ID assigned by the App server.

track

AliRtcVideoTrack

The video stream type.

sub

BOOL

Whether to subscribe.

subscribeAllRemoteVideoStreams

Stops or resumes receiving all remote video streams.

Note

This method is a global switch for subscribing to remote video streams. If you set this parameter to NO, you stop subscribing to the video streams of all remote users in the current channel and the video streams of users who join the channel later, even if you have called setDefaultSubscribeAllRemoteVideoStreams:YES.

- (int)subscribeAllRemoteVideoStreams:(BOOL)sub;

This method is a global switch for subscribing to remote video streams. If you set this parameter to false, the following occurs:

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

  • New users who join the meeting later will not be subscribed either (even if you have set <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="0464849a17dks">setDefaultSubscribeAllRemoteVideoStreams</a> to subscribe by default).

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

To resume subscription, call this method again and set it to true.

Note

By default, the SDK subscribes to the video streams of all remote users when you join a channel. 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 channel to disable this default setting.

Parameter description

Name

Type

Description

sub

BOOL

  • YES receives all users' video streams.

  • NO stops allowing all users' video streams to be received. The default value is YES.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

subscribeRemoteMediaStream[1/2]

Stops or resumes the media stream of a specific remote user.

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

This method combines the subscription to remote audio and video streams.

Related methods

Compared to subscribeRemoteMediaStream[2/2], this method uses two boolean parameters, subVideo and subAudio, to determine whether to subscribe to remote audio and video streams. The videoTrack parameter controls which video stream to pull.

Note: In this method, AliRtcVideoTrackNo of AliRtcVideoTrack is invalid and has no effect.

Parameter description

Parameter

Type

Description

uid

String

The ID of the remote user.

videoTrack

AliRtcVideoTrack

The video stream type.

subVideo

boolean

Stops or resumes pulling the video stream of a specific remote user. Valid values:

  • true (default): Resumes.

  • false: Stops.

subAudio

boolean

Stops or resumes pulling the audio stream of a specific remote user. Valid values:

  • true (default): Resumes.

  • false: Stops.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

subscribeRemoteMediaStream[2/2]

Stops or resumes the media stream of a specific remote user.

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

This method combines the subscription to remote audio and video streams.

Note

This method uses videoTrack and audioTrack to inform the SDK of the desired state in a single call.

Related methods

Compared to subscribeRemoteMediaStream[1/2], this method uses the videoTrack and audioTrack parameters to inform the SDK about the desired subscription state in a single call. For example:

  • To subscribe to both the camera stream and microphone stream, set videoTrack to AliRtcVideoTrackCamera and audioTrack to AliRtcAudioTrackMic when calling.

  • To unsubscribe from the camera stream but keep the microphone, set videoTrack to AliRtcVideoTrackNo and audioTrack to AliRtcAudioTrackMic when calling again.

  • To unsubscribe from both, set videoTrack to AliRtcVideoTrackNo and audioTrack to AliRtcAudioTrackNo when calling again.

  • To subscribe to both the camera stream and screen sharing stream simultaneously, set videoTrack to AliRtcVideoTrackBoth. The same applies to audio.

Parameter description

Parameter

Type

Description

uid

NSString *

The ID of the remote user.

videoTrack

AliRtcVideoTrack

The video stream type.

audioTrack

AliRtcAudioTrack

The audio stream type.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

subscribeRemoteDestChannelStream

Subscribes to the stream of a specific user across channels.

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

Parameter description

Parameter

Type

Description

channelId

String

The ID of the remote channel.

uid

String

The ID of the remote user.

track

AliRtcVideoTrack

The video stream to subscribe to.

sub_audio

boolean

Stops or resumes pulling the audio stream of a specific remote user. Valid values:

  • true (default): Resumes.

  • false: Stops.

sub

boolean

Stops or resumes subscribing to the stream of a specific user across channels.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

subscribeRemoteDestChannelAllStream

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

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

Parameter description

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 the remote channel user.

Return value

0 indicates success. Other values indicate failure.

setRemoteAudioVolume

Sets 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. If the user has not joined the channel, the setting fails.

Parameter description

Name

Type

Description

uid

NSString *

The unique user ID assigned by the App server.

volume

NSInteger

The playback volume. Valid values: 0 to 100. 0: muted; 100: original volume.

Return value

0 indicates success. Other values indicate failure.

muteLocalMic

Stops or resumes sending local audio data.

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

Muting means that the audio stream sends silent frames. The collection and encoding modules are still working.

When to call

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

Related callbacks

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

Parameter description

Name

Type

Description

mute

BOOL

  • YES indicates that the local audio sends empty frames.

  • NO indicates a return to normal. The default value is NO.

mode

AliRtcMuteLocalAudioMode

The mute mode. By default, all audio is muted.

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

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

  • AliRtcMuteOnlyMicAudioMode: Mutes only the microphone.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

muteRemoteAudioPlaying

Stops or resumes the playback of remote audio.

- (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 method is only used to stop or resume the playback of audio from a specified remote user. It does not affect stream pulling or decoding of the remote audio. If you want 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.

Parameter description

Name

Type

Description

uid

NSString *_Nonnull

The user ID.

mute

BOOL

  • YES stops playback.

  • NO resumes playback. The default value is NO.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

muteAllRemoteAudioPlaying

Stops or resumes the playback of all remote audio.

- (int)muteAllRemoteAudioPlaying:(BOOL)mute;

This method stops or resumes the playback of all remote audio.

Note

This method only stops playback. Stream pulling and decoding are not affected.

When to call

You can set this before or after joining a channel.

Parameter description

Name

Type

Description

mute

BOOL

  • YES stops playback.

  • NO resumes playback. The default value is NO.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

startAudioCapture[1/2]

Starts audio collection.

- (void)startAudioCapture;

This method controls the start of audio collection. Calling it before joining a meeting can enable audio collection in advance. If not set, the SDK automatically controls the audio collection device. After calling stopAudioCapture to stop audio collection, call this method to start it again.

When to call

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

Related methods

The startAudioCapture[2/2] method can control whether the audio collection device remains on after leaving a meeting through parameters.

Related callbacks

After calling this method to modify the local audio collection status, you can get status changes through the onLocalAudioStateChanged callback.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

startAudioCapture[2/2]

Starts audio collection.

- (void)startAudioCapture:(BOOL)keepAlive;

Turns off microphone collection when muted.

This method controls the start of audio collection. Calling it before joining a channel can enable audio collection in advance. If not set, the SDK automatically controls the audio collection device.

When to call

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

Related methods

Compared to startAudioCapture[1/2], this method lets you control whether the collection device remains on after leaving a channel through the keepAlive parameter.

Related callbacks

After calling this method to modify the local audio collection status, you can get the status change through the onLocalAudioStateChanged callback.

Parameter description

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

0 indicates that the method call succeeded. Other values indicate failure.

stopAudioCapture

Stops audio collection.

- (void)stopAudioCapture;

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

Related callbacks

After calling this method to modify the local audio collection status, you can get the status change through the onLocalAudioStateChanged callback.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

enableSpeakerphone

Sets the audio output to the earpiece or speaker (iOS only).

- (int)enableSpeakerphone:(BOOL)enable;

This method sets the current audio playback device after joining a meeting, allowing you to choose between the earpiece and speaker. If this feature is not set, the device configured by the default audio route is used for playback.

The priority of audio routing is defined within the SDK and automatically switches based on the current peripheral connection status. The priority is as follows: Wired headset > Bluetooth headset > User settings > Default settings. Therefore, when a peripheral is connected, calls to this method have no effect. For more details about audio routing settings, see Audio routing settings.

When to call

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

Related methods

<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#83be8cc066qqq" id="f8de149ef8so0">setDefaultAudioRoutetoSpeakerphone</a> is used to modify the default audio routing settings, while this interface is used to set the current routing device.

Parameter description

Name

Type

Description

enable

BOOL

  • YES indicates speaker mode.

  • NO indicates earpiece mode. The default is YES.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

isEnableSpeakerphone

Gets the current audio output device, either earpiece or speaker (iOS only).

- (BOOL)isEnableSpeakerphone;

Return description

YES indicates speaker mode. NO indicates earpiece mode.

enableAudioVolumeIndication

Sets the volume callback frequency and smoothing factor.

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

This method allows the SDK to regularly report volume-related information of the local streaming user and the remote user with the highest instantaneous volume to the application.

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 users streaming in the channel, the SDK triggers the following two callbacks at the specified time interval:

  • The audio volume of speakers is reported through the onAudioVolumeCallback callback, with a frequency determined by the interval parameter.

  • For voice activation, when an active user is detected, the speaker's UID is reported through the onActiveSpeaker callback.

Parameter description

Name

Type

Description

interval

NSInteger

The time interval in milliseconds. The minimum value is 10 ms. We recommend setting it to 300-500 ms. A value less than or equal to 0 disables volume and speaker prompts.

smooth

NSInteger

The smoothing factor. Valid values: [0, 9]. A larger value indicates a higher degree of smoothing, while a smaller value indicates a lower degree of smoothing but better real-time performance. We recommend setting this to 3.

reportVad

NSInteger

The speaker detection switch. Valid values:

  • 1: On. The onAudioVolumeCallback method is called back for the status of each speaker.

  • 0: Off.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

enableEarBack

Enables in-ear monitoring.

- (int)enableEarBack:(BOOL)enable;

This method enables or disables in-ear monitoring. We recommend enabling in-ear monitoring when wearing headphones (wired or Bluetooth) for better results.

When to call

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

Parameter description

Name

Type

Description

enable

BOOL

  • YES enables in-ear monitoring.

  • NO disables in-ear monitoring. The default value is NO.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setEarBackVolume

Sets the in-ear monitoring volume.

- (int)setEarBackVolume:(NSInteger)volume;

This method is used to set the volume for in-ear monitoring. It takes effect only after in-ear monitoring is enabled through <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.

Parameter description

Name

Type

Description

volume

NSInteger

Valid values: [0, 100]. Default: 100.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

startAudioPlayer

Starts audio playback.

- (void)startAudioPlayer;
Note

This method can start audio playback in advance. If not set, the SDK automatically starts audio playback after subscribing to an audio stream.

stopAudioPlayer

Stops audio playback.

- (void)stopAudioPlayer;
Note

This method can stop audio playback.

setPlayoutVolume

Sets the playback volume.

- (int)setPlayoutVolume:(NSInteger)volume;

Parameter description

Name

Type

Description

volume

Volume

Range: [0-400]. [0-100] is the original volume range, and [100-400] is for volume amplification.

Return value

0 indicates success. Other values indicate failure.

setRecordingVolume

Sets the recording volume.

- (int)setRecordingVolume:(NSInteger)volume;

Parameter description

Name

Type

Description

volume

NSInteger

Range: [0-400]. [0-100] is the original volume, and [100-400] is for volume amplification.

Return value

0 indicates success. Other values indicate failure.

playAudioFileTest

Plays an audio file.

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

Call this method before JoinChannel.

Parameter description

Parameter

Type

Description

filePath

NSString *_Nonnull

The playback file path.

Return value

0 indicates success. Other values indicate failure.

stopAudioFileTest

Stops playing an audio file.

- (int)stopAudioFileTest;
Note

Call this method before JoinChannel.

Return value

0 indicates success. Other values indicate failure.

startAudioCaptureTest

Starts audio collection device detection before a call.

- (void)startAudioCaptureTest;
Note

You can only call this method before joining a channel. Calling it after joining a channel will fail.

stopAudioCaptureTest

Stops audio collection device detection before a call.

- (void)stopAudioCaptureTest;
Note

You can only call this method before joining a channel. Calling it after joining will fail.

setDefaultAudioRoutetoSpeakerphone

Sets whether the default audio output is from the speaker. By default, audio comes from the speaker.

- (int)setDefaultAudioRouteToSpeakerphone:(BOOL)defaultToSpeakerphone;

This method sets the default audio routing device before joining a meeting. You can choose to output to the earpiece or speaker by default. The SDK defaults to the speaker. If you want to modify this default configuration, you can call this method before joining the meeting.

The priority of audio routing is predefined in the SDK and automatically switches based on the current peripheral connection status. The priority is as follows: Wired headset>Bluetooth headset>User settings>Default settings. Therefore, if no peripheral is connected and the route is not configured using <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#f7d0d8b64fzkz" id="30798b686b5qk">enableSpeakerphone</a>, the default settings are used.

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

Mobile devices generally have two audio routing devices: earpiece and speaker.

  • When audio is routed to the earpiece, the sound is quiet and can only be heard clearly when the ear is close, providing better privacy and is suitable for answering calls.

  • When audio is routed to the speaker, the sound is louder and can be heard clearly without holding the phone to your face, thus enabling a "hands-free" feature.

Related methods

This interface is used to modify the default audio routing settings, while the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#f7d0d8b64fzkz" id="6001aa98ebapw">enableSpeakerphone</a> interface is used to set the current routing device.

When to call

This can be called both before and after joining a meeting.

Parameter description

Name

Type

Description

defaultToSpeakerphone

BOOL

Whether to route audio to the speaker. YES for speaker, NO for earpiece.

Return value

0 indicates success. Other values indicate failure.

setAudioEffectVoiceChangerMode

Sets the voice changer mode.

- (int)setAudioEffectVoiceChangerMode:(AliRtcAudioEffectVoiceChangerMode)mode;

Parameter description

Name

Type

Description

mode

AliRtcAudioEffectVoiceChangerMode

The mode value. The default value is AliRtcSdk_AudioEffect_Voice_Changer_OFF.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAudioEffectPitchValue

Sets the pitch parameter.

- (int)setAudioEffectPitchValue:(double)value;

Parameter description

Name

Type

Description

value

double

Valid values: [0.5, 2.0]. The default value is 1.0, which means the pitch remains unchanged.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAudioEffectReverbMode

Sets the reverberation mode.

- (int)setAudioEffectReverbMode:(AliRtcAudioEffectReverbMode)mode;

Parameter description

Name

Type

Description

mode

AliRtcAudioEffectReverbMode

The reverberation mode. The default value is AliRtcAudioEffectReverb_Off.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAudioEffectReverbParamType

Sets the reverberation type and specific parameters.

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

Parameter description

Name

Type

Description

type

AliRtcAudioEffectReverbParamType

The reverberation mode.

value

float

The specific parameter value.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

addExternalAudioStream

Adds an external audio stream.

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

This method adds a new external audio stream. The following are the related 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> method to add an external audio stream and obtain the external audio stream ID.

  2. Call pushExternalAudioStream to input audio data into the created audio 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="16f621608d94x">removeExternalAudioStream</a> to remove the external audio stream.

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

Parameter description

Name

Type

Description

config

AliRtcExternalAudioStreamConfig

The configuration of the external audio stream.

Return description

A value greater than 0 indicates that the call succeeded and is the ID of the external audio stream. Other values indicate failure.

pushExternalAudioStream

Inputs external audio stream data.

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

This method inputs data into a specified audio stream. The following are the related steps:

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

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

  3. When the call ends, you must invoke <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 collection.

Parameter description

Name

Type

Description

streamId

int

The ID of the external audio stream.

audioFrame

AliRtcAudioFrame

The audio data.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setExternalAudioStream:publishVolume

Sets the volume of an external audio stream for stream ingest.

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

Parameter description

Name

Type

Description

streamId

int

The ID of the external audio stream.

publishVolume

int

The stream ingest volume.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

getExternalAudioStreamPublishVolume

Gets the volume of an external audio stream for stream ingest.

- (int)getExternalAudioStreamPublishVolume:(int)streamId;

Parameter description

Name

Type

Description

streamId

int

The ID of the external audio stream.

Return description

[0, 100]: The stream ingest volume. < 0: Failed.

setExternalAudioStream:playoutVolume

Sets the playback volume of an external audio stream.

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

Parameter description

Name

Type

Description

streamId

int

The ID of the external audio stream.

playoutVolume

int

The playback volume.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

getExternalAudioStreamPlayoutVolume

Gets the playback volume of an external audio stream.

- (int)getExternalAudioStreamPlayoutVolume:(int)streamId;

Parameter description

Name

Type

Description

streamId

int

The ID of the external audio stream.

Return description

[0, 100]: The playback volume. < 0: Failed.

removeExternalAudioStream

Deletes an external audio stream.

- (int)removeExternalAudioStream:(int)streamId;

This method removes the corresponding external audio stream based on the input streamId, corresponding to the addExternalAudioStream method.

When to call

If you want to use the custom audio input feature, you need to call the addExternalAudioStream method to add an audio stream and get the external audio stream ID, then call the pushExternalAudioStream method to input your audio data to the SDK. When you want to stop custom audio input, call this method to remove the corresponding external audio stream and clean up resources.

Parameter description

Name

Type

Description

streamId

int

The ID of the external audio stream.

Return value

0 indicates success. Other values indicate failure.

getAudioFileInfo

Gets audio file information.

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

This is an asynchronous method. You can get audio file information through {@link onAudioFileInfo:errorCode:}.

Parameter description

Name

Type

Description

filePath

NSString *

The file path.

startAudioAccompanyWithFile

Starts accompaniment mixing.

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

This is an asynchronous method. You can monitor the player status through {@link onAudioAccompanyStateChanged:errorCode:}.

Parameter description

Name

Type

Description

filePath

NSString *

The file path.

config

AliRtcAudioAccompanyConfig *

The configuration for the accompaniment.

Return value

0 indicates success. Other values indicate failure.

stopAudioAccompany

Stops accompaniment mixing.

- (int)stopAudioAccompany;

Return value

0 indicates success. Other values indicate failure.

setAudioAccompanyVolume

Sets the accompaniment volume.

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

This sets both the local playback volume and the stream ingest volume for the accompaniment.

Parameter description

Name

Type

Description

volume

NSInteger

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

Return value

0 indicates success. Other values indicate failure.

setAudioAccompanyPublishVolume

Sets the volume of the accompaniment file for stream ingest.

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

This sets the volume that is streamed out.

Parameter description

Name

Type

Description

volume

NSInteger

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

Return value

0 indicates success. Other values indicate failure.

getAudioAccompanyPublishVolume

Gets the volume of the accompaniment file for stream ingest.

- (int)getAudioAccompanyPublishVolume;

Return value

Values between [0, 100] indicate success. Other values indicate failure.

setAudioAccompanyPlayoutVolume

Sets the accompaniment volume for local playback.

- (int)setAudioAccompanyPlayoutVolume:(NSInteger)volume;

Parameter description

Name

Type

Description

volume

NSInteger

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

Return value

0 indicates success. Other values indicate failure.

getAudioAccompanyPlayoutVolume

Gets the volume of the accompaniment for local playback.

- (int)getAudioAccompanyPlayoutVolume;

Return value

Values between [0, 100] indicate success. Other values indicate failure.

pauseAudioAccompany

Pauses accompaniment mixing.

- (int)pauseAudioAccompany;

Return value

0 indicates success. Other values indicate failure.

resumeAudioAccompany

Resumes accompaniment mixing.

- (int)resumeAudioAccompany;

Return value

0 indicates success. Other values indicate failure.

getAudioAccompanyDuration

Gets the duration of the accompaniment file in milliseconds.

- (int)getAudioAccompanyDuration;

Return value

>=0: The duration of the accompaniment file in milliseconds. <0: Failed.

getAudioAccompanyCurrentPosition

Gets the current playback position of the accompaniment file in milliseconds.

- (int)getAudioAccompanyCurrentPosition;

Return value

>=0: The current playback position of the accompaniment file. <0: Failed.

setAudioAccompanyPosition

Sets the playback position of the accompaniment file.

- (int)setAudioAccompanyPosition:(int)pos;

Parameter description

Name

Type

Description

pos

int

The position of the progress bar in milliseconds.

Return value

0 indicates success. Other values indicate failure.

preloadAudioEffectWithSoundId

Preloads a sound effect file.

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

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

filePath

NSString *_Nonnull

The path of the sound effect file.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

unloadAudioEffectWithSoundId

Deletes a preloaded sound effect file.

- (int)unloadAudioEffectWithSoundId:(NSInteger)soundId;

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

playAudioEffectWithSoundId

Starts playing a sound effect.

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

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

filePath

NSString *_Nonnull

The path of the sound effect file.

cycles

NSInteger

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

publish

BOOL

Whether to publish.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

stopAudioEffectWithSoundId

Stops playing a sound effect.

- (int)stopAudioEffectWithSoundId:(NSInteger)soundId;

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

stopAllAudioEffects

Stops playing all sound effects.

- (int)stopAllAudioEffects;

Return description

0 indicates that the method call succeeded. Other values indicate failure.

pauseAudioEffectWithSoundId

Pauses a sound effect.

- (int)pauseAudioEffectWithSoundId:(NSInteger)soundId;

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

pauseAllAudioEffects

Pauses all sound effects.

- (int)pauseAllAudioEffects;

Return description

0 indicates that the method call succeeded. Other values indicate failure.

resumeAudioEffectWithSoundId

Resumes playing a sound effect.

- (int)resumeAudioEffectWithSoundId:(NSInteger)soundId;

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

resumeAllAudioEffects

Resumes playing all sound effects.

- (int)resumeAllAudioEffects;

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAudioEffectPublishVolumeWithSoundId

Sets the stream ingest volume of a sound effect.

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

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

volume

NSInteger

The mixing volume. Valid values: [0, 100]. Default value: 50.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

getAudioEffectPublishVolumeWithSoundId

Gets the stream ingest volume of a sound effect.

- (int)getAudioEffectPublishVolumeWithSoundId:(NSInteger)soundId;

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAllAudioEffectsPublishVolume

Sets the stream ingest volume of all mixed sound effects.

- (int)setAllAudioEffectsPublishVolume:(NSInteger)volume;

Parameter description

Name

Type

Description

volume

NSInteger

The mixing volume. Valid values: [0, 100]. Default value: 50.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAudioEffectPlayoutVolumeWithSoundId

Sets the local playback volume of a sound effect.

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

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

volume

NSInteger

The mixing volume. Valid values: [0, 100]. Default value: 50.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

getAudioEffectPlayoutVolumeWithSoundId

Gets the local playback volume of a sound effect.

- (int)getAudioEffectPlayoutVolumeWithSoundId:(NSInteger)soundId;

Parameter description

Name

Type

Description

soundId

NSInteger

The ID assigned by the user to the sound effect file.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setAllAudioEffectsPlayoutVolume

Sets the local playback volume of all sound effects.

- (int)setAllAudioEffectsPlayoutVolume:(NSInteger)volume;

Parameter description

Name

Type

Description

volume

NSInteger

The mixing volume. Valid values: [0, 100]. Default value: 50.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

startRecord

Starts recording a media file.

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

Parameter description

Parameter

Type

Description

recordType

AliRtcRecordType

The record type.

recordFormat

AliRtcRecordFormat

The recording format.

filePath

NSString *

The recording file name and path.

audioConfig

AliRtcRecordAudioConfig *

The audio configuration.

videoConfig

AliRtcRecordVideoConfig *

The video configuration.

Return description

TRUE indicates success. Other values indicate failure.

Note
  • When recording a video stream, call this method after the stream is successfully published (onVideoPublishStateChanged). This method records the locally encoded video stream and saves it to the local device.

  • When recording an audio stream, the recorded file is a mix of local and remote audio.

stopRecord

Stops recording a media file.

- (void)stopRecord 

Parameter description

None.

setLocalViewConfig

Sets the rendering window and drawing parameters for local preview.

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

This method sets the local preview view. Calling this method binds the display window (view) of the local video stream and sets the rendering mode, mirror mode, and rotation angle for the local user's view. It only affects the local user's preview display and does not affect the published video. To set the remote user interface view, call setRemoteViewConfig.

Note

When to call

This method can be called both before and after joining a channel.

Parameter description

Name

Type

Description

viewConfig

AliVideoCanvas

*_Nullable

The rendering parameters, including the rendering window and rendering method.

track

AliRtcVideoTrack

The type of the video track.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setCameraCapturerConfiguration

Sets the camera capture preferences.

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

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

When to call

You must set this before turning on the camera, for example, before the following operations:

  • startPreview (start preview)

  • joinChannel (join channel)

Parameter description

Name

Type

Description

config

AliRtcCameraCapturerConfiguration

* _Nonnull

The camera capture preferences. Default values:

  • preference: 0

  • cameraDirection: 0

  • fps: 0

  • cameraCaptureProfile: 0

  • disableVideoCaptureReverse: -1

  • enableCameraMacroFocus: -1

  • captureObserverOriginal: -1

  • nativeBufferObserver: -1

  • captureCallbackCvpixelbufferToRaw: -1

A value of -1 indicates using the SDK's internal default settings.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

enableLocalVideo

Disables or re-enables local video collection.

- (int)enableLocalVideo:(BOOL)enable;

This method controls the enabling and disabling of local video collection. When local video collection is disabled, both local preview and stream ingest will not have video data, but it does not affect receiving remote video. If you call this method to turn off local camera collection, both the local preview and remote stream will remain on the last frame.

Note

Local video collection is enabled by default in the SDK.

When to call

This method can be called both before and after joining a channel.

Related callbacks

  • After you successfully call this method, remote users are notified through the onUserVideoEnabled callback.

Parameter description

Name

Type

Description

enable

BOOL

YES indicates a return to normal. NO stops video collection. The default is YES.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

muteLocalCamera

Stops or resumes sending local video data.

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

When streaming, you can call this method to send black video frames. The local preview remains normal, and the collection, encoding, and sending modules continue to work, but the video content is black frames.

Note

This method only controls whether to send black frames on a specified video stream. Collection and data sending are not stopped. To disable collection, use the enableLocalVideo method. To stop video data sending, use the publishLocalVideoStream method.

Parameter description

Name

Type

Description

mute

BOOL

YES indicates that black frames are sent for video data. NO indicates a return to normal. The default value is NO.

track

AliRtcVideoTrack

The type of video track for which you want to change the publishing status.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setRemoteViewConfig

Sets the rendering window and drawing parameters for a remote video.

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

This method binds the display view for a specified video stream of a remote user and sets the rendering mode, mirror mode, rotation angle, and other parameters for displaying the remote user's view locally. It only affects the video image seen by the local user. To set the local preview view, 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 that you call this method when you receive the onRemoteTrackAvailableNotify callback, which indicates that the remote user's video is available.

Parameter description

Name

Type

Description

canvas

AliVideoCanvas

*_Nullable

The rendering parameters, including the rendering window and rendering method.

uid

NSString *_Nonnull

The user ID.

track

AliRtcVideoTrack

The type of video track to set.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

isCameraOn

Checks whether the camera is on.

- (BOOL)isCameraOn;

Return description

YES indicates that the camera is on. NO indicates that the camera is off.

setVideoEncoderConfiguration

Sets video encoding properties.

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

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

Note

All set parameters have corresponding range limitations. If a set parameter is outside the valid range, the SDK automatically adjusts it.

When to call

This method can be called both before and after joining a channel. If you only need to set the camera stream video encoding properties once per channel, we recommend calling this method before joining the channel.

Call restrictions

Both the mirrorMode parameter in this method and setVideoMirrorMode can set video stream mirroring. We recommend using only one method. Using multiple methods simultaneously can cause mirroring effects to stack, resulting in setting failures or errors.

Parameter description

Name

Type

Description

config

AliRtcVideoEncoderConfiguration

* _Nonnull

The predefined encoding properties. Default values:

  • dimensions: [640,480]

  • frameRate: 15

  • bitrate: 0

  • mirrorMode: 0

  • keyFrameInterval: The Group of Pictures (GOP) in milliseconds. The default is 0, which means it is controlled by the SDK.

  • forceStrictKeyFrameInterval: Whether to force the encoder to strictly generate keyframes according to the set keyframe interval. The default value is false.

  • orientationMode: 0

  • rotation: 0

  • codecType: AliRtcVideoCodecTypeDefault

  • encoderType:AliRtcVideoEncodeCodecTypeDefault

  • seiForceFrontIFrame: -1

  • enableDynamicEncode: -1

  • disableDipenseResolutionChange: -1

  • enableDowngrade: -1

  • enableH264BFrame: -1

  • enableHevcBFrame: -1

  • backgroundHardwareToSoftware: -1

A value of -1 indicates using the SDK's internal default settings.

setVideoDecoderConfiguration

Sets video decoding properties.

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

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

When to call

We recommend that you call this method before joining a channel.

Parameter description

Name

Type

Description

config

AliRtcVideoDecoderConfiguration

* _Nonnull

The predefined decoding properties. Default values:

  • codecType: AliRtcVideoCodecTypeDefault

  • enableDecoderBframe: -1

  • backgroundHardwareToSoftware: -1

A value of -1 indicates using the SDK's internal default settings.

switchCamera

Switches between the front and rear cameras. By default, the front camera is used (iOS only).

- (int)switchCamera;

This method controls the use of the front or rear camera. The front camera is used by default. You can dynamically switch cameras during application runtime based on the actual availability of cameras, without needing to restart the video stream or reconfigure the video source.

When to call

This method must be called after the camera has been successfully turned on.

Call restrictions

This method is available only on Android and iOS platforms.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

getCurrentCameraDirection

Gets the current camera direction. The front camera is used by default (iOS only).

- (AliRtcCameraDirection)getCurrentCameraDirection;

Return description

Returns the camera direction enumeration value.

startPreview

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

- (int)startPreview;

This method starts a local video preview and automatically turns on the camera. To stop the local preview, call the stopPreview method.

Note

leaveChannel automatically stops the local preview when leaving a channel. If you are not publishing a camera stream, the camera is automatically turned off.

When to call

  • Before calling this method, you need to set a view for local preview through setLocalViewConfig. Otherwise, you cannot preview, but stream ingest is not affected.

  • If needed, you can call this method before joining a channel to start the preview, which automatically turns on the camera.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

stopPreview

Stops a local preview.

- (int)stopPreview;

This method closes the local video preview and turns off the camera. After stopping the preview, the local end remains at the last frame, which does not affect stream ingest.

Note

leaveChannel automatically stops the local preview when leaving a channel. If you are not publishing a camera stream, the camera is automatically turned off.

When to call

Call this method to stop the preview after it has been started.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

setCameraZoom

Sets the camera zoom.

 - (int)setCameraZoom:(float)zoom;

Parameter description

Name

Type

Description

zoom

float

The zoom level, ranging from 1 to the maximum zoom value supported by the camera.

Return value

0 indicates success. Other values indicate failure.

GetCameraMaxZoomFactor

Gets the maximum zoom factor of the camera.

 - (float)GetCameraMaxZoomFactor;

Return value

The maximum zoom factor of the camera.

GetCurrentZoom

Gets the current zoom factor of the camera.

- (float)GetCurrentZoom;

Return value

Gets the current zoom factor of the camera.

SetExposure

Sets the camera exposure.

- (int)SetExposure:(float)exposure;

Parameter description

Name

Type

Description

exposure

float

The exposure.

Return value

0 indicates success. Other values indicate failure.

GetCurrentExposure

Gets the camera exposure.

- (float)GetCurrentExposure;

Return value

The camera exposure.

GetMinExposure

Gets the minimum camera exposure.

- (float)GetMinExposure;

Return value

The minimum camera exposure.

GetMaxExposure

Gets the maximum camera exposure.

- (float)GetMaxExposure;

Return value

The maximum camera exposure.

setCameraFlash

Sets the camera flash on or off.

- (int)setCameraFlash:(BOOL)flash;

Parameter description

Name

Type

Description

flash

BOOL

Whether to allow the flash to be turned on.

Return value

0 indicates success. Other values indicate failure.

isCameraFocusPointSupported

Queries whether the camera supports manual focus.

- (BOOL)isCameraFocusPointSupported;

Return value

TRUE indicates that manual focus is supported. FALSE indicates that manual focus is not supported.

isCameraExposurePointSupported

Queries whether the camera supports setting an exposure point.

- (BOOL)isCameraExposurePointSupported;

Return value

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

setCameraFocusPoint

Sets the manual focus point for the camera.

- (int)setCameraFocusPoint:(CGPoint)point;

Parameter description

Name

Type

Description

point

CGPoint

The focus point coordinate that is set and maintained.

Return value

0 indicates success. Other values indicate failure.

setCameraExposurePoint

Sets the exposure point and exposure value.

- (int)setCameraExposurePoint:(CGPoint)point;

Parameter description

Name

Type

Description

point

CGPoint

The set focus point coordinate is maintained continuously.

Return value

0 indicates success. Other values indicate failure.

isCameraAutoFocusFaceModeSupported

Queries whether the camera supports face-autofocus.

- (BOOL)isCameraAutoFocusFaceModeSupported;

Return value

TRUE indicates that face-autofocus is supported. FALSE indicates that face-autofocus is not supported.

setCameraAutoFocusFaceModeEnabled

Enables or disables face-autofocus for the camera.

- (BOOL)setCameraAutoFocusFaceModeEnabled:(BOOL)enable;

Parameter description

Name

Type

Description

point

CGPoint

The set focus point coordinate is maintained continuously.

Return value

TRUE indicates success. FALSE indicates failure.

setVideoMirrorMode

Sets the video mirror mode.

- (int)setVideoMirrorMode:(AliRtcVideoPipelineMirrorMode)mirrorMode;

Sets whether to enable mirror mode for local preview video and the published video stream.

Note

The priority of this method is higher than setLocalViewConfig and setVideoEncoderConfiguration. To set the video mirror mode, we recommend calling this method.

When to call

This method can be dynamically set both before and after joining a channel. The SDK internally records the state and operates on the video when it can manipulate the preview and encoding (stream ingest).

Call restrictions

This method overlaps with the mirrorMode in setLocalViewConfig and setVideoEncoderConfiguration. We recommend using only this method.

Parameter description

Name

Type

Description

mirrorMode

AliRtcVideoPipelineMirrorMode

The mirror type.

SetCapturePipelineScaleMode

Sets the video pipeline scaling mode.

-(void)setCapturePipelineScaleMode:(AliRtcCapturePipelineScaleMode)mode;

Sets whether video data scaling occurs immediately during capture or only during encoding. For example, when the capture resolution differs from the encoding resolution, you can decide whether preview data and streaming data are consistent by setting the timing of scaling.

Note

Controls the mode that determines when capture scaling occurs. By default, scaling is performed immediately during capture. This API must be set before the camera is turned on, before startPreview or joinChannel.

When to call

This method needs to be set before the camera is turned on, for example, before startPreview begins preview or joinChannel joins the channel.

Parameter description

Name

Type

Description

mode

AliRtcCapturePipelineScaleMode

The scaling type.

Return value

0 indicates success. Other values indicate failure.

registerVideoFrameWithObserver

Registers a video data output object.

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

This method registers an object that exports video data. To cancel the registration, call the unregisterVideoSampleWithObserver method.

When to call

To get raw video data, such as in YUV or RGBA format, you can call this method to register a video data monitor to get video data at various stages.

Related callbacks

After you successfully register a video data output monitor, the SDK triggers the callbacks that you implement when each video frame is captured. Implement the corresponding callbacks as needed:

Parameter description

Name

Type

Description

observer

AliRtcVideoFrameDelegate

The video data output object.

unregisterVideoSampleWithObserver

Deregisters a 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.

Parameter description

Name

Type

Description

observer

AliRtcVideoFrameDelegate

The video data output object.

registerLocalVideoTextureObserver

Registers an observer for local camera stream video OpenGL texture data.

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

If you want to get raw video data, call the registerVideoSampleObserver method to register the relevant callbacks. If you want to get internal texture data, call this method. To cancel the registration, call the unRegisterLocalVideoTextureObserver method.

Note
  • This method applies only to the video from the local camera stream.

  • After you register an observer for the OpenGL texture data from the local camera's video stream, the SDK triggers the onTextureCreate, onTextureUpdate, and onTextureDestroy callbacks whenever a video frame is captured. This interface only supports the local camera's video stream.

Related callbacks

After you successfully register an observer for local camera stream video OpenGL texture data, the SDK triggers the callbacks that you implement in the AliRtcTextureObserver interface when each video frame is captured. Implement the corresponding callbacks as needed:

  • onTextureCreate: This callback is triggered when the OpenGL context is created within the SDK.

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

  • onTextureDestroy: This callback is triggered when the OpenGL context within the SDK is destroyed.

Parameter description

Name

Type

Description

observer

AliRtcTextureDelegate

The OpenGL texture data observer.

unregisterLocalVideoTextureObserver

Deregisters an observer for local camera stream video OpenGL texture data.

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

This method corresponds to registerLocalVideoTextureObserver and is responsible for deregistration.

Parameter description

Name

Type

Description

observer

AliRtcTextureDelegate

The OpenGL texture data observer.

snapshotVideo

The video snapshot feature.

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

Parameter description

Name

Type

Description

userId

NSString *

The user ID. A null or empty userId represents the local user.

type

AliRtcVideoTrack

The video stream type. Only {@link AliRtcVideoTrack::AliRtcVideoTrackCamera} and {@link AliRtcVideoTrack::AliRtcVideoTrackScreen} are supported.

Return value

0 indicates success. Other values indicate failure.

setExternalVideoSource

Enables an external video input source.

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

Parameter description

Name

Type

Description

enable

BOOL

YES enables the source. NO disables it.

type

AliRtcVideoSource

The stream type.

renderMode

AliRtcRenderMode

The rendering mode.

pushExternalVideoFrame

Inputs video data.

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

Parameter description

Name

Type

Description

frame

AliRtcVideoDataSample

*_Nonnull

The frame data.

type

AliRtcVideoSource

The stream type.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

startPublishLiveStreamWithURL

Starts bypass live streaming.

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

Parameter description

Name

Type

Description

streamUrl

NSString *

The ingest URL.

transcoding

AliRtcLiveTranscodingParam

*

The parameters required for stream ingest.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

updatePublishLiveStreamWithURL

Updates parameters for bypass live streaming.

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

Parameter description

Name

Type

Description

streamUrl

NSString *

The ingest URL.

transcoding

AliRtcLiveTranscodingParam

*

The parameters required for stream ingest.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

stopPublishLiveStreamWithURL

Stops bypass live streaming.

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

Parameter description

Name

Type

Description

streamUrl

NSString *_Nonnull

The ingest URL.

Return description

0 indicates that the method call succeeded. Other values indicate failure.

GetPublishLiveStreamStateWithURL

Gets the status of bypass live streaming.

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

Parameter description

Parameter

Type

Description

streamURL

NSString *

The ingest URL.

Return description

Returns the status of bypass live streaming.

startLastmileDetect

Starts network quality probing.

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

Parameter description

Parameter

Type

Description

config

AliRtcNetworkQualityProbeConfig

The parameters for the probe configuration.

Return description

0 indicates success. Other values indicate failure.

stopLastmileDetect

Stops network quality probing.

- (int)stopLastmileDetect;

Return description

0 indicates success. Other values indicate failure.

sendMediaExtensionMsg

Sends SEI information.

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

The SDK provides the ability to send and receive media extension information. This method sends media extension information using the SEI extension protocol. The receiver can get the information by listening to the onMediaExtensionMsgReceived callback.

Common use cases include the following:

  • Using media extension information to transmit timestamps, calculate end-to-end network latency, or synchronize data with other business operations.

  • Using media extension information to transmit descriptions. You can transmit up to 4 KB of data, which is suitable for small amounts of data. We recommend using JSON or plain strings.

When to call

Call this method after starting stream ingest.

Call restrictions

Using media extension information requires reusing the audio and video data channels. Therefore, you must control the frequency and length of custom messages. The limits are as follows:

  • You can send a maximum of fps messages per second, as set in the profile, because SEI information is transmitted in the H.264/H.265 stream and requires video frame encoding to attach extension information.

  • To avoid affecting the transmission quality of media data, the custom message body is limited to 4 KB, which is suitable for small amounts of information.

  • The repeatCount parameter in the sendMediaExtensionMsg function represents the redundancy of custom messages. If it is greater than 1, the message is sent multiple times.

  • To prevent message loss due to network packet loss, other users in the room will also receive the same message multiple times and need to deduplicate them.

  • When you send custom messages, subscribers in the room will also receive them during bypass live streaming.

  • Only one MediaExtensionMsg can be transmitted at a time. If you call sendMediaExtensionMsg multiple times, the data from the new call overwrites the data from the previous call.

Related callbacks

After the stream publisher sends media extension information, the stream subscriber can get the information by listening to the onMediaExtensionMsgReceived callback.

Parameter description

Name

Type

Description

data

NSData *

The extension information content, limited to a maximum of 4 KB.

repeatCount

int

The number of repetitions, representing message redundancy to prevent message loss due to network packet loss. A value of -1 indicates infinite resending until sendMediaExtensionMsg is called again.

delay

int

The delay in milliseconds before sending. This is used to delay sending SEI. Since SEI is attached to the encoded H.264/H.265 stream, the actual delay will be slightly longer than the set delay.

isKeyFrame

bool

Whether to add SEI only to keyframes. If set to true, SEI information is only added to keyframes.

Return value

0 indicates success. Other values indicate failure.

sendMediaExtensionMsgEx

Sends media extension information. This is implemented using SEI at the underlying level.

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

The SDK provides the ability to send and receive media extension information. This method sends media extension information using the SEI extension protocol. The receiver can get the information by listening to onMediaExtensionMsgReceived. When payloadType is 5, it is equivalent to using the sendMediaExtensionMsg method.

Common use cases include the following:

  • Using media extension information to transmit timestamps, calculate end-to-end network latency, or synchronize data with other business operations.

  • Using SEI to transmit descriptions. You can transmit up to 4 KB of data, which can be used to transmit small amounts of data. We recommend using JSON or plain strings.

When to call

Call this method after starting stream ingest.

Call restrictions

Using media extension information requires reusing the audio and video data channels. Therefore, you must control the frequency and length of custom messages. The limits are as follows:

  • You can send a maximum of fps messages per second as set in the profile, because SEI information is transmitted in the H.264/H.265 stream, and video frame encoding is required to attach extension information.

  • To avoid affecting the transmission quality of media data, the custom message body is limited to 4 KB, which can be used to transmit small amounts of information.

  • The repeatCount parameter in the sendMediaExtensionMsg function is the redundancy of the custom message. If it is greater than 1, the message is sent multiple times.

  • To prevent message loss due to network packet loss, others in the room will also receive the same message multiple times, requiring deduplication.

  • For custom messages that are sent, subscribers in the room will also receive them during bypass live streaming.

  • Only one MediaExtensionMsg can be transmitted at a time. When sendMediaExtensionMsg is called multiple times, the data from the new call overwrites the data from the previous call.

Parameter description

Name

Type

Description

data

NSData *

The extension information content, limited to a maximum of 4 KB.

repeatCount

int

The number of repetitions, representing message redundancy, used to prevent message loss due to network packet loss. -1 indicates infinite retransmission unless sendMediaExtensionMsg is called again.

delay

int

The delay in milliseconds before sending. Used to delay sending SEI. Since SEI is attached to the H.264/H.265 stream after encoding, the actual delay will be slightly larger than the set delay.

isKeyFrame

bool

Whether to add SEI only to keyframes. When set to true, SEI information is only added to keyframes.

payloadType

int

The type. Use 5 for UUID-based types. The range is [5, 100-254].

Return description

  • 0: The call is successful.

  • <0: The call failed, and an error code is returned.

    • ERR_INNER(-1): Internal SDK error, possibly because the SDK is not initialized or the method is called after the SDK is destroyed.

onConnectionStatusChange

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

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

Parameter description

Parameter

Type

Description

status

AliRtcConnectionStatus

The current status value.

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;

Parameter description

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 the user's authentication information is about to expire. The authentication expires 30 seconds after you receive this callback. You need to get a new token and update the authentication information 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> method to update the 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.

When triggered

The SDK triggers this callback 30 seconds before the user authentication information expires. You should update the authentication information promptly after receiving this callback.

onAuthInfoExpired

The callback for expired authentication. The expiration information is returned by the server when users call a method that requires authentication.

- (void)onAuthInfoExpired;

This callback indicates that the user's authentication information has expired. If you want to continue in the meeting, you need to generate a new token on the server side, and then update the authentication information through 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 it.

When triggered

This callback is triggered when the user's authentication information expires.

onJoinChannelResult

The callback that is invoked to return the result of joining a channel. This callback is equivalent to the block operation of the joinChannel method, which handles events after joining a channel. You can choose either one.

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

Trigger condition

When the application calls the joinChannel method, this callback indicates a successful or failed channel join, and returns relevant information about the channel join along with the time consumed.

Parameter description

Parameter

Type

Description

result

int

The result of joining the channel. 0 indicates success. Otherwise, an error code is returned.

channel

NSString *_Nonnull

The ID of the channel that you join.

elapsed

int

The time consumed for joining the channel.

onLeaveChannelResult

The callback that is invoked to return the result of leaving a channel. This callback is returned after you call the leaveChannel method. If you call destroy immediately after calling leaveChannel, you will not receive this callback.

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

Parameter description

Parameter

Type

Description

result

int

The result of leaving the channel. 0 indicates success. Otherwise, an error code is returned.

stats

AliRtcStats

The statistics summary of the session in this channel.

onRemoteUserOffLineNotify

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

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

This callback notifies the local user that a remote user has left the channel for various reasons. This method is triggered when a remote user goes offline.

Trigger conditions

  • When a remote user actively leaves the channel, this callback is triggered.

  • This callback is triggered when a remote streamer calls <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).

  • When no data is received from a remote streamer for a long time and they are considered disconnected, this callback is triggered.

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The unique user ID assigned by the App server.

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 notifies the local client when a remote user joins the channel.

Trigger conditions

  • A remote user successfully joins the channel.

  • When the current user joins the channel, they receive join callbacks for users who are already in the channel, to display previously joined users.

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The unique user ID assigned by the App server.

elapsed

int

The 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 the streaming status of a remote user changes. Through this callback, developers can monitor in real time whether remote users are publishing audio and video streams, and display or hide the remote users' audio and video information on the interface accordingly.

Note

This callback returns the streaming status of remote users. To know which specific stream went offline in this change, record the status before and after the callback.

Trigger conditions

This callback is triggered in the following scenarios:

  • When a remote user changes from not streaming to streaming (including audio and video).

  • When a remote user changes from streaming to not streaming (including audio and video).

  • In interactive mode, when a remote user calls setClientRole to switch from viewer to streamer role and sets up streaming, this callback is triggered.

Taking video as an example, if a remote user sets not to stream, this callback is not triggered:

  • When a remote user starts publishing a camera stream (streaming status: not streaming video -> only streaming camera), the callback returns AliRtcVideoTrackCamera indicating that the remote user's camera stream is available.

  • When the remote user also publishes a screen sharing stream (streaming status: only camera stream -> both camera and screen sharing streams), the callback returns AliRtcVideoTrackBoth indicating that both the remote user's camera stream and screen sharing stream are available.

  • When the remote user stops publishing the camera stream and only keeps the screen sharing stream (streaming status: both camera and screen sharing streams -> only screen sharing stream), the callback returns AliRtcVideoTrackScreen indicating that only the screen sharing stream is currently available.

  • When the remote user also stops publishing the screen sharing stream (streaming status: only screen sharing stream -> not streaming video), the callback returns AliRtcVideoTrackNo indicating that no video stream is currently available.

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The unique user ID assigned by the App server.

audioTrack

AliRtcAudioTrack

The audio stream of the remote user after the change.

videoTrack

AliRtcVideoTrack

The video stream of the remote user after the change.

onBye

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

- (void)onBye:(int)code;

When a user is disconnected for some reason or the meeting ends, this callback is triggered. Developers can determine the reason for disconnection from the callback parameter code and take appropriate action.

Trigger conditions

  • The current user is kicked out by the server.

  • The meeting ends (the server actively removes the channel).

  • Passive departure, requiring the client to attempt to recover the session or reconnect.

Parameter description

Parameter

Type

Description

code

int

The 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 the stream ingest for an audio track changes.

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

This callback is used to monitor changes in the stream ingest status of the local user's audio track.

Trigger conditions

When the audio stream ingest status of the user changes, for example:

  • Stopping stream ingest.

  • Call <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 the viewer role.

Parameter description

Parameter

Type

Description

oldState

AliRtcPublishState

The previous stream ingest state.

newStat

AliRtcPublishState

The current stream ingest state.

elapseSinceLastState

NSInteger

The time elapsed since the last state change. Unit: milliseconds.

channel

NSString *_Nonnull

The current channel ID.

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 is triggered when the subscription state of a remote user's audio stream changes. It informs you of the new state and the time elapsed since the previous state.

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

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

oldState

AliRtcSubscribeState

The previous subscription status.

newState

AliRtcSubscribeState

The current subscription status.

elapseSinceLastState

NSInteger

The time elapsed since the last state change. Unit: milliseconds.

channel

NSString *_Nonnull

The ID of the current channel.

onUserAudioMuted

A notification is sent when a user mutes their audio.

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

Parameter description

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

A notification is sent when the user's audio is interrupted. A common scenario is when a phone call preempts the audio.

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

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user whose audio track is interrupted.

onUserAudioInterruptedEnded

A notification is sent when the user's audio interruption ends. It corresponds to onUserAudioInterruptedBegin.

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

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user whose audio track interruption ends.

onVideoPublishStateChanged

Callback for video stream ingest changes.

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

This callback reports changes to the video stream ingest status of the local user.

Parameter description

Parameter

Type

Description

oldState

AliRtcPublishState

The previous stream ingest state.

newState

AliRtcPublishState

The current stream ingest state.

elapseSinceLastState

NSInteger

The time elapsed since the last state change. Unit: milliseconds.

channel

NSString *_Nonnull

The current channel ID.

onVideoSubscribeStateChanged

A callback that indicates a change in the subscription status of a camera stream.

- (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 a change in the subscription status of a remote user's camera stream. The callback also provides the time elapsed since the previous state change.

Related callbacks

Video streams mainly include camera streams and screen sharing streams. This interface is for changes to the subscription status of camera streams. The related callback interface for screen sharing streams is onScreenShareSubscribeStateChanged.

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user whose subscription status changed.

oldState

AliRtcSubscribeState

The previous subscription status.

newState

AliRtcSubscribeState

The current subscription status.

elapseSinceLastState

NSInteger

The time interval since the last state change, in milliseconds.

channel

NSString *_Nonnull

The current channel ID.

onUserVideoMuted

Notification that a user has muted their video.

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

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who stops the video track.

isMute

BOOL

YES indicates that black frames are published. NO indicates that the stream is published normally.

onUserVideoEnabled

This notification is triggered when the local video capture is disabled or re-enabled.

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

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

The ID of the user who executes EnableLocalVideo.

isMute

BOOL

YES enables camera stream capturing. NO disables camera stream capturing.

onUserWillResignActive

Callback triggered when a remote user's application enters the background.

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

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

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

onUserWillBecomeActive

Callback invoked when a remote user's application returns to the foreground.

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

Parameter description

Parameter

Type

Description

uid

NSString *_Nonnull

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

onRtcStats

Real-time data callback (triggered every 2 s).

- (void)onRtcStats:(AliRtcStats)stats;

Parameter description

Parameter

Type

Description

stats

AliRtcStats

Data callback.

onRtcLocalVideoStats

Reports local video statistics (triggered every 2 seconds).

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

Parameter description

Parameter

Type

Description

localVideoStats

AliRtcLocalVideoStats

Local video performance statistics.

onRtcRemoteVideoStats

Remote video statistics information (triggered every 2 seconds).

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

Parameter description

Parameter

Type

Description

remoteVideoStats

AliRtcRemoteVideoStats

The performance statistics for the remote video track.

onRtcLocalAudioStats

Statistics information for local audio (triggered every 2 s).

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

Parameter description

Parameter

Type

Description

localAudioStats

AliRtcLocalAudioStats

Local audio statistics.

onRtcRemoteAudioStats

Remote audio performance statistics (triggered every 2 s).

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

Parameter description

Parameter

Type

Description

remoteAudioStats

AliRtcRemoteAudioStats

Remote audio performance statistics.

onMediaExtensionMsgReceived

A media extension information callback is received.

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

When one end sends information through sendMediaExtensionMsg, other ends receive the data through this callback.

Metric description

Parameter

Type

Description

uid

NSString

The user ID.

payloadType

int

The payload type.

message

NSData *

The media extension information.

onAudioRouteChanged

Callback for audio route changes (Android and iOS platforms only).

- (void)onAudioRouteChanged:(AliRtcAudioRouteType)routing;

Parameter description

Parameter

Type

Description

routing

AliRtcAudioRouteType

The route type.

onSnapshotComplete

Screenshot callback

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

Parameter description

Parameter

Type

Description

image

UIImage *

The type of the image.

success

BOOL

Indicates whether the operation was successful.

onLocalAudioStateChanged

Callback for the status of the local audio capture device.

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

The result callback for startAudioCapture and stopAudioCapture.

Parameters

Parameter

Type

Description

state

AliRtcLocalAudioStateType

The status of the device.

msg

NSString *

A description of the change in device status.

onLocalVideoStateChanged

Local video capture device status callback.

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

Parameter description

Parameter

Type

Description

state

AliRtcLocalVideoStateType

The status of the device. The type is `AliRtcLocalVideoStateType`.

msg

NSString *

The description of the device status change.

onRemoteUserSubscribedDataChannel

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. This callback notifies the local user that the specified remote user is ready to receive custom messages. Developers can safely call sendDataChannelMessage to send data to them at this time. This callback is a key mechanism to ensure reliable message delivery, avoiding packet loss or failure that could occur when sending messages to users who have not subscribed to the Data Channel.

Note

This callback is triggered only in AI scenarios.

Parameter description

Parameter

Type

Description

uid

NSString *

The user ID.

onDataChannelMessage

Data channel message callback.

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

The Alibaba Real-Time Communication (ARTC) SDK lets you send and receive custom messages. This lets you transmit custom real-time message data along with audio and video data. This callback receives custom messages from the data channel. For more information, see Send and receive custom messages.

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

  • This feature is disabled by default. To enable this feature, call setParameter after creating the DPI engine and set the parameter to {\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}}.

When this callback is triggered

A sender calls sendDataChannelMessage to send a custom message. If the receiver has the data channel feature enabled, the receiver's SDK triggers this callback.

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

controlMsg

AliRtcDataChannelMsg

The data channel message.

onScreenSharePublishStateChanged

The callback for a change in the stream ingest status for screen sharing.

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

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

Detection result, 0 indicates success, -1 indicates failure, poor network condition.

newState

AliRtcPublishState

The previous state of the stream ingest.

newState

AliRtcPublishState

The new stream ingest state.

elapseSinceLastState

NSInteger

The time interval between state changes, in milliseconds.

channel

NSString *

The current channel ID.

onCapturedAudioFrame

Callback for captured raw audio data.

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

This callback obtains the raw audio data captured by the current device. This callback is disabled by default. To obtain the audio data:

  • Enable this callback by setting the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). The config parameter lets you set the sample rate, number of sound channels, and read/write mode for the audio data.

  • Call registerAudioFrameObserver to register an audio data receiver object.

Note
  • You can set the sample rate, number of sound channels, and read/write mode.

  • Do not perform time-consuming operations in this callback function. This can cause audio issues.

  • You can set the sample rate and the number of sound channels.

  • You can set the read/write mode.

Limitations

Do not perform time-consuming operations in this callback function. This can cause audio issues.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Video frame

Return value

true: Success.

onProcessCapturedAudioFrame

A callback for audio data after 3A processing.

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

This callback returns audio data after 3A processing. The callback is disabled by default. To get this audio data:

  • Enable this callback using the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). Use the config parameter to set the sample rate, number of sound channels, and read/write mode for the audio data.

  • Call registerAudioFrameObserver to register an audio data receiver object.

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

  • Do not perform any time-consuming operations in this callback function. Otherwise, it may cause abnormal sound.

  • You can set the sample rate, number of sound channels, and read/write mode.

  • This interface supports read and write operations.

Call restrictions

Do not perform time-consuming operations in this callback function. Otherwise, audio issues may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Video frame

Return value

true: The operation is successful.

onPublishAudioFrame

Callback for stream ingest data.

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

This callback retrieves audio data for stream ingest. It is disabled by default. To retrieve this audio data:

  • Enable this callback using the audioSource parameter of enableAudioFrameObserver(true,audioSource,config). The config parameter lets you set parameters for the audio data, such as the sample rate, the number of sound channels, and the read/write mode.

  • Call registerAudioFrameObserver to register an audio data receiver object.

Note
  • This interface lets you set the sample rate and the number of sound channels, but can be set only to read-only mode.

  • Do not perform time-consuming operations in this callback function. Otherwise, audio issues may occur.

  • The interface lets you set the sample rate and the number of sound channels.

  • This interface supports read/write mode.

Call restrictions

Do not perform time-consuming operations in this callback function. Otherwise, audio issues may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Video frame

Return value

true: Success.

onPlaybackAudioFrame

Playback audio data callback.

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

This callback returns the audio data for playback. It is disabled by default. To get this audio data:

  • Enable this callback using the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). The config parameter sets the sample rate, number of sound channels, and read/write mode for the audio data.

  • Call registerAudioFrameObserver to register an object to receive audio data.

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

  • Do not perform any time-consuming operations in this callback function. This may cause audio issues.

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

  • This interface supports read and write operations.

Call restrictions

Do not perform time-consuming operations in this callback function. This can cause audio issues.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Video frame

Return value

true: Success.

onRemoteUserAudioFrame

Callback for remote audio stream data.

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

Use this callback to obtain the audio data of a specified remote user. This callback is disabled by default. To obtain the audio data:

  • Enable this callback using the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). You can also use the config parameter to set the sample rate, the number of sound channels, and the read/write mode.

  • Call registerAudioFrameObserver to register an audio data receiver object.

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

  • Do not perform time-consuming operations in this callback function. Otherwise, audio issues may occur.

  • The API does not support setting the sample rate or the number of sound channels.

  • This API supports the read/write mode.

Limitations

Do not perform time-consuming operations in this callback function. Otherwise, audio issues may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Video frame.

Returns

true: success

onDestroyCompletion

This callback confirms that the engine is released. The engine is not fully released until this callback completes.

- (void)onDestroyCompletion;

This callback indicates that the SDK engine instance is destroyed. You can create a new instance after this callback completes.

Note

To avoid blocking the main thread, wait for the onDestroyCompletion callback to complete before executing other methods.

When this is triggered

This callback is triggered after the destroy[2/2] method is called and the engine is destroyed.

onTextureCreate

OpenGL context creation callback.

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

This callback is triggered when the OpenGL context is created within the SDK.

Trigger conditions

This callback is triggered when the OpenGL context is created within the SDK. Use this callback to initialize related resources.

Parameter description

Parameter

Type

Description

context

void *

OpenGL context.

onTextureUpdate

Callback for OpenGL texture updates.

- (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. If an external OpenGL texture data observer is registered, you can process the texture in this callback and return the ID of the processed texture.

  • The return value of this callback must be a valid texture ID. If no processing is performed, return the textureId parameter.

Trigger conditions

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

Parameter description

Parameter

Type

Description

textureId

int

OpenGL context.

width

int

Video width.

height

int

Video height.

videoSample

AliRtcVideoDataSample

Video frame data.

Return value

Returns the new or original texture ID. A return value of less than 0 means the texture ID is not updated.

onTextureDestory

Callback for when the OpenGL context is destroyed.

- (void)onTextureDestory;
Note

This callback is triggered when the OpenGL context within the SDK is destroyed.

Trigger

This callback is triggered when the OpenGL context within the SDK is destroyed. Use this callback to clean up related resources.

onCaptureVideoSample

Video frame capture callback.

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

This callback provides the original video frames captured by the local camera, such as YUV data. Use this callback to implement custom video processing, such as adding filters, watermarks, or transcoding. You can then decide whether to return the processed data to the SDK for subsequent encoding or rendering. Return `true` to send the processed data to the SDK.

Trigger

After you successfully 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 type of the video stream.

videoSample

AliRtcVideoDataSample

Raw video data.

Return value

YES: The processed data is written back to the SDK. This is valid only for I420 and CVPixelBuffer (iOS/macOS).

NO: The processed data is not written back to the SDK.

onPreEncodeVideoSample

Callback for local video data from a subscribed stream, captured before encoding.

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

This callback provides the raw video data, such as data in YUV format, before the SDK encodes a video frame. Use this callback to apply custom processing, such as adding watermarks, adjusting colors, or transcoding. After processing, decide whether to return the modified data to the SDK for encoding.

Parameters

Parameter

Type

Description

videoSource

AliRtcVideoSource

The type of the video stream.

videoSample

AliRtcVideoDataSample

The raw video data.

Return value

YES: The data is written back to the SDK. This is valid only for data in I420 and CVPixelBuffer (iOS/macOS) formats.

NO: The data is not written back to the SDK.

onRemoteVideoSample

The callback for subscribed remote video data.

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

This callback provides the subscribed remote video data. Use this callback to get the raw video frame data, such as data in YUV format, from a remote user. You can use this callback to implement custom processing logic, such as adding filters, watermarks, or performing transcoding. You can also decide whether to return the processed data to the SDK for rendering.

Parameters

Parameter

Type

Description

uid

NSString *

The user ID.

videoSource

AliRtcVideoSource

The type of the video stream.

videoSample

AliRtcVideoDataSample

The raw video data.

Return value

YES: The data is written back to the SDK. This is valid only for I420 and CVPixelBuffer on iOS and macOS.

NO: The data is not written back to the SDK.

onGetVideoFormatPreference

The output format for video data.

- (AliRtcVideoFormat)onGetVideoFormatPreference;
Note

The application returns the desired output format for video data. The default format is AliRtcYUV420.

Return value

The desired video output format.

onGetVideoObservedFramePosition

The output position of the video data.

- (NSInteger)onGetVideoObservedFramePosition;

Return value

The expected video output. For more information, see {@link AliRtcVideoObserPosition}.

onAudioEffectFinished

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

- (void)onAudioEffectFinished:(int)soundId;

Parameter description

Parameter

Type

Description

soundId

int

The ID of the sound effect.

onAudioVolumeCallback

A callback that returns the audio volume, speech status, and UID of subscribed users.

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

This callback provides subscribed remote video data. Get original video frames from remote users, such as YUV data. Apply custom logic, such as filters, watermarks, or transcoding. Then, decide whether to send the processed data back to the SDK for rendering.

Parameters

Parameter

Type

Description

array

NSArray <AliRtcUserVolumeInfo

*> *_Nullable

An array that contains the volume information for users. This includes the user UID, speech status, and volume.

  • A UID of 0 indicates the local speaker.

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

  • Other values indicate the volume information of a specific remote user.

totalVolume

int

The total mixed volume. The value ranges from 0 to 255. In a callback for a local user, totalVolume is the mixed volume of the local user. In a callback for a remote user, totalVolume is the total mixed volume of all speakers.

onActiveSpeaker

Reports the user who is currently speaking.

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

After you successfully call <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 who has the highest volume and counts the number of times the user is detected as the loudest speaker. In the current time interval, the remote user with the highest accumulated count is the most active user.

Trigger conditions

The SDK triggers this callback when two or more users are in the channel and a remote user is active. The callback reports the uid of the most active remote user.

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

  • If the most active remote user changes, the SDK triggers this callback again and reports the uid of the new most active remote user.

Parameter description

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;

Parameter description

Parameter

Type

Description

streamURL

NSString *

The ingest URL.

state

AliRtcLiveTranscodingState

Status.

errCode

AliRtcTrascodingLiveStreamErrorCode

Error code.

onPublishTaskStateChanged

The callback for changes in the status of a relayed live streaming task.

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

Parameter description

Parameter

Type

Description

streamURL

NSString *

The ingest URL.

state

AliRtcTrascodingLiveTaskStatus

Status.

onNetworkQualityChanged

The network quality change callback.

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

Parameters

Parameter

Type

Description

uid

NSString*

The user ID. An empty value indicates the upstream and downstream network quality of the local user.

upQuality

AliRtcNetworkQuality

The upstream network quality.

downQuality

AliRtcNetworkQuality

The downstream network quality.

onLastmileDetectResultWithQuality

Callback for the last-mile network quality test.

- (void)onLastmileDetectResultWithQuality:(AliRtcNetworkQuality)networkQuality;

Parameter description

Parameter

Type

Description

networkQuality

AliRtcNetworkQuality

Network quality

onLastmileDetectResultWithBandWidth

The callback for the network quality probe result.

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

Parameter description

Parameter

Type

Description

code

int

The probe result. 0 indicates success. -1 indicates failure due to poor network conditions.

result

AliRtcNetworkQualityProbeResult

Network quality

onOccurError

This callback notifies the app when an error occurs in the engine.

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

Parameters

Parameter

Type

Description

error

int

The error type. For more information, see {@link AliRtcErrorCode}.

message

NSString *

The error description.

onFirstAudioPacketSentWithTimecost

Audio first packet sent callback

- (void)onFirstAudioPacketSentWithTimecost:(AliRtcAudioTrack)track timeCost:(int)timeCost;

Parameters

Parameter

Type

Description

track

AliRtcAudioTrack

The audio track.

timeCost

int

The time it took to send the packet.

onFirstVideoFrameReceivedWithUid

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

- (void)onFirstVideoFrameReceivedWithUid:(NSString *_Nonnull)uid
                      videoTrack:(AliRtcVideoTrack)videoTrack
                        timeCost:(int)timeCost;

Parameter description

Parameter

Type

Description

uid

NSString *

The user ID.

videoTrack

AliRtcVideoTrack

The video stream tag.

timeCost

int

Time consumed (milliseconds).

onFirstVideoPacketSentWithVideoTrack

The callback for when the first video packet is sent.

- (void)onFirstVideoPacketSentWithVideoTrack:(AliRtcVideoTrack)videoTrack
                                    timeCost:(int)timeCost;

Parameters

Parameter

Type

Description

videoTrack

AliRtcVideoTrack

The video stream tag.

timeCost

int

The time elapsed, in milliseconds.

onFirstAudioPacketReceivedWithUid

Occurs 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 track type.

timeCost

int

The time elapsed, in milliseconds.

onFirstRemoteAudioDecodedWithUid

A callback that is fired 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 tag.

elapsed

int

The time elapsed, in milliseconds.

onFirstRemoteVideoFrameDrawn

Called when the first video frame of a remote user is drawn.

- (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

An audio stream tag.

width

int

Width

height

int

Height

elapsed

int

The time elapsed, in milliseconds, from when the local user joins the channel until this callback is triggered.

onFirstLocalVideoFrameDrawn

This message is triggered when the preview begins displaying the first video frame.

- (void)onFirstLocalVideoFrameDrawn:(int)width height:(int)height elapsed:(int)elapsed;

Parameter description

Parameter

Type

Description

width

int

The width of the local preview video.

height

int

The height of the local preview video.

elapsed

int

The total time elapsed (in milliseconds) from when the local user joins the channel until this callback is triggered.

onTestAudioVolumeCallback

The volume callback for the pre-call audio capture test.

- (void)onTestAudioVolumeCallback:(int)volume;

Parameters

Parameter

Type

Description

volume

int

The audio volume. The value ranges from 0 to 100.

onAudioAccompanyStateChanged

Callback for the local audio accompaniment playback state.

- (void)onAudioAccompanyStateChanged:(AliRtcAudioAccompanyStateCode)playState
                           errorCode:(AliRtcAudioAccompanyErrorCode)errorCode;

Parameters

Parameter

Type

Description

playState

AliRtcAudioAccompanyStateCode

The accompaniment state.

errorCode

AliRtcAudioAccompanyErrorCode

The error code.

onRemoteAudioAccompanyStarted

Occurs when a remote user starts playing audio accompaniment.

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

Parameter description

Parameter

Type

Description

uid

NSString *

The user ID.

onRemoteAudioAccompanyFinished

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

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

Parameter description

Parameter

Type

Description

uid

NSString *

The ID of the user.

setParameter

Sets custom parameters.

- (int)setParameter:(NSString * _Nonnull)param;

Parameter description

Parameter

Type

Description

param

String

The custom parameter.

getParameter

Gets a custom parameter.

- (NSString * _Nonnull)getParameter:(NSString * _Nonnull)param;

Parameter description

Parameter

Type

Description

param

String

Custom parameter.

enableAudioFrameObserver

Sets the audio callback parameters.

- (int)enableAudioFrameObserver:(bool)enable audioSource: (AliRtcAudioSource)audioSource config:(AliRtcAudioFrameObserverConfig*_Nullable)config;

Call this method to enable or disable callbacks for specific types of audio data. Enabling callbacks lets you get raw and encoded audio data. By default, callbacks are disabled.

Note

When you enable audio data callbacks for a specific AliRtcAudioSource, you must also call the registerAudioFrameObserver method to pass the object that receives the audio data.

When to call

Call this method when you need to get audio data.

Parameters

Parameter

Type

Description

enable

bool

Specifies whether to enable data callbacks.

audioSource

AliRtcAudioSource

The type of the callback data source.

config

AliRtcAudioFrameObserverConfig

The callback parameters.

registerAudioFrameObserver

Register for audio data output.

- (int)registerAudioFrameObserver:(id<AliRtcAudioFrameDelegate> _Nullable)observer;

This method registers an object to receive audio callback data.

When to call

Call this method to register an object that receives audio data. After registration, the software development kit (SDK) triggers callbacks to provide different types of audio data. These callbacks include onCapturedAudioFrame, onProcessCapturedAudioFrame, onPublishAudioFrame, onPlaybackAudioFrame, and onRemoteUserAudioFrame. To cancel the registration, call this method again and pass nil.

Call restrictions

Call enableAudioFrameObserver to enable callbacks for a specific AliRtcAudioSource. Otherwise, the specified observer cannot receive data.

Parameter description

Parameter

Type

Description

observer

AliRtcAudioFrameDelegate

The audio data callback.

registerVideoSampleObserver

Registers the video data output.

- (void)registerVideoSampleObserver;

unRegisterVideoSampleObserver

Unregisters the video data output.

- (void)unregisterVideoSampleObserver;

setLogDirPath

Sets the path to store SDK log files.

Important

Call this method before any other SDK methods to prevent log loss. Ensure that the specified directory exists and is writable.

+ (int)setLogDirPath:(NSString *_Nullable)logDirPath;

Parameters

Name

Type

Description

logDirPath

NSString *_Nullable

The absolute path to store the SDK log files.

  • The default storage path for iOS is Library/Caches/Ali_RTC_Log.

  • The default storage path for macOS is /Users/xxx/Documents/Ali_RTC_Log.

Returns

A return value of 0 indicates a successful call. Any other value indicates a failed call.

setLogLevel

Sets the log level.

- (void)setLogLevel:(AliRtcLogLevel)logLevel;

Parameter description

Name

Type

Description

logLevel

AliRtcLogLevel

The log level. Default value: AliRtcLogLevelInfo.

setAudioSessionOperationRestriction

Sets the permission for the SDK to control AVAudioSession.

- (int)setAudioSessionOperationRestriction:(AliRtcAudioSessionOperationRestriction)restriction;

Parameters

Name

Type

Description

restriction

AliRtcAudioSessionOperationRestriction

The control permission of the SDK. Default value: AliRtcAudioSessionOperationRestrictionNone.

setDeviceOrientationMode

Sets the device orientation.

- (int)setDeviceOrientationMode:(AliRtcOrientationMode)mode;

Parameters

Name

Type

Description

mode

AliRtcOrientationMode

The device orientation.

Return value

0 indicates success. Other values indicate failure.

getNetworkTime

Gets the timeline time.

-(long long)getNetworkTime;

Return value

A UNIX timestamp.

sendDataChannelMessage

-(int) sendDataChannelMessage:(AliRtcDataChannelMsg* _Nonnull)controlMsg;

The Alibaba Real-Time Communication (ARTC) software development kit (SDK) lets you send and receive custom messages. You can send custom real-time message data while transmitting audio and video data. For example, call this method to send real-time control instructions, state synchronization data, or other business messages during audio and video transmission. For more information, see Send and receive custom messages.

Note
  • The custom message channel is disabled by default. To use this feature, call the setParameter method and set the parameter to `("{\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}}")` to enable the custom message channel. Enable the channel before or after you join.

  • Messages can be any type of data, such as text or images.

Related callbacks

  • The `onRemoteUserSubscribedDataChannel` callback is triggered when a remote user subscribes to the data channel. After you receive this callback, you can send data channel messages to the user.

  • After the sender enables the custom message channel, they can call this method to send custom messages. The receiver listens for the onDataChannelMessage callback to receive the custom messages.

When to call

Call this method after you receive the `onRemoteUserSubscribedDataChannel` callback. This callback indicates that a remote user called `setParameter` with `enableSubDataChannel` enabled to receive data channel messages.

Limitations

Streamers can send and receive messages. Viewers can only receive messages.

Call `setParameter` to enable the custom message channel.

Parameters

Name

Type

Description

controlMsg

AliRtcDataChannelMsg *

Control message for accompaniment.

Return value

0: Success. Other values: Failure.

startScreenShare

Starts sharing the screen and audio stream.

- (int)startScreenShare:(NSString * _Nonnull)appGroup
mode:(AliRtcScreenShareMode)mode;

Parameters

Name

Description

appGroup

The app package name. For example, @"group.com.aliyun.rtc.demo".

mode

The type of screen sharing. For more information, see AliRtcScreenShareMode.

Return value

Returns 0 on success. Returns a non-zero value on failure.

startScreenShare

Starts sharing the screen video stream.

Important

This method will be deprecated soon. Use the new startScreenShare method.

- (int)startScreenShare;

Returns

A value of 0 indicates that the call succeeded. A value other than 0 indicates failure.

stopScreenShare

Stops the screen sharing stream, including the audio stream.

- (int)stopScreenShare;

Return description

A value of 0 indicates that the call succeeded. A value other than 0 indicates failure.

isScreenSharePublished

Queries whether a screen-sharing stream is being ingested.

- (BOOL)isScreenSharePublished;

Returns

true: A screen-sharing stream is being ingested. false: A screen-sharing stream is not being ingested.

setScreenShareEncoderConfiguration

Sets the screen sharing encoder configuration.

- (void)setScreenShareEncoderConfiguration:(AliRtcScreenShareEncoderConfiguration* _Nonnull)config;
Note

Use this method to set the video parameters for the screen stream, such as resolution, frame rate, bitrate, and video orientation. All parameters have range limits. If a parameter is set outside its valid range, the software development kit (SDK) automatically adjusts it. You can call this method before or after joining a meeting. To set the screen stream video encoding properties only once for each meeting, call this method before you join.

Parameters

Name

Type

Description

config

AliRtcScreenShareEncoderConfiguration

The video encoding parameters for screen sharing, such as resolution, frame rate, bitrate, and video orientation.

setAudioShareAppVolume

Sets the volume of the shared audio stream.

- (int)setAudioShareAppVolume:(int)volume;

Parameter description

Name

Description

volume

The volume. Valid values: 0 to 100. Default value: 50.

Return description

A value of 0 indicates that the method call succeeded. Other values indicate failure.