This topic describes the APIs of the ApsaraVideo Real-time Communication SDK for iOS.
Table of contents
Basic APIs
API | Description |
Creates an AliRtcEngine instance (singleton pattern). | |
Destroys the AliRtcEngine instance (synchronous). | |
Destroys the AliRtcEngine instance (asynchronous). | |
Sets the H5 compatibility mode. | |
Checks whether the H5 compatibility mode is enabled. | |
Gets the SDK version number. |
Channel APIs
API | Description |
You can set the channel mode. | |
Sets the audio profile. | |
Checks whether the current mode is audio-only. | |
Sets the mode to audio-only or audio and video. | |
Joins a channel. | |
Joins a channel. | |
Joins a channel. | |
Leaves a channel. | |
Checks whether the user is in a channel. | |
Sets the user role. | |
Gets the user role. | |
Refreshes the authentication information. | |
Refreshes the authentication information. |
Publishing and subscription APIs
API | Description |
Sets whether to publish the local audio stream. By default, the audio stream is published. | |
Checks whether the local audio stream is being published. | |
Sets whether to subscribe to remote audio streams by default. By default, all remote audio streams are subscribed. Call this method before joining a channel. | |
Stops or resumes subscribing to the audio stream of a specific remote user. | |
Stops or resumes subscribing to all remote audio streams. | |
Sets whether to publish the local video stream. | |
Checks whether the local video stream is being published. | |
Sets whether to subscribe to remote video streams by default. By default, all remote video streams are subscribed. Call this method before joining a channel. | |
Stops or resumes subscribing to a remote user's video stream. | |
Stops or resumes subscribing to all remote video streams. | |
Stops or resumes subscribing to the media stream of a specific remote user. Use this method when both audio and video streams exist and need to be controlled. | |
Stops or resumes subscribing to the media stream of a specific remote user. Use this method when both audio and video streams exist and need to be controlled. | |
Stops or resumes subscribing to the media stream of a specific remote user in another channel. | |
Subscribes to the streams of all users in a target channel. | |
Sets the volume of a remote audio stream. |
Audio device management APIs
API | Description |
Sets whether to stop publishing the local audio stream. | |
Sets whether to stop playing remote audio streams. | |
Stops or resumes playing all remote audio streams. | |
Starts audio capture. | |
Starts audio capture. | |
Stops audio capture. | |
Sets the audio output to the earpiece or speaker. | |
Gets whether the current audio output is the earpiece or speaker. | |
Enables volume detection. | |
Enables in-ear monitoring. | |
Sets the in-ear monitoring volume (iOS only). | |
Starts audio playback. | |
Stops audio playback. | |
Sets the playback volume. | |
Sets the capture volume. | |
Starts testing the audio playback device. | |
Stops testing the audio playback device. | |
Starts testing the audio capture device. | |
Stops testing the audio capture device. | |
Sets the default output device. |
Voice changing and reverberation
API | Description |
Sets the voice changer effect mode. | |
Sets the pitch parameter. | |
Sets the reverberation effect mode. | |
Sets the reverberation effect type and specific parameters. | |
Sets the preset voice beautification effect mode. | |
Sets the audio equalizer (EQ) parameters to adjust the gain of a specified frequency band. |
Custom audio input
API | Description |
Adds an external audio stream. | |
Inputs external audio stream data. | |
Sets the publishing volume. | |
Gets the publishing volume. | |
Sets the playback volume of the external audio stream. | |
Gets the playback volume of the external audio stream. | |
Deletes an external stream. |
Audio accompaniment
API | Description |
Retrieve details of the audio accompaniment file. | |
Starts playing an audio mixing file. | |
Stops playing an audio mixing file. | |
You can set the accompaniment volume. | |
Sets the publishing volume of an audio mixing file. | |
Gets the publishing volume of an audio mixing file. | |
Sets the playback volume of an audio mixing file. | |
Gets the playback volume of an audio mixing file. | |
Pauses the playback of the backing track. | |
Resume playback of the accompaniment. | |
Gets the duration of an audio mixing file. | |
Gets the current playback position of an audio mixing file. | |
Set the playback position of the accompaniment. |
Sound effects
API | Description |
Preloads a sound effect file. | |
Deletes a preloaded sound effect file. | |
Starts playing a sound effect. | |
Stops playing a sound effect. | |
Stops playing all sound effects. | |
Pauses a sound effect. | |
Pauses all sound effects. | |
Resumes a specified sound effect file. | |
Resumes all sound effect files. | |
Sets the publishing mix volume of a sound effect. | |
Gets the publishing mix volume of a sound effect. | |
Sets the publishing mix volume for all sound effects. | |
Sets the local playback volume of a sound effect. | |
Gets the local playback volume of a sound effect. | |
Sets the local playback volume for all sound effects. |
Record audio and video files
API | Description |
Records audio and video files (AAC, WAV, MP4). | |
Stops recording audio and video files. |
Video device management APIs
API | Description |
Sets the rendering window and drawing parameters for the local preview. | |
Sets camera capture preferences. | |
Disables or re-enables local video capture. | |
Sets whether to stop publishing the local video stream. | |
Sets the rendering window and drawing parameters for a remote video stream. | |
Checks whether the camera is on. | |
Sets the video encoding properties. | |
Sets the video decoding properties. | |
Switches between the front and rear cameras (the front camera is used by default). | |
Gets the current camera direction. | |
Starts the local preview. | |
Stops the local preview. | |
Sets the camera zoom. | |
Gets the maximum camera zoom factor. | |
Gets the maximum camera zoom factor. | |
Sets the camera exposure. | |
Gets the camera exposure. | |
Gets the minimum camera exposure. | |
Gets the maximum camera exposure. | |
Turns the camera flash on or off. | |
Checks whether the camera supports manual focus. | |
Checks whether the camera supports setting an exposure point. | |
Sets the manual focus point for the camera. | |
Sets the camera exposure point. | |
Checks whether the camera supports face-based autofocus. | |
Sets face-based autofocus for the camera. | |
Sets the mirror mode for preview and publishing. | |
Sets the capture scaling timing, determining whether video data is scaled immediately upon capture or during encoding. |
Configure video data callbacks
API | Description |
Registers for video data callbacks. | |
Unregisters from video data callbacks. | |
Registers for video texture callbacks. | |
Unregisters from video texture callbacks. | |
Capture from a camera. | |
Registers for video data output callbacks. | |
Unregisters from video data output callbacks. |
Configure audio data callbacks
API | Description |
Sets audio callback parameters. | |
Registers for audio data callbacks. |
Custom video input
API | Description |
Enables an external video input source. | |
Inputs video data. |
Screen sharing APIs
API | Description |
Starts publishing the screen sharing stream. | |
Starts publishing the screen sharing stream. Note This API is about to be deprecated. | |
Stops publishing the screen sharing stream. | |
Sets the volume of the shared audio stream. | |
Checks whether screen sharing is being published. | |
Configures the screen sharing encoding parameters. |
Bypass streaming APIs
API | Description |
Starts bypass live streaming. | |
Updates bypass live streaming parameters. | |
Stops bypass live streaming. | |
Gets the bypass live streaming status. |
Network quality probing APIs
API | Description |
Starts network quality probing. | |
Stops network quality probing. |
SEI
API | Description |
Pushes an SEI stream. | |
Pushes an SEI stream (extended). |
Other APIs
API | Description |
Sets custom parameters. | |
Gets custom parameters. | |
Sets the path to save SDK log files. | |
Sets the log level. | |
Sets the SDK's control permissions for AVAudioSession. | |
Sets the device orientation. | |
Gets the network timestamp. | |
Sends a data channel message. |
AliveEnc APIs
API | Description |
Sets the global environment. |
Callbacks
AliRtcEngineDelegate
API | Description |
Callback for network connection status changes. Customers need to handle this callback. | |
Callback for local device exceptions. Customers need to handle this callback. | |
Notification that user authentication information is about to expire. Authentication will expire 30 seconds after this notification is received. Customers need to handle this callback. | |
The server returns that the authentication information has expired when a user calls an API that requires authentication. | |
Callback for the result of joining a channel. | |
Callback for the result of leaving a channel. | |
Notification that a remote user has gone offline. | |
Notification that a remote user has come online. | |
Notification about remote stream publishing information. | |
Message indicating that the user was kicked from the server or the channel has ended. | |
Notification of audio publishing state changes. | |
Notification of audio subscription state changes. | |
Notification that a remote user has been muted. | |
Notification that an audio device interruption has started. | |
Notification that an audio device interruption has ended. | |
Callback for video publishing state changes. | |
Callback for camera stream subscription state changes. | |
Notification that a remote user is sending black video frames. | |
Notification that a remote user has disabled camera stream capture. | |
A remote user's application has moved to the background. | |
A remote user's application has returned to the foreground. | |
Callback for when local sound effect playback finishes. | |
The audio volume, voice status, and UID of the subscribed audio. | |
Voice activity detection callback when an active user is detected. | |
Callback for bypass stream publishing state changes. | |
Callback for bypass task state changes. | |
Callback for network quality changes. | |
Callback for network quality probing. | |
Callback for network quality probing results. | |
If an error occurs in the engine, this callback notifies the application. | |
Callback for the first audio packet sent. | |
Callback for the first video frame received. | |
Callback for the first video packet sent. | |
Callback for the first audio packet received. | |
Callback for the first decoded remote audio frame. | |
This message is triggered when the first video frame of a remote user is displayed. | |
This message is triggered when the first video frame starts to display in the preview. | |
Volume callback for pre-call audio capture detection. | |
Callback for local audio mixing playback state. | |
Callback for when a remote user starts audio mixing playback. | |
Callback for when a remote user finishes audio mixing playback. | |
Real-time data callback (triggered every 2 seconds). | |
Local video statistics (triggered every 2 seconds). | |
Remote video statistics (triggered every 2 seconds). | |
Local audio statistics (triggered every 2 seconds). | |
Remote audio statistics (triggered every 2 seconds). | |
Callback for receiving media extension messages. | |
Callback for audio route changes. | |
Snapshot callback. | |
Callback for local audio capture device state. | |
Callback for local video capture device state. | |
Callback indicating that data channel messages can be sent. | |
Data channel message callback. | |
Callback for screen sharing publishing state changes. |
AliRtcAudioFrameDelegate
API | Description |
Callback for captured raw data. | |
Callback for data after 3A processing. | |
Callback for published stream data. | |
Callback for playback data. | |
Callback for remote stream pulling data. |
AliRtcEngineDestroyDelegate
API | Description |
Callback for when the engine is released. The engine is considered released only after this callback is executed. |
AliRtcTextureDelegate
API | Description |
Callback for OpenGL context creation. | |
Callback for OpenGL texture updates. | |
Callback for OpenGL context destruction. |
AliRtcVideoFrameDelegate
API | Description |
Callback for captured video frames. | |
Callback for local video data before encoding. | |
Callback for subscribed remote video data. | |
Video data output format. | |
Video data output position. |
API details
sharedInstance
Creates a singleton AliRtcEngine instance.
+ (instancetype _Nonnull )sharedInstance:(id<AliRtcEngineDelegate>_Nullable)delegate extras:(NSString *_Nullable)extras;When to call
Call this method to create an AliRtcEngine instance before you call any other ApsaraVideo Real-time Communication (ARTC) SDK APIs.
Limits
This is a synchronous method and must be called from the main thread.
The SDK supports only one AliRtcEngine instance for each application.
Related callbacks
When you create an engine instance, you can implement the callbacks in AliRtcEngineDelegate based on your business scenario. If the SDK encounters an exception during operation, it first attempts to recover automatically using its internal retry mechanism. For errors that it cannot resolve on its own, the SDK notifies your application through predefined callback interfaces. The following are key callbacks that the application layer must listen for and respond to because the SDK cannot handle them:
Cause | 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 correct. | If authentication fails when a user actively calls an API, the system returns an authentication failure error message in the API's callback. |
Network connectivity issue | The onConnectionStatusChange callback returns AliRtcConnectionStatusFailed. | If this exception occurs, the application must rejoin the channel. | The SDK can automatically recover from network disconnections for a certain period. However, if the disconnection time exceeds the preset threshold, a timeout occurs and the connection is dropped. In this case, the application should check the network status and guide the user to rejoin the session. |
Local device exception | onLocalDeviceException | If this exception occurs, the application must check whether permissions and device hardware are normal. | The RTC service supports device detection and exception diagnosis. When a local device exception occurs, the RTC service notifies the customer through a callback. If the SDK cannot resolve the issue on its own, the application must intervene to check if the device is functioning correctly. |
Kicked offline | onBye |
| The RTC 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 it. | Authentication expiration errors can occur in two situations: when a user calls an API or during program execution. Therefore, the error feedback is provided through either an API callback or a separate error callback. |
Authentication expired | onAuthInfoExpired | If this exception occurs, the application must rejoin the channel. | Authentication expiration errors can occur in two situations: when a user calls an API or during program execution. Therefore, the error feedback is provided through either an API callback or a separate error callback. |
Parameters
Name | Type | Description |
delegate | id<AliRtcEngineDelegate>_Nullable | The delegate for listening to callbacks. |
extras | NSString *_Nullable | Used to receive parameters for grayscale features. Configure special SDK features using JSON Configurations. This can be an empty string. |
destroy[1/2]
Destroys the AliRtcEngine instance.
+ (void)destroy;This method destroys the AliRtcEngine singleton object. After you call this method, all internal resources are released, and you can no longer use other AliRtcEngine methods or 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.
If you want to create an AliRtcEngine instance again after destroying it, make sure this method has finished executing before you create the new instance.
After you call this method, you must set the engine object to null.
When to call
After a real-time communication session ends and you no longer need to use AliRtcEngine features, you can call this method to release the instance and reduce resource usage.
Limits
To avoid deadlocks, do not call this method in any SDK callbacks.
destroy[2/2]
Destroys the AliRtcEngine instance.
+ (void)destroy:(id<AliRtcEngineDestroyDelegate>_Nullable)delegate;This method destroys the AliRtcEngine singleton object and releases all internal resources. After you call this method, you can no longer use any other AliRtcEngine methods or 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="115fd691743nx">sharedInstance</a> to create a new instance.
Both this method and destroy[1/2] can release the AliRtcEngine instance. The difference is that this method is an asynchronous call. It lets you pass an observer so that developers can monitor when the destruction is complete. You can create a new instance only after the onDestroyCompletion callback is returned.
When to call
You can call this method to release the instance after a real-time communication session ends.
Limits
To avoid deadlocks, do not call this method in any SDK callbacks.
Parameters
Name | Type | Description |
delegate | The callback object for when the release is complete. |
setH5CompatibleMode
Sets whether to enable HTML5 (H5) compatibility.
The current version does not support changing the H5 compatibility mode after an AliRtcEngine instance is created. You must call this method before you create the instance.
+ (void)setH5CompatibleMode:(BOOL)comp;Parameters
Name | Type | Description |
comp | BOOL | YES indicates H5 compatibility. NO indicates no H5 compatibility. The default value is NO. |
getH5CompatibleMode
Checks whether H5 compatibility mode is enabled.
+ (BOOL)getH5CompatibleMode;Return value
YES indicates that H5 compatibility is enabled. NO indicates that H5 compatibility is not enabled.
getSdkVersion
Retrieves the SDK version number.
+ (NSString *_Nonnull)getSdkVersion;Return value
The current SDK version number as a string, for example, `2.5.0.x`.
Description
This is a static method. You can retrieve the version number at any time.
setChannelProfile
Configure the channel mode.
- (int)setChannelProfile:(AliRtcChannelProfile)profile;This method sets the channel profile. The SDK provides profiles for video calls and interactive streaming:
Video call profile: All users are streamers and can publish and subscribe to streams.
Interactive stream mode: 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 user role. Users who ingest streams in the channel must be set to the streamer role (AliRTCSdkInteractive), while users who only pull streams must be set to the viewer role (AliRTCSdkLive). This mode is recommended for Real-Time Communication (RTC) scenarios.
The interactive streaming profile (
AliRTCSdkInteractiveLive) is recommended for all RTC scenarios.All users in the same channel must use the same channel profile.
When to call
This method can only be called before you join a channel. It cannot be reset during a session. You can set it again after you leave the channel.
Parameters
Name | Type | Description |
profile | The channel profile. For all RTC scenarios, set this to AliRtcChannelProfileInteractiveLive, which is the interactive streaming profile. |
Returns
0 indicates that the method call was successful. A non-zero value indicates 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 scenario. For more information, see Common audio operations and configurations. By default, the ARTC SDK uses the high-quality mode (AliRtcEngineHighQualityMode) and the music scenario (AliRtcSceneMusicMode). If the default settings do not meet your needs, you can call this method to configure the audio profile.
When to call
This method can only be called before you join a channel. It cannot be reset after you join. You can set it again after you leave the channel.
Parameters
Name | Type | Description |
audio_profile | The audio capture or encoding mode parameter. The high-quality mode (AliRtcEngineHighQualityMode) is recommended. Note To interoperate with a web client, set the sample rate to 48 kHz.
| |
audio_scene | The audio scenario parameter. It includes:
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
isAudioOnly
Checks whether the current mode is audio-only.
- (BOOL)isAudioOnly;Response 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;Parameters
Name | Type | Description |
audioOnly | BOOL |
|
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
joinChannel[1/3]
Joins a channel (single-parameter authentication).
- (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 allows a user to join a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[2/3], and joinChannel[3/3] can all be used to join a channel. They differ in their authentication methods and the user information they pass.
This method uses single-parameter authentication. You must pass a token that is generated for single-parameter authentication to join a channel. For more information, see Token-based authentication. This method is recommended for RTC scenarios.
joinChannel[2/3]uses multi-parameter authentication. You must pass a token that is generated for multi-parameter authentication and the corresponding user information that is used to generate the token. For more information, see Token-based authentication.joinChannel[3/3]is used for AI real-time interaction scenarios. You must pass a single-parameter authentication token and set the user propertycapabilityProfilebased on the scenario.
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 cancel this default subscription, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="2e9165006d7tz">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="96cf16cf8a4us">setDefaultSubscribeAllRemoteVideoStreams</a> before you call this API to disable the subscription to audio or video streams.
When to call
You can call this method after you create the engine instance.
Limits
After you join a channel, to switch to 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. 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="50039f328fdk7">onLeaveChannelResult</a>callback.This method supports joining only one channel at a time.
Applications with different App IDs cannot interoperate.
Do not call this method to retry joining a channel if the initial attempt fails.
Related callbacks
Calling this method successfully triggers the following callbacks:
The
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6d2a213d7sl2" id="903005c54be4d">onJoinChannelResult</a>callback returns the result of the local user joining the channel.After you successfully join a channel, the
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#634626babfq9x" id="4b11b846b1f4t">onRemoteUserOnLineNotify</a>callback is triggered on the remote client.
Parameters
Parameter | Type | Description |
token | String | The authentication information for single-parameter authentication. |
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 user's display name (not the user ID). |
onResultWithUserId | void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed) | This callback is invoked when the method execution is complete. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
joinChannel[2/3]
Join a channel for a multi-party call.
- (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 allows a user to join a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[1/3], and joinChannel[3/3] can all be used to join a channel. They differ in their authentication methods and the user information they pass.
joinChannel[1/3]uses single-parameter authentication. You must pass a token that is generated for single-parameter authentication to join a channel. For more information, see Token-based authentication. This method is recommended for RTC scenarios.This method uses multi-parameter authentication. You must pass a token that is generated for multi-parameter authentication and the corresponding user information that is used to generate the token. For more information, see Token-based authentication.
joinChannel[3/3]is used for AI real-time interaction scenarios. You must pass a single-parameter authentication token and set the user propertycapabilityProfile.
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 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="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 you call this method.This method uses multi-parameter authentication. Before you call it, you must generate a token for multi-parameter authentication. For more information, see Token-based authentication.
Limits
After you successfully join a channel, to switch to 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="4283c6cc013bz">leaveChannel</a>to leave the current one. You can join the new channel only after you receive the<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="9e6478b2f0hen">onLeaveChannelResult</a>callback.This method supports joining only one channel at a time.
Applications with different App IDs cannot interoperate.
Related callbacks
Calling this method successfully triggers the following callbacks:
The
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6d2a213d7sl2" id="df00346ea8928">onJoinChannelResult</a>callback notifies you of the result of the local user joining a channel.After you successfully join a channel, the
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#634626babfq9x" id="c3832e71e8vck">onRemoteUserOnLineNotify</a>callback is triggered on the remote client.
Parameters
Name | Type | Description |
authInfo | Authentication information. | |
userName | String | The user's display name (not the user ID). |
onResultWithUserId | void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed) | This callback is invoked when the method execution is complete. |
joinChannel[3/3]
Joins a channel.
- (int)joinChannel:(NSString *_Nonnull)token channelParam:(AliRtcChannelParam *_Nonnull)channelParam onResultWithUserId:(void(^_Nullable)(NSInteger errCode, NSString * _Nonnull channel, NSString * _Nonnull userId, NSInteger elapsed))onResult;This method allows a user to join a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[1/3], and joinChannel[2/3] can all be used to join a channel. They differ in their authentication methods and the user information they pass.
joinChannel[1/3]is a single-parameter authentication method for RTC scenarios. You must pass a token that is generated for single-parameter authentication to join a channel. For more information, see Token-based authentication. This method is recommended for RTC scenarios.joinChannel[2/3]uses multi-parameter authentication. You must pass a token that is generated for multi-parameter authentication and the corresponding user information that is used to generate the token. For more information, see Token-based authentication.This method is used for AI real-time interaction scenarios. You must pass a single-parameter authentication token and set the user property
capabilityProfile. To communicate with an AI agent, set it toAliRtcCapabilityProfileAiHuman.
By default, when you join a channel, you subscribe to the audio and video streams of all other users in the channel and push your audio and video streams to remote users. If you want to 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="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 to disable the subscription to audio or video streams.
Limits
After you successfully join 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="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 a new channel.This method supports joining only one channel at a time.
Applications with different App IDs cannot interoperate.
Do not call this method to retry joining a channel if the initial attempt fails.
Related callbacks
Calling this method successfully triggers the following callbacks:
The
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6d2a213d7sl2" id="f83d0aff9btwh">onJoinChannelResult</a>callback notifies you of the result of joining a channel.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 for remote users.
Parameters
Name | Type | Description |
token | NSString* | Authentication information obtained from your App Server. |
channelParam | Parameters for joining the channel. | |
onResultWithUserId | void(^_Nullable)(NSInteger errCode,NSString * _Nonnull channel,NSInteger elapsed) | This callback is invoked when the method execution is complete. |
leaveChannel
Leaves the current channel.
- (int)leaveChannel;When you call this method, the SDK terminates the real-time communication session and leaves the current channel.
This method is an asynchronous operation. Even if the method call is successful, you do not leave the channel until 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 leaveChannel completes, you must destroy the engine and set the engine object to null.
When to call
You can call this method when you need to leave a channel that you have joined.
If you are in a channel and need to join another one, you must call this method first to leave the current channel.
Related callbacks
Local client: Calling this method triggers the
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3721f1f2a3kpd" id="ea2e36a41csu0">onLeaveChannelResult</a>callback to notify you of the result of leaving the channel.Remote users: A successful call to this API triggers the
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#34876c27d7zv7" id="a50f534f21mew">onRemoteUserOffLineNotify</a>callback.
Response Description
0 indicates that the method call was successful. A non-zero value indicates failure.
isInCall
Checks whether the user is in a channel.
- (BOOL)isInCall;Return value
YES indicates that the user is in a channel. NO indicates that the user is not in a channel.
setClientRole
Sets the user role.
- (int)setClientRole:(AliRtcClientRole)role;This method sets the user role to streamer or viewer.
In interactive mode, before you join a channel:
If you set the user role to streamer, the SDK automatically publishes local audio and video streams and subscribes to the audio and video streams of other streamers by default.
If you set the user role to viewer, the SDK does not publish local audio and video streams but subscribes to the audio and video streams of other streamers.
When to call
This method can be called before or after you join a channel. You can call it before you join to set the initial user role, or after you join to switch roles.
Limits
This method is effective only in interactive mode. To use interactive mode, call the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#fc9626a99f5kj" id="cd8138c77fv4r">setChannelProfile</a> API and set the channel profile to AliRtcInteractivelive.
In interactive mode, you must explicitly call this method to set the user role before you join a channel.
Parameters
Name | Type | Description |
role | The user role type. The default value isAliRtcClientRolelive (viewer role). The role type is effective only in non-communication mode. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
getCurrentClientRole
Retrieves the user role (iOS only).
- (AliRtcClientRole)getCurrentClientRole;Return value
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 specific period. After the token expires, the SDK can no longer connect to the server.
Both this method and refreshAuthInfoWithToken update the authentication information. This method is for updating a multi-parameter token, while refreshAuthInfoWithToken is for updating a single-parameter token. For more 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, which indicates that your authentication information is about to expire, you must regenerate a token on your server and then call this method to pass 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, which indicates that authentication has expired. You must then regenerate a token and calljoinChannelto rejoin the channel.
Parameters
Name | Type | Description |
authInfo | AliRtcAuthInfo *_Nonnull | Authentication information. |
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
refreshAuthInfoWithToken
Refreshes the authentication information.
- (int)refreshAuthInfoWithToken:(NSString *_Nonnull)token;This method updates the token. The token expires after a specific period. After the token expires, the SDK can no longer connect to the server.
Both this API and
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6a4495191bmd" id="eb171f6dc0n9p">refreshAuthInfo</a>are used to update authentication information. This API is used to update the token for joining a channel with a single parameter, whilerefreshAuthInfois used to update the token for joining a channel with multiple parameters. For more information about token generation, see Token Authentication.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="3fd3c64767aq8">onAuthInfoExpired</a>callback is triggered to notify you that the authentication has expired. In this case, you need to calljoinChannelto rejoin the channel.
When to call
In the following situation, you must regenerate the token on your server and then call this method to pass in the new token:
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 when the authentication information is about to expire.
Parameters
Name | Type | Description |
token | NSString *_Nonnull | The authentication information for joining a session, which is provided as a single parameter. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
publishLocalAudioStream
Sets whether to publish the local 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, you can call publishLocalAudioStream(false) before you join the channel to disable audio stream publishing.
When to call
This method can be called before or after you join a channel. Calling it before you join modifies the default configuration, which takes effect when you join the channel.
Related callbacks
When the state of the local audio stream ingest changes, the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#86b2d8735bm71" id="e5ef180ba6e2i">onAudioPublishStateChanged</a> callback is triggered on the local client to report the latest status of the stream ingest. The <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#6da9cf330aoer" id="299ef35806ttb">onRemoteTrackAvailableNotify</a> callback is triggered on the remote client to notify of changes to the remote user's audio and video streams.
Parameters
Name | Type | Description |
enable | boolean |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
isLocalAudioStreamPublished
Checks whether the local audio stream is being published.
- (BOOL)isLocalAudioStreamPublished;Return value
YES allows pushing, and NO denies pushing.
setDefaultSubscribeAllRemoteAudioStreams
Sets whether to subscribe to remote audio streams by default.
- (int)setDefaultSubscribeAllRemoteAudioStreams:(BOOL)sub;This method configures whether the system subscribes to the audio streams of remote users by default. This setting affects the audio stream subscription behavior of new users who join the channel. We recommend that you set this to true unless you have specific scenario requirements.
When to call
This method can be called before or after you join a channel.
Before you join a channel:
By default, the SDK subscribes to the audio streams of remote users when you join a channel. If you want to change this behavior, you can call this method before you join.
After you join a channel:
If you want to stop the default subscription, you can call
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="a467e60e4eyhk">setDefaultSubscribeAllRemoteAudioStreams</a>(false). You will not subscribe to the audio streams of users who join the channel later.After you stop the default subscription, you can call
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#c8249fb568gms" id="9806dd9a750pf">subscribeRemoteAudioStream</a>to resume subscribing to a specific user's audio stream. If you want to resume subscribing to the audio streams of multiple users, you must 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 subscription only to the audio streams of users who join the channel afterward. It does not subscribe to the audio streams of remote users who joined while the subscription was stopped.
Parameters
Name | Type | Description |
sub | BOOL |
|
Response Description
0 indicates that the method call was successful. A non-zero value indicates failure.
subscribeRemoteAudioStream
Stops or resumes subscribing to 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 that you set this to true unless you have specific scenario requirements.
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_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 to cancel this default configuration.
Parameters
Name | Type | Description |
uid | NSString *_Nonnull | The remote user's ID. |
sub | BOOL |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
subscribeAllRemoteAudioStreams
Stops or resumes subscribing to all remote audio streams.
- (int)subscribeAllRemoteAudioStreams:(BOOL)sub;This method is a master switch for subscribing to remote audio streams. We recommend that you set it to YES. If it is set to NO, it causes the following:
Subscription to all remote audio streams in the current session is stopped.
New users who join the session are not 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 resubscribe, you can call this method again and set it to YES to resume subscription.
By default, the SDK subscribes to the audio streams of all remote users when you join a meeting. To change this behavior, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#8b515d9855osk" id="86e8c09213k9y">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before you join the meeting to cancel this default configuration.
Parameters
Name | Type | Description |
sub | BOOL |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
publishLocalVideoStream
Sets whether to publish the local camera stream.
- (int)publishLocalVideoStream:(BOOL)enable;This method controls whether to publish the locally captured video stream.
The SDK publishes the video stream by default. To disable video stream publishing, you can call publishLocalVideoStream(false) before you join the channel.
When to call
This method can be called before or after you join a channel.
Calling it before you join modifies the default configuration, which takes effect when you join the channel.
Related callbacks
When the state of the local audio stream ingest changes, the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#bd67711e63tnk" id="f966292202q3d">onVideoPublishStateChanged</a> callback is triggered on the local client to provide the latest audio stream ingest status. The <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#6da9cf330aoer" id="2fdc208ccczr1">onRemoteTrackAvailableNotify</a> callback is triggered on the remote client to notify that the remote user's audio and video stream has changed.
Parameters
Name | Type | Description |
enable | boolean |
|
isLocalVideoStreamPublished
Checks whether publishing a video stream is allowed.
- (BOOL)isLocalVideoStreamPublished;Return value
YES indicates that the camera stream is published. NO indicates that the camera stream is not published.
setDefaultSubscribeAllRemoteVideoStreams
Sets whether to subscribe to remote video streams by default.
- (int)setDefaultSubscribeAllRemoteVideoStreams:(BOOL)sub;This method sets whether to subscribe to video streams by default. The SDK subscribes by default.
By default, the SDK subscribes to the audio and video streams of remote users when you join a channel. If you want to change this behavior, you can call this method before you join the channel.
When to call
This method can be called before or after you join a channel.
Before you join a channel:
You can use this method to cancel the default subscription setting.
After you join the meeting:
If you want to stop the default subscription, you can call setDefaultSubscribeAllRemoteVideoStreams(false). This prevents you from subscribing to the video streams of users who join the channel later.
After you stop the default subscription, to resume subscribing to a specific user's audio stream, you can call the subscribeRemoteVideoStream method. To resume subscribing to the audio streams of multiple users, you must call it multiple times.
After you stop the default subscription, calling setDefaultSubscribeAllRemoteVideoStreams(false) resumes subscribing only to the audio streams of users who join subsequently.
Parameters
Name | Type | Description |
sub | boolean |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
subscribeRemoteVideoStream
Stops or resumes subscribing to a remote user's video stream.
- (int)subscribeRemoteVideoStream:(NSString *_Nonnull)uid track:(AliRtcVideoTrack)track sub:(BOOL)sub;This method subscribes to or unsubscribes from a specific user's video stream.
By default, the SDK subscribes to the video streams of all remote users when you join a meeting. To change this behavior, you can call <a baseurl="t2309850_v10_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="97d89be88bvan">setDefaultSubscribeAllRemoteVideoStreams</a>(false) before you join the meeting to cancel this default configuration.
When to call
This method can be called before or after you join a channel.
Parameters
Name | Type | Description |
uid | NSString * | The user ID, a unique identifier assigned by the App server. |
track | The video stream type. | |
sub | BOOL | Whether to subscribe. |
subscribeAllRemoteVideoStreams
Stops or resumes subscribing to all remote video streams.
This method is a master switch for subscribing to remote video streams. If it is set to NO, not only are all remote video streams in the current session unsubscribed, but new users who join the session are also not subscribed to, even if setDefaultSubscribeAllRemoteVideoStreams:YES is set.
- (int)subscribeAllRemoteVideoStreams:(BOOL)sub;This method is a master switch for subscribing to remote video streams. If it is set to false, it causes the following:
Subscription to all remote video streams in the current session is stopped.
New users who join later are also not subscribed to, even if you have called
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="0464849a17dks">setDefaultSubscribeAllRemoteVideoStreams</a>, which sets the default subscription.You cannot use
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#1cc7ef76fdawz" id="498e782f414zz">subscribeRemoteVideoStream</a>to individually control the audio stream of a specific user.
To resubscribe, you can call this method again and set it to true to resume subscription.
By default, the SDK subscribes to the video streams of all remote users when you join a meeting. To change this behavior, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#a975297480yoj" id="317fa38ecf6ya">setDefaultSubscribeAllRemoteVideoStreams</a> before you join the meeting to cancel this default configuration.
Parameters
Name | Type | Description |
sub | BOOL |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
subscribeRemoteMediaStream[1/2]
Stops or resumes subscribing to the media stream of a specific remote user.
- (int)subscribeRemoteMediaStream:(NSString *_Nonnull)uid videoTrack:(AliRtcVideoTrack)videoTrack subVideo:(BOOL)subVideo subAudio:(BOOL)subAudio;This method merges the subscription to remote audio and video streams.
Related APIs
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 for AliRtcVideoTrack is invalid and has no effect.
Parameters
Parameter | Type | Description |
uid | String | The remote user's ID. |
videoTrack | The video stream type. | |
subVideo | boolean | Stops or resumes pulling the video stream of a specific remote user. Valid values:
|
subAudio | boolean | Stops or resumes pulling the audio stream of a specific remote user. Valid values:
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
subscribeRemoteMediaStream[2/2]
Stops or resumes subscribing to the media stream of a specific remote user.
- (int)subscribeRemoteMediaStream:(NSString *_Nonnull)uid videoTrack:(AliRtcVideoTrack)videoTrack audioTrack:(AliRtcAudioTrack)audioTrack;This method merges the subscription to remote audio and video streams.
This method informs the SDK of the desired state through the videoTrack and audioTrack parameters.
Related APIs
Compared to subscribeRemoteMediaStream[1/2], this method uses the videoTrack and audioTrack parameters to inform the SDK of the desired subscription state in a single call. For example:
To subscribe to the camera stream and microphone stream, set videoTrack and audioTrack to
AliRtcVideoTrackCameraandAliRtcAudioTrackMicrespectively.To unsubscribe from the camera stream but keep the microphone stream, call the method again with videoTrack set to
AliRtcVideoTrackNoand audioTrack set toAliRtcAudioTrackMic.To unsubscribe from both, call the method again with videoTrack set to
AliRtcVideoTrackNoand audioTrack set toAliRtcAudioTrackNo.To subscribe to both the camera stream and the screen sharing stream, set videoTrack to
AliRtcVideoTrackBoth. The same applies to audio.
Parameters
Parameter | Type | Description |
uid | NSString * | The remote user's ID. |
videoTrack | The video stream type. | |
audioTrack | The audio stream type. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
subscribeRemoteDestChannelStream
Subscribes to the stream of a specific user in another channel.
- (int)subscribeRemoteDestChannelStream:(NSString *_Nonnull)channelId uid:(NSString *_Nonnull)uid track:(AliRtcVideoTrack)track subAudio:(BOOL)subAudio sub:(BOOL)sub;Parameters
Parameter | Type | Description |
channelId | String | The remote channel ID. |
uid | String | The remote user's ID. |
track | The video stream to subscribe to. | |
sub_audio | boolean | Stops or resumes pulling the audio stream of a specific remote user. Valid values:
|
sub | boolean | Stops or resumes cross-channel subscription to the specified user's stream. |
Return value
0 indicates that the method call was successful. A non-zero value indicates 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;Parameters
Name | Type | Description |
channelId | NSString * | The target channel. |
videotrack | The video stream type. | |
audioTrack | The audio stream type. | |
subAudio | BOOL | Whether to subscribe to the audio stream. |
sub | BOOL | Whether to subscribe to the video streams of users in the remote channel. |
Return value
0 indicates success. A non-zero value indicates failure.
setRemoteAudioVolume
Sets the volume of a remote audio stream.
- (int)setRemoteAudioVolume:(NSString *_Nonnull)uid volume:(NSInteger)volume;The UID must be set after the user has joined the channel. If the user has not joined, the setting fails.
Parameters
Name | Type | Description |
uid | NSString * | The user ID, a unique identifier assigned by the App server. |
volume | NSInteger | The playback volume. The range is [0, 100]. 0 means mute. 100 means the original volume. |
Return value
0 indicates success. A non-zero value indicates failure.
muteLocalMic
Stops or resumes sending local audio data.
- (int)muteLocalMic:(BOOL)mute mode:(AliRtcMuteLocalAudioMode)mode;Muting means sending silent audio frames. The capture and encoding modules continue to work.
When to call
This method can be called before or after you join 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> notification is triggered for the remote user to indicate whether that user is muted.
Parameters
Name | Type | Description |
mute | BOOL |
|
mode | The mute mode. By default, all audio is muted.
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
muteRemoteAudioPlaying
Stops or resumes playing 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 API only stops or resumes audio playback for a specified remote user, but does not affect stream pulling and decoding of the remote audio. If you want to unsubscribe from a user's audio stream, you can 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
This method can be called before or after you join a channel.
Parameters
Name | Type | Description |
uid | NSString *_Nonnull | The user ID. |
mute | BOOL |
|
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
muteAllRemoteAudioPlaying
Stops or resumes playing all remote audio.
- (int)muteAllRemoteAudioPlaying:(BOOL)mute;This method stops or resumes playing all remote audio.
This method only stops playback. Stream pulling and decoding are not affected.
When to call
This can be set before or after you join a channel.
Parameters
Name | Type | Description |
mute | BOOL |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
startAudioCapture[1/2]
Starts audio capture.
- (void)startAudioCapture;This method starts audio capture. You can also call it before you join a channel to start audio capture in advance. If you do not call it, the SDK automatically controls the audio capture device. If you want to start audio capture after you stop it with stopAudioCapture, you can call this method.
When to call
This method can be called before or after you join a channel.
Related APIs
The startAudioCapture[2/2] method lets you control whether the audio capture device remains on after you leave the channel.
Related callbacks
After you call this method to change the local audio capture state, you can retrieve the state change through the onLocalAudioStateChanged callback.
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
startAudioCapture[2/2]
Starts audio capture.
- (void)startAudioCapture:(BOOL)keepAlive;Stops microphone capture after muting.
This method starts audio capture. You can also call it before you join a channel to start audio capture in advance. If you do not call it, the SDK automatically controls the audio capture device.
When to call
This method can be called before or after you join a channel.
Related APIs
Compared to startAudioCapture[1/2], this method lets you use the keepAlive parameter to control whether the capture device remains on after you leave the channel.
Related callbacks
After you call this method to change the local audio capture state, you can retrieve the state change through the onLocalAudioStateChanged callback.
Parameters
Parameter | Type | Description |
keepAlive | boolean | The state of the capture device after leaving the channel. Valid values:
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
stopAudioCapture
Stops audio capture.
- (void)stopAudioCapture;After you call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#3103c368bexf8" id="ddef64f9b93zq">startAudioCapture</a> to start audio device capture, you can call this method to stop the capture.
Related callbacks
After you call this method to change the local audio capture state, you can retrieve the state change through the onLocalAudioStateChanged callback.
Return value
0 indicates that the method call was successful. A non-zero value indicates 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 to either the earpiece or the speaker after you join a channel. If this feature is not set, the device that is specified in the default audio route settings is used for playback.
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, when a peripheral is connected, calls to this API have no effect. For more information about audio routing settings, see Audio Routing Settings.
When to call
This method can be called before or after you join a channel.
Related APIs
<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 by setting the current routing device.
Parameters
Name | Type | Description |
enable | BOOL |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
isEnableSpeakerphone
Retrieves whether the current audio output is the earpiece or speaker (iOS only).
- (BOOL)isEnableSpeakerphone;Return value
YES indicates speaker mode. NO indicates earpiece mode.
enableAudioVolumeIndication
Sets the volume callback frequency and smoothing coefficient.
- (int)enableAudioVolumeIndication:(NSInteger)interval smooth:(NSInteger)smooth reportVad:(NSInteger)reportVad;This method allows the SDK to periodically report volume-related information about the local publishing user and the remote user with the highest instantaneous volume to the application.
When to call
This method can be called before or after you join a channel.
Related callbacks
After this method is called successfully, if there are publishing users in the channel, the SDK triggers the following two callbacks at the set time interval:
The onAudioVolumeCallback callback notifies the speaker's audio volume. The callback frequency is determined by the interval.
For voice activity detection, when an active user is detected, the onActiveSpeaker callback reports the speaker's UID.
Parameters
Name | Type | Description |
interval | NSInteger | The time interval in milliseconds. The minimum value is 10 ms. A value between 300 ms and 500 ms is recommended. A value less than or equal to 0 disables the volume and speaker indication features. |
smooth | NSInteger | The smoothing coefficient. The range is [0, 9]. A larger value provides more smoothing, while a smaller value provides better real-time performance. A value of 3 is recommended. |
reportVad | NSInteger | The speaker detection switch. Valid values:
|
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
enableEarBack
Enables in-ear monitoring.
- (int)enableEarBack:(BOOL)enable;This method enables or disables the in-ear monitoring feature. For better results, enable in-ear monitoring when you wear headphones (wired or Bluetooth).
When to call
This method can be called before or after you join a channel.
Parameters
Name | Type | Description |
enable | BOOL |
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setEarBackVolume
Sets the in-ear monitoring volume.
- (int)setEarBackVolume:(NSInteger)volume;This API is used to set the volume for in-ear monitoring. This setting takes effect only after you enable the in-ear monitoring feature by calling <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#bd665d0f894ux" id="b0fa866c9bcuq">enableEarBack</a>.
When to call
This method can be called before or after you join a channel.
Parameters
Name | Type | Description |
volume | NSInteger | The range is [0, 100]. The default value is 100. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
startAudioPlayer
Starts audio playback.
- (void)startAudioPlayer;This method can start audio playback in advance. If not set, the SDK automatically starts audio playback after it subscribes to an audio stream.
stopAudioPlayer
Stops audio playback.
- (void)stopAudioPlayer;This method can stop audio playback.
setPlayoutVolume
Sets the playback volume.
- (int)setPlayoutVolume:(NSInteger)volume;Parameters
Name | Type | Description |
volume | Volume | The range is [0, 400]. [0, 100] is the original volume range. [100, 400] is volume amplification. |
Return value
0 indicates success. A non-zero value indicates failure.
setRecordingVolume
Sets the recording volume.
- (int)setRecordingVolume:(NSInteger)volume;Parameters
Name | Type | Description |
volume | NSInteger | The range is [0, 400]. [0, 100] is the original volume. [100, 400] is volume amplification. |
Return value
0 indicates success. A non-zero value indicates failure.
playAudioFileTest
Plays an audio file.
- (int)playAudioFileTest:(NSString *_Nonnull)filePath;You must call this method before you call joinChannel.
Parameters
Parameter | Type | Description |
filePath | NSString *_Nonnull | The path of the file to play. |
Return value
0 indicates success. A non-zero value indicates failure.
stopAudioFileTest
Stops playing the audio file.
- (int)stopAudioFileTest;You must call this method before you call joinChannel.
Return value
0 indicates success. A non-zero value indicates failure.
startAudioCaptureTest
Starts audio capture device detection before a call.
- (void)startAudioCaptureTest;This method can be called only before joinChannel. Calling it after joinChannel fails.
stopAudioCaptureTest
Stops the pre-call device detection of audio capture devices.
- (void)stopAudioCaptureTest;This method must be called before `joinChannel`. Otherwise, the call fails.
setDefaultAudioRoutetoSpeakerphone
Sets whether the default audio output is the speaker. The default is the speaker.
- (int)setDefaultAudioRouteToSpeakerphone:(BOOL)defaultToSpeakerphone;This method sets the default audio route device before you join a channel. You can choose to output to the earpiece or speaker by default. The SDK defaults to the speaker. If you want to change this default configuration, you can call this method before you join.
The audio routing priority is predefined in the SDK and switches automatically based on the connection status of peripherals. The priority is as follows: Wired headset>Bluetooth headset>User settings>Default settings. Therefore, if no peripheral is connected and the audio route is not set 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 information about audio routing settings, see Audio routing settings.
Mobile devices typically have two audio route devices: the earpiece and the speaker.
When the audio route is the earpiece, the sound is quieter and can be heard clearly only by bringing the ear close. This provides better privacy and is suitable for answering calls.
When the audio route is the speaker, the sound is louder and can be heard without holding the phone to your face, which enables a "hands-free" feature.
Related APIs
This API modifies the default audio routing settings, and the <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#f7d0d8b64fzkz" id="6001aa98ebapw">enableSpeakerphone</a> API sets the current routing device.
When to call
This method can be called before or after you join a channel.
Parameters
Name | Type | Description |
defaultToSpeakerphone | BOOL | Whether to route audio to the speaker. YES for speaker, NO for earpiece. |
Return value
0 indicates success. A non-zero value indicates failure.
setAudioEffectVoiceChangerMode
Sets the voice changer effect mode.
- (int)setAudioEffectVoiceChangerMode:(AliRtcAudioEffectVoiceChangerMode)mode;Parameters
Name | Type | Description |
mode | The mode value. The default is AliRtcSdk_AudioEffect_Voice_Changer_OFF. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAudioEffectPitchValue
Sets the pitch parameter.
- (int)setAudioEffectPitchValue:(double)value;Parameters
Name | Type | Description |
value | double | The range is [0.5, 2.0]. The default is 1.0, which means the pitch is unchanged. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAudioEffectReverbMode
Sets the reverberation effect mode.
- (int)setAudioEffectReverbMode:(AliRtcAudioEffectReverbMode)mode;Parameters
Name | Type | Description |
mode | The sound effect mode. The default is AliRtcAudioEffectReverb_Off. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAudioEffectReverbParamType
Sets the reverberation effect type and specific parameters.
- (int)setAudioEffectReverbParamType:(AliRtcAudioEffectReverbParamType)type value:(float)value;Parameters
Name | Type | Description |
type | The sound effect reverberation mode. | |
value | float | The specific parameter value. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAudioEffectBeautifyMode
Sets the preset voice beautification effect mode.
- (int)setAudioEffectBeautifyMode:(AliRtcAudioEffectBeautifyMode)mode;This method sets some of the SDK's preset voice beautification modes. It is suitable for scenarios that require voice enhancement, such as voice live streaming, karaoke, and voice social networking. By selecting different beautification modes, you can change the auditory effect of the human voice, such as enhancing its magnetic quality or improving clarity, which improves the listening experience for remote users.
When to call
This method can be called before or after you join a channel.
Parameters
Parameter | Type | Description |
mode | The voice beautification effect mode. For more information, see the enumeration definition. |
Return value
0: Success.
Non-zero: Failure.
setAudioEffectEqualizationParam
Sets the audio equalizer (EQ) parameters to adjust the gain of a specified frequency band.
- (int)setAudioEffectEqualizationParam:(AliRtcAudioEffectEqualizationBandFrequency)bandIndex gain:(float)gain;This method adjusts the locally captured human voice or audio signal using a Graphic Equalizer. By adjusting the gain in dB of one of the 10 fixed frequency bands, you can customize the timbre. It is suitable for scenarios such as optimizing voice clarity, emphasizing vocals, and assisting with noise reduction.
The equalizer supports adjusting the full audio spectrum from 31 Hz to 16 kHz, with 10 standard frequency bands. The gain for each band can be set independently within the range of [-15, 15] dB. The default is 0 dB, which means no enhancement or attenuation.
Limits
The equalizer cannot be used alone before the voice beautification mode is enabled. You must call this method after you call
setAudioEffectBeautifyMode.
Parameters
Parameter | Type | Description |
bandIndex | The index of the frequency band to adjust, corresponding to a segment within the center frequencies (31 Hz to 16 kHz). | |
gain | float | The gain value in dB. The range is [-15, 15]. |
Return value
0: Success.
Non-zero: Failure.
addExternalAudioStream
Adds an external audio stream.
- (int)addExternalAudioStream:(AliRtcExternalAudioStreamConfig *_Nonnull)config;This method adds a new external audio stream. The steps are as follows:
Call
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#d71bbfd2f242b" id="c310321e9eu35">addExternalAudioStream</a>to add an external audio stream and retrieve the external audio stream ID.Call pushExternalAudioStream to input audio data into the created audio stream.
When the call ends, you must 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.
For more information about how to publish custom-captured audio in a channel, see Custom audio capture.
Parameters
Name | Type | Description |
config | AliRtcExternalAudioStreamConfig | External audio stream configuration. |
Returns
A value greater than 0 indicates success and is the external audio stream ID. Any other value indicates 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 steps are as follows:
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 retrieve the external audio stream ID.Call this method to input audio data into the created audio stream.
When the call ends, you must call
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#282d70095duaw" id="a9ebc8d599dz4">removeExternalAudioStream</a>to remove the external audio stream.
For more information about how to publish custom-captured audio in a channel, see Custom audio capture.
Parameters
Name | Type | Description |
streamId | int | The external audio stream ID. |
audioFrame | AliRtcAudioFrame | The audio data. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setExternalAudioStream:publishVolume
Sets the publishing volume of the external audio stream.
- (int)setExternalAudioStream:(int)streamId
publishVolume:(int)publishVolume;Parameters
Name | Type | Description |
streamId | int | The external audio stream ID. |
publishVolume | int | The publishing volume. |
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
getExternalAudioStreamPublishVolume
Retrieves the publishing volume of the external audio stream.
- (int)getExternalAudioStreamPublishVolume:(int)streamId;Parameters
Name | Type | Description |
streamId | int | The external audio stream ID. |
Return value
[0, 100]: The publishing volume. < 0: Failure.
setExternalAudioStream:playoutVolume
Sets the playback volume of the external audio stream.
- (int)setExternalAudioStream:(int)streamId
playoutVolume:(int)playoutVolume;Parameters
Name | Type | Description |
streamId | int | The external audio stream ID. |
playoutVolume | int | The playback volume. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
getExternalAudioStreamPlayoutVolume
Retrieves the playback volume of the external audio stream.
- (int)getExternalAudioStreamPlayoutVolume:(int)streamId;Parameters
Name | Type | Description |
streamId | int | The external audio stream ID. |
Return value
[0, 100]: The playback volume. < 0: Failure.
removeExternalAudioStream
Deletes an external audio stream.
- (int)removeExternalAudioStream:(int)streamId;This method removes the corresponding external audio stream based on the provided streamId. It corresponds to the addExternalAudioStream method.
When to call
If you want to use the custom audio input feature, you must call the addExternalAudioStream method to add an audio stream and retrieve the external audio stream ID. Then, you can call the pushExternalAudioStream method to input your audio data into the SDK. When you want to stop custom audio input, you can call this method to remove the corresponding external audio stream and clean up resources.
Parameters
Name | Type | Description |
streamId | int | The external audio stream ID. |
Return value
0 indicates success. A non-zero value indicates failure.
getAudioFileInfo
Retrieves audio file information.
- (int)getAudioFileInfo:(NSString *_Nonnull)filePath;This is an asynchronous method. You can retrieve the audio file information through {@link onAudioFileInfo:errorCode:}.
Parameters
Name | Type | Description |
filePath | NSString * | The file path. |
startAudioAccompanyWithFile
Starts audio mixing.
- (int)startAudioAccompanyWithFile:(NSString *_Nonnull)filePath config:(AliRtcAudioAccompanyConfig *_Nonnull)config;This is an asynchronous method. You can monitor the player status through {@link onAudioAccompanyStateChanged:errorCode:}.
Parameters
Name | Type | Description |
filePath | NSString * | The file path. |
config | The audio mixing configuration. |
Return value
0 indicates success. A non-zero value indicates failure.
stopAudioAccompany
Stops audio mixing.
- (int)stopAudioAccompany;Return value
0 indicates success. A non-zero value indicates failure.
setAudioAccompanyVolume
Adjust the accompaniment volume
- (int)setAudioAccompanyVolume:(NSInteger)volume;This sets both the local playback volume and the publishing volume for audio mixing.
Parameters
Name | Type | Description |
volume | NSInteger | The audio mixing volume. The range is [0, 100]. |
Return value
0 indicates success. A non-zero value indicates failure.
setAudioAccompanyPublishVolume
Sets the publishing volume for audio mixing.
- (int)setAudioAccompanyPublishVolume:(NSInteger)volume;This method sets the volume for the published stream.
Parameters
Name | Type | Description |
volume | NSInteger | The audio mixing volume. The range is [0, 100]. |
Return value
0 indicates success. A non-zero value indicates failure.
getAudioAccompanyPublishVolume
Retrieves the publishing volume for audio mixing.
- (int)getAudioAccompanyPublishVolume;Return value
[0, 100] indicates success. Any other value indicates failure.
setAudioAccompanyPlayoutVolume
Sets the local playback volume for audio mixing.
- (int)setAudioAccompanyPlayoutVolume:(NSInteger)volume;Parameters
Name | Type | Description |
volume | NSInteger | The audio mixing volume. The range is [0, 100]. |
Return value
0 indicates success. A non-zero value indicates failure.
getAudioAccompanyPlayoutVolume
Retrieves the local playback volume for audio mixing.
- (int)getAudioAccompanyPlayoutVolume;Return value
[0, 100]: Success. Any other value indicates failure.
pauseAudioAccompany
Pauses audio mixing.
- (int)pauseAudioAccompany;Return value
0 indicates success. A non-zero value indicates failure.
resumeAudioAccompany
Resumes audio mixing.
- (int)resumeAudioAccompany;Return value
0 indicates success. A non-zero value indicates failure.
getAudioAccompanyDuration
Retrieves the duration of the audio mixing file in milliseconds.
- (int)getAudioAccompanyDuration;Return value
>=0: The duration of the audio mixing file in milliseconds. <0: Failure.
getAudioAccompanyCurrentPosition
Retrieves the current playback position of the audio mixing file in milliseconds.
- (int)getAudioAccompanyCurrentPosition;Return value
>=0: The playback position of the audio mixing file. <0: Failure.
setAudioAccompanyPosition
Sets the playback position of the audio mixing file.
- (int)setAudioAccompanyPosition:(int)pos;Parameters
Name | Type | Description |
pos | int | The progress bar position in milliseconds. |
Return value
0 indicates success. A non-zero value indicates failure.
preloadAudioEffectWithSoundId
Preloads a sound effect file.
- (int)preloadAudioEffectWithSoundId:(NSInteger)soundId filePath:(NSString *_Nonnull)filePath;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
filePath | NSString *_Nonnull | The path to the sound effect file. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
unloadAudioEffectWithSoundId
Deletes a preloaded sound effect file.
- (int)unloadAudioEffectWithSoundId:(NSInteger)soundId;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
playAudioEffectWithSoundId
Starts playing a sound effect.
- (int)playAudioEffectWithSoundId:(NSInteger)soundId filePath:(NSString *_Nonnull)filePath cycles:(NSInteger)cycles publish:(BOOL)publish;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
filePath | NSString *_Nonnull | The path to the sound effect file. |
cycles | NSInteger | The number of loops (can be -1 or a positive integer). |
publish | BOOL | Whether to publish. |
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
stopAudioEffectWithSoundId
Stops playing a sound effect.
- (int)stopAudioEffectWithSoundId:(NSInteger)soundId;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
stopAllAudioEffects
Stops playing all sound effects.
- (int)stopAllAudioEffects;Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
pauseAudioEffectWithSoundId
Pauses a sound effect.
- (int)pauseAudioEffectWithSoundId:(NSInteger)soundId;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
pauseAllAudioEffects
Pauses all sound effects.
- (int)pauseAllAudioEffects;Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
resumeAudioEffectWithSoundId
Resumes playing a sound effect.
- (int)resumeAudioEffectWithSoundId:(NSInteger)soundId;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
resumeAllAudioEffects
Resumes playing all sound effects.
- (int)resumeAllAudioEffects;Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAudioEffectPublishVolumeWithSoundId
Sets the publishing volume of a sound effect.
- (int)setAudioEffectPublishVolumeWithSoundId:(NSInteger)soundId volume:(NSInteger)volume;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
volume | NSInteger | The mix volume. The range is [0, 100]. The default value is 50. |
Returns
0 indicates that the method call was successful. A non-zero value indicates failure.
getAudioEffectPublishVolumeWithSoundId
Retrieves the publishing volume of a sound effect.
- (int)getAudioEffectPublishVolumeWithSoundId:(NSInteger)soundId;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAllAudioEffectsPublishVolume
Sets the publishing mix volume for all sound effects.
- (int)setAllAudioEffectsPublishVolume:(NSInteger)volume;Parameters
Name | Type | Description |
volume | NSInteger | The mix volume. The range is [0, 100]. The default value is 50. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAudioEffectPlayoutVolumeWithSoundId
Sets the local playback volume of a sound effect.
- (int)setAaudioEffectPlayoutVolumeWithSoundId:(NSInteger)soundId volume:(NSInteger)volume;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
volume | NSInteger | The mix volume. The range is [0, 100]. The default value is 50. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
getAudioEffectPlayoutVolumeWithSoundId
Retrieves the local playback volume of a sound effect.
- (int)getAudioEffectPlayoutVolumeWithSoundId:(NSInteger)soundId;Parameters
Name | Type | Description |
soundId | NSInteger | The ID assigned to the sound effect file by the user. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setAllAudioEffectsPlayoutVolume
Sets the local playback volume for all sound effects.
- (int)setAllAudioEffectsPlayoutVolume:(NSInteger)volume;Parameters
Name | Type | Description |
volume | NSInteger | The mix volume. The range is [0, 100]. The default value is 50. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
startRecord
Starts recording a media file.
- (BOOL)startRecord:(AliRtcRecordType)recordType recordFormat:(AliRtcRecordFormat)recordFormat filePath:(NSString*)filePath audioConfig:(AliRtcRecordAudioConfig*)audioConfig videoConfig:(AliRtcRecordVideoConfig*)videoConfig;Parameters
Parameter | Type | Description |
recordType | The recording type. | |
recordFormat | The recording format. | |
filePath | NSString * | The recording file name and path. |
audioConfig | The audio configuration. | |
videoConfig | The video configuration. |
Response description
TRUE indicates success. Any other value indicates failure.
When you record a video stream, you can 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 you record an audio stream, the recorded file is a mix of local and remote audio.
stopRecord
Stops recording a media file.
- (void)stopRecord Parameters
None.
setLocalViewConfig
Sets the rendering window and drawing parameters for the local preview.
- (int)setLocalViewConfig:(AliVideoCanvas *_Nullable)viewConfig forTrack:(AliRtcVideoTrack)track;This method sets the local preview view. It binds the display view for the local video stream and sets the rendering mode, mirror mode, and rotation angle for the local user's view. It affects only the local user's preview and not the published video. To set the remote user's view, you can call setRemoteViewConfig.
If the view parameter in AliVideoCanvas: Rendering canvas. is null, rendering stops.
To reset the renderMode parameter of AliVideoCanvas: Rendering canvas. during playback, keep the other parameters unchanged and modify only renderMode.
To reset the mirrorMode parameter of AliVideoCanvas: Rendering canvas. during playback, keep the other parameters unchanged and modify only mirrorMode.
You must explicitly call startPreview() to start the local preview.
When to call
This method can be called before or after you join a channel.
Parameters
Name | Type | Description |
viewConfig | *_Nullable | Rendering parameters, including the rendering window and rendering method. |
track | The video track type. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setCameraCapturerConfiguration
Sets 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
This must be set before the camera is turned on, for example, before the following operations:
startPreview (starts preview)
joinChannel (joins a channel)
Parameters
Name | Type | Description |
config | AliRtcCameraCapturerConfiguration * _Nonnull | Camera capture preferences. Default values:
A value of -1 indicates that the SDK's internal default setting is used. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
enableLocalVideo
Disables or re-enables local video capture.
- (int)enableLocalVideo:(BOOL)enable;This method controls whether local video capture is enabled or disabled. When local video capture is disabled, both the local preview and the published stream have no video data, but this does not affect receiving remote video. If you call this method to disable local camera capture, both the local preview and the remote stream freeze on the last frame.
Local video capture is enabled by default in the SDK.
When to call
This method can be called before or after you join a channel.
Related callbacks
After this method is called successfully, remote users are notified through the onUserVideoEnabled callback.
Parameters
Name | Type | Description |
enable | BOOL | YES indicates that normal operation is resumed. NO indicates that video capture is stopped. The default value is YES. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
muteLocalCamera
Stops or resumes sending local video data.
- (int)muteLocalCamera:(BOOL)mute forTrack:(AliRtcVideoTrack)track;When you publish a stream, you can call this method to send all-black video frames. The local preview remains normal, and the capture, encoding, and sending modules continue to work, but the video content is black frames.
This method only controls whether black frames are sent on the specified video stream. Capture and data sending are not stopped. To disable capture, use the enableLocalVideo method. To stop sending video data, use the publishLocalVideoStream method.
Parameters
Name | Type | Description |
mute | BOOL | YES indicates that black frames are sent for video data. NO indicates that normal sending is resumed. The default value is NO. |
track | The type of video track whose publishing state needs to be changed. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setRemoteViewConfig
Sets the rendering window and drawing parameters for a remote video stream.
- (int)setRemoteViewConfig:(AliVideoCanvas *_Nullable)canvas uid:(NSString *_Nonnull)uid forTrack:(AliRtcVideoTrack)track;This method attaches the display view for a specified video stream from a remote user and sets its rendering mode, mirror mode, and rotation angle for local display. This affects only the video image that the local user sees. To set the local preview view, you can call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#fea843803078q" id="b6f22fe87a2es">setLocalViewConfig</a>.
If the view parameter in AliVideoCanvas: Rendering canvas. is null, rendering stops.
To reset the renderMode parameter of AliVideoCanvas: Rendering canvas. during playback, keep the other parameters unchanged and modify only renderMode.
To reset the mirrorMode parameter of AliVideoCanvas: Rendering canvas. during playback, keep the other parameters unchanged and modify only mirrorMode.
When to call
You can call this method when you receive the onRemoteTrackAvailableNotify callback, which is when the remote user's video is available.
Parameters
Name | Type | Description |
canvas | *_Nullable | Rendering parameters, including the rendering window and rendering method. |
uid | NSString *_Nonnull | The user ID. |
track | The type of video track to set. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
isCameraOn
Checks whether the camera is on.
- (BOOL)isCameraOn;Return value
YES indicates that the camera is on. NO indicates that the camera is off.
setVideoEncoderConfiguration
Sets the video encoding properties.
- (void)setVideoEncoderConfiguration:(AliRtcVideoEncoderConfiguration* _Nonnull)config;This method sets the video parameters for the video stream encoding properties, such as resolution, frame rate, bitrate, and video orientation. We recommend that you call this method for all video scenarios.
All set parameters have corresponding range limits. If a set parameter is outside the valid range, the SDK automatically adjusts it.
When to call
This method can be called before or after you join a channel. To set the camera stream video encoding properties only once per session, we recommend that you call it before you join.
Limits
Both the `mirrorMode` of this method and setVideoMirrorMode can set the video publishing mirror mode. We recommend that you use only one method. If you use both, the mirror effects may stack, which can lead to setting failures or incorrect mirroring.
Parameters
Name | Type | Description |
config | AliRtcVideoEncoderConfiguration * _Nonnull | Predefined encoding properties. Default values:
A value of -1 indicates that the SDK's internal default setting is used. |
setVideoDecoderConfiguration
Sets the video decoding properties.
- (void)setVideoDecoderConfiguration:(AliRtcVideoDecoderConfiguration* _Nonnull)config;This method sets the video parameters for the camera stream video decoding properties.
When to call
You must call this method before you join a channel.
Parameters
Name | Type | Description |
config | AliRtcVideoDecoderConfiguration * _Nonnull | Predefined decoding properties. Default values:
A value of -1 indicates that the SDK's internal default setting is used. |
switchCamera
Switches between the front and rear cameras. The front camera is used by default (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 the application's runtime based on the available cameras, without restarting the video stream or reconfiguring the video source.
When to call
This method must be called after the camera has been successfully turned on.
Limits
This is available only on Android and iOS.
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
getCurrentCameraDirection
Retrieves the current camera direction. The front camera is the default (iOS only).
- (AliRtcCameraDirection)getCurrentCameraDirection;Returns
Returns the camera direction enumeration value.
startPreview
Starts the local preview (automatically turns on the camera).
- (int)startPreview;This method starts the local video preview and automatically turns on the camera. To stop the local preview, you can call the stopPreview method.
leaveChannel automatically stops the local preview when you leave a channel. If the camera stream is not being published, the camera is automatically turned off.
When to call
Before you call this method, you must set the view for the local preview using setLocalViewConfig. Otherwise, the preview is not available, but this does not affect publishing.
If needed, you can call this method to start the preview before you join a channel with joinChannel. This automatically turns on the camera.
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
stopPreview
Stops the local preview.
- (int)stopPreview;This method stops the local video preview and turns off the camera. After you stop the preview, the local display remains on the last frame, which does not affect publishing.
leaveChannel automatically stops the local preview when you leave a channel. If the camera stream is not being published, the camera is automatically turned off.
When to call
To stop the preview after you start it, you can call this method.
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setCameraZoom
Sets the camera zoom.
- (int)setCameraZoom:(float)zoom;Parameters
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. A non-zero value indicates failure.
GetCameraMaxZoomFactor
Retrieves the maximum camera zoom factor.
- (float)GetCameraMaxZoomFactor;Return value
The maximum camera zoom factor.
GetCurrentZoom
Retrieves the current camera zoom factor.
- (float)GetCurrentZoom;Return value
Retrieves the current scaling ratio of the camera.
SetExposure
Sets the camera exposure.
- (int)SetExposure:(float)exposure;Parameters
Name | Type | Description |
exposure | float | The exposure value. |
Return value
0 indicates success. A non-zero value indicates failure.
GetCurrentExposure
Retrieves the camera exposure.
- (float)GetCurrentExposure;Return value
The camera exposure value.
GetMinExposure
Retrieves the minimum camera exposure.
- (float)GetMinExposure;Return value
The minimum camera exposure value.
GetMaxExposure
Retrieves the maximum camera exposure.
- (float)GetMaxExposure;Return value
The maximum camera exposure value.
setCameraFlash
Turns the camera flash on or off.
- (int)setCameraFlash:(BOOL)flash;Parameters
Name | Type | Description |
flash | BOOL | Whether to turn on the flash. |
Return value
0 indicates success. A non-zero value indicates failure.
isCameraFocusPointSupported
Checks 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
Checks 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;Parameters
Name | Type | Description |
point | CGPoint | The focus point coordinates to set and maintain. |
Return value
0 indicates success. A non-zero value indicates failure.
setCameraExposurePoint
Sets the exposure value for the exposure point.
- (int)setCameraExposurePoint:(CGPoint)point;Parameters
Name | Type | Description |
point | CGPoint | The focus point coordinates to set and maintain. |
Return value
0 indicates success. A non-zero value indicates failure.
isCameraAutoFocusFaceModeSupported
Checks whether the camera supports face-based autofocus.
- (BOOL)isCameraAutoFocusFaceModeSupported;Return value
TRUE indicates that face-based autofocus is supported. FALSE indicates that face-based autofocus is not supported.
setCameraAutoFocusFaceModeEnabled
Sets face-based autofocus for the camera.
- (BOOL)setCameraAutoFocusFaceModeEnabled:(BOOL)enable;Parameters
Name | Type | Description |
point | CGPoint | The focus point coordinates to set and maintain. |
Return value
TRUE indicates success. FALSE indicates failure.
setVideoMirrorMode
Sets the video mirror mode.
- (int)setVideoMirrorMode:(AliRtcVideoPipelineMirrorMode)mirrorMode;This method sets whether to enable mirror mode for the local preview video and the published video stream.
This method has a higher priority than setLocalViewConfig and setVideoEncoderConfiguration. To set the video mirror mode, we recommend that you call this method.
When to call
This method can be dynamically set before and after you join a channel. The SDK records the state and applies the video operation when the preview and encoding (publishing) can be operated.
Limits
This method overlaps with the mirrorMode in setLocalViewConfig and setVideoEncoderConfiguration. We recommend that you use only this method.
Parameters
Name | Type | Description |
mirrorMode | The mirror type. |
SetCapturePipelineScaleMode
Sets the video pipeline scaling mode.
-(void)setCapturePipelineScaleMode:(AliRtcCapturePipelineScaleMode)mode;This method sets whether video data is scaled immediately upon capture or during encoding. For example, when the capture resolution and encoding resolution are different, you can set the scaling timing to determine whether the preview data and the published data are consistent.
This controls the capture scaling timing mode. By default, scaling occurs immediately upon capture. This API must be set before the camera is turned on, such as before startPreview or joinChannel.
When to call
This method needs to be set before the camera is turned on, for example, before you start the preview with startPreview or join a channel with joinChannel.
Parameters
Name | Type | Description |
mode | The scaling type. |
Return value
0 indicates success. A non-zero value indicates failure.
registerVideoFrameWithObserver
Registers a video data output object.
- (void)registerVideoFrameWithObserver:(id<AliRtcVideoFrameDelegate> _Nullable)observer;This method registers a video data output object. To unregister, you can call the unregisterVideoSampleWithObserver method.
When to call
You can call this API to register a video data observer to obtain raw video data, such as data in YUV or RGBA format, at various stages.
Related callbacks
After you successfully register a video data output listener, the SDK triggers the callbacks you implement whenever a video frame is captured. You can implement the corresponding callbacks as needed:
onCaptureVideoSample: Callback for local captured video data.
onRemoteVideoSample: Callback for remote video data.
onPreEncodeVideoSample: Callback for local video data before encoding.
Parameters
Name | Type | Description |
observer | The video data output object. |
unregisterVideoSampleWithObserver
Unregisters a video data output object.
- (void)unregisterVideoSampleWithObserver:(id<AliRtcVideoFrameDelegate> _Nullable)observer;This API is the counterpart of <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#9a3437ab16j1w" id="f524bad30a6ys">registerVideoSampleObserver</a> and unregisters the object for video data output.
Metric descriptions
Name | Type | Description |
observer | The video data output object. |
registerLocalVideoTextureObserver
Registers a listener for local camera stream video OpenGL texture data.
- (void)registerLocalVideoTextureObserver:(id<AliRtcTextureDelegate> _Nullable)observer;If you want to retrieve raw video data, you can call the registerVideoSampleObserver method to register the relevant callbacks. If you want to retrieve internal texture data, you can call this method. To unregister, you can call the unRegisterLocalVideoTextureObserver method.
This method is valid only for local camera stream video.
After you register an observer for OpenGL texture data from the local camera video stream, the SDK triggers the onTextureCreate, onTextureUpdate, and onTextureDestroy callbacks whenever a video frame is captured. This interface works only with the local camera video stream.
Related callbacks
After you successfully register a listener for local camera stream video OpenGL texture data, the SDK triggers the callbacks you implement in the AliRtcTextureObserver interface whenever a video frame is captured. You can implement the corresponding callbacks as needed:
onTextureCreate: This callback is triggered when the SDK's internal OpenGL context is created.
onTextureUpdate: This callback is triggered after each video frame is uploaded to an OpenGL texture. When an external OpenGL texture data listener is registered, you can process the texture in this callback and return the processed texture ID. This callback must return a valid texture ID. If no processing is done, it must return the textureId parameter.
onTextureDestroy: This callback is triggered when the SDK's internal OpenGL context is destroyed.
Parameters
Name | Type | Description |
observer | The OpenGL texture data listener. |
unregisterLocalVideoTextureObserver
Unregisters the listener for local camera stream video OpenGL texture data.
- (void)unregisterLocalVideoTextureObserver:(id<AliRtcTextureDelegate> _Nullable)observer;This method corresponds to registerLocalVideoTextureObserver and is responsible for unregistering.
Parameters
Name | Type | Description |
observer | The OpenGL texture data listener. |
snapshotVideo
Video snapshot feature.
- (int)snapshotVideo:(NSString*_Nullable)userId type:(AliRtcVideoTrack)type;Parameters
Name | Type | Description |
userId | NSString * | The user ID. A null or empty userId represents the local user. |
type | The video stream type. Only {@link AliRtcVideoTrack::AliRtcVideoTrackCamera} and {@link AliRtcVideoTrack::AliRtcVideoTrackScreen} are supported. |
Return value
0 indicates success. A non-zero value indicates failure.
setExternalVideoSource
Enables an external video input source.
- (int)setExternalVideoSource:(BOOL)enable sourceType:(AliRtcVideoSource)type renderMode:(AliRtcRenderMode)renderMode;Parameters
Name | Type | Description |
enable | BOOL | YES enables, NO disables. |
type | The stream type. | |
renderMode | The rendering mode. |
pushExternalVideoFrame
Inputs video data.
- (int)pushExternalVideoFrame:(AliRtcVideoDataSample *_Nonnull)frame sourceType:(AliRtcVideoSource)type;Parameters
Name | Type | Description |
frame | *_Nonnull | The frame data. |
type | The stream type. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
startPublishLiveStreamWithURL
Starts bypass live streaming.
- (int)startPublishLiveStreamWithURL:(NSString *_Nonnull)streamURL liveTranscoding:(AliRtcLiveTranscodingParam *_Nonnull)trancoding;Parameters
Name | Type | Description |
streamUrl | NSString * | The ingest URL. |
transcoding | * | The parameters required for stream ingest. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
updatePublishLiveStreamWithURL
Updates bypass live streaming parameters.
- (int)updatePublishLiveStreamWithURL:(NSString *_Nonnull)streamURL liveTranscoding:(AliRtcLiveTranscodingParam *_Nonnull)trancoding;Parameters
Name | Type | Description |
streamUrl | NSString * | The ingest URL. |
transcoding | * | The parameters required for stream ingest. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
stopPublishLiveStreamWithURL
Stops bypass live streaming.
- (int)stopPublishLiveStreamWithURL:(NSString *_Nonnull)streamURL;Parameters
Name | Type | Description |
streamUrl | NSString *_Nonnull | The ingest URL. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
GetPublishLiveStreamStateWithURL
Retrieves the bypass live streaming status.
- (AliRtcLiveTranscodingState)GetPublishLiveStreamStateWithURL:(NSString *_Nonnull)streamURL;Parameters
Parameter | Type | Description |
streamURL | NSString * | The ingest URL. |
Return value
Returns the bypass live streaming status.
startLastmileDetect
Starts network quality probing.
- (int)startLastmileDetect:(AliRtcNetworkQualityProbeConfig *_Nonnull)config;Parameters
Parameter | Type | Description |
config | The probing configuration parameters. |
Response Description
0 indicates success. A non-zero value indicates failure.
stopLastmileDetect
Stops network quality probing.
- (int)stopLastmileDetect;Return value
0 indicates success. A non-zero value indicates failure.
sendMediaExtensionMsg
Sends Supplemental Enhancement Information (SEI).
- (int)sendMediaExtensionMsg:(NSData *_Nonnull)data repeatCount:(int)repeatCount delay:(int)delay isKeyFrame:(bool)isKeyFrame;The SDK provides the functionality to send and receive media extension information. This method sends media extension information using the SEI extension protocol. The receiver can retrieve the information by listening to the onMediaExtensionMsgReceived callback.
Common use cases include the following:
You can transmit timestamps using media extension information to calculate end-to-end network latency or to synchronize data with other business services.
You can transmit descriptive information using media extension information. Currently, up to 4 KB of data can be transmitted, which can be used for small amounts of data, preferably in JSON or plain string format.
When to call
You can call this method after you start to publish the stream.
Limits
When you use media extension information, the audio and video data channel is reused. 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. This is because SEI is transmitted in the H.264/H.265 stream, and extension information can be attached only when a video frame is available to encode.
To avoid affecting the quality of media data transmission, the custom message body is limited to 4 KB. This can be used for small amounts of information.
The repeatCount parameter in the sendMediaExtensionMsg function is for message redundancy. 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 channel also receive the same message multiple times and need to deduplicate them.
Subscribers in the channel also receive custom messages that are sent during bypass live streaming.
Only one `MediaExtensionMsg` can be transmitted at a time. If sendMediaExtensionMsg is called multiple times, the new data overwrites the previous data.
Related callbacks
After the publishing party sends media extension information, the subscribing party can retrieve the information by listening to the onMediaExtensionMsgReceived callback.
Parameters
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. -1 means infinite resends, unless sendMediaExtensionMsg is called again. |
delay | int | The delay in milliseconds before sending. This is used to delay the sending of 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 added only to keyframes. |
Return value
0 indicates success. A non-zero value indicates failure.
sendMediaExtensionMsgEx
Sends media extension information, which is implemented using SEI at the underlying layer.
- (int)sendMediaExtensionMsgEx:(NSData *_Nonnull)data repeatCount:(int)repeatCount delay:(int)delay isKeyFrame:(bool)isKeyFrame payloadType:(int)payloadType;The SDK provides the functionality to send and receive media extension information. This method sends media extension information using the SEI extension protocol. The receiver can retrieve the information by listening to the onMediaExtensionMsgReceived callback. When payloadType is 5, it is equivalent to using the sendMediaExtensionMsg method.
Common use cases include the following:
You can transmit timestamps using media extension information to calculate end-to-end network latency or to synchronize data with other business services.
You can transmit descriptive information using media extension information. Currently, up to 4 KB of data can be transmitted, which can be used for small amounts of data, preferably in JSON or plain string format.
When to call
You can call this method after you start to publish the stream.
Limits
When you use media extension information, the audio and video data channel is reused. 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. This is because SEI is transmitted in the H.264/H.265 stream, and extension information can be attached only when a video frame is available to encode.
To avoid affecting the quality of media data transmission, the custom message body is limited to 4 KB. This can be used for small amounts of information.
The repeatCount parameter in the sendMediaExtensionMsg function is for message redundancy. 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 channel also receive the same message multiple times and need to deduplicate them.
Subscribers in the channel also receive custom messages that are sent during bypass live streaming.
Only one `MediaExtensionMsg` can be transmitted at a time. If sendMediaExtensionMsg is called multiple times, the new data overwrites the previous data.
Parameters
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. -1 means infinite resends, unless sendMediaExtensionMsg is called again. |
delay | int | The delay in milliseconds before sending. This is used to delay the sending of 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 added only to keyframes. |
payloadType | int | The type. Use 5 for UUIDs. The range is [5, 100..254]. |
Returns
0: Success.
<0: Failure. An error code is returned.
ERR_INNER(-1): Internal SDK error. This may occur if the SDK is not initialized or is called after it is destroyed.
onConnectionStatusChange
Callback for network connection status changes.
- (void)onConnectionStatusChange:(AliRtcConnectionStatus)status reason:(AliRtcConnectionStatusChangeReason)reason;Parameters
Parameter | Type | Description |
status | The current status value. | |
reason | The specific reason for the status change. |
onLocalDeviceException
Callback for local device exceptions. Customers need to handle this callback.
- (void)onLocalDeviceException:(AliRtcLocalDeviceType)deviceType exceptionType:(AliRtcLocalDeviceExceptionType)exceptionType message:(NSString *_Nullable)msg;Parameters
Parameter | Type | Description |
deviceType | AliRtcLocalDeviceType | The device type. |
exceptionType | AliRtcLocalDeviceExceptionType | The device exception type. |
msg | NSString | The message carried during the exception. |
onAuthInfoWillExpire
Notification that user authentication information is about to expire. Authentication expires 30 seconds after this notification is received. Customers need to handle this callback.
- (void)onAuthInfoWillExpire;This callback indicates that the user's authentication information is about to expire. Authentication expires 30 seconds after this callback is received. You need to retrieve a new token and then update the authentication information in one of the following ways:
Call the
<a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#e6a4495191bmd" id="918ba91977wi6">refreshAuthInfo</a>API to update 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 calljoinChannelto rejoin the channel.
When this is triggered
The SDK triggers this callback 30 seconds before the user's authentication information expires. You should update the authentication information promptly after you receive this callback.
onAuthInfoExpired
The server returns that the authentication information has expired when a user calls an API that requires authentication.
- (void)onAuthInfoExpired;This callback indicates that the user's authentication information has expired. To continue in the session, you need to generate a new token on the server and then update the authentication information using the following method:
You can 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 calljoinChannelto rejoin it.
When this is triggered
This callback is triggered when the user's authentication information expires.
onJoinChannelResult
Callback for the result of joining a channel. This callback is equivalent to the block operation of the joinChannel method. It handles events after you join a channel. You can use either one.
- (void)onJoinChannelResult:(int)result channel:(NSString *_Nonnull)channel elapsed:(int) elapsed;Trigger conditions
When the application calls the joinChannel method, this callback indicates whether joining the channel was successful or failed. It also returns information about joining the channel and the time it took.
Parameters
Parameter | Type | Description |
result | int | The result of joining the channel. 0 indicates success. A non-zero value indicates an error code. |
channel | NSString *_Nonnull | The ID of the channel joined. |
elapsed | int | The time taken to join the channel. |
onLeaveChannelResult
Callback for the result of leaving a channel. This is returned after you call the leaveChannel method. If you call destroy immediately after leaveChannel, you do not receive this callback.
- (void)onLeaveChannelResult:(int)result stats:(AliRtcStats)stats;Parameters
Parameter | Type | Description |
result | int | The result of leaving the channel. 0 indicates success. A non-zero value indicates an error code. |
stats | A summary of data statistics for this session in the channel. |
onRemoteUserOffLineNotify
A callback that is invoked when a remote user goes offline.
- (void)onRemoteUserOffLineNotify:(NSString *_Nonnull)uid offlineReason:(AliRtcUserOfflineReason)reason;This callback is triggered when a remote user goes offline. It notifies the local user that the remote user has left the channel.
Trigger conditions
Triggered when a remote user leaves the channel.
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 their role to viewer (`AliRtcClientRolelive`).Triggered when a remote streamer is considered disconnected because no data is received from them for an extended period.
Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID, a unique identifier assigned by the App server. |
reason | The reason the user went offline. |
onRemoteUserOnLineNotify
Callback for when a remote user comes online.
- (void)onRemoteUserOnLineNotify:(NSString *_Nonnull)uid elapsed:(int)elapsed;This method notifies the local client that a remote user has joined the channel.
Trigger conditions
A remote user successfully joins the channel.
After the current user joins the channel, they receive join callbacks for users who are already in the channel. This can be used to display previously joined users.
Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID, a unique identifier assigned by the App server. |
elapsed | int | The time taken for the user to join the channel. |
onRemoteTrackAvailableNotify
Callback for when a remote user's stream changes.
- (void)onRemoteTrackAvailableNotify:(NSString *_Nonnull)uid audioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;This callback is triggered when the publishing state of a remote user changes. Through this callback, developers can know in real time whether a remote user is publishing audio and video streams and can show or hide the remote user's audio and video information on the interface accordingly.
This callback returns the publishing status of the remote user. To know which stream went offline in this change, you must record the state before and after the callback.
Trigger conditions
This callback is triggered in the following scenarios:
When a remote user changes from not publishing to publishing, including audio and video.
When a remote user changes from publishing to not publishing, including audio and video.
In interactive mode, when a remote user calls setClientRole to switch from a viewer to a streamer and also sets up publishing, this callback is triggered.
For example, this callback is not triggered for video if a remote user disables stream ingest:
The remote user starts publishing the camera stream (publishing state: no video stream -> camera stream only). The local client's callback returns
AliRtcVideoTrackCamera, which indicates that the remote user's camera stream is available.The remote user also publishes the screen sharing stream (publishing state: camera stream only -> camera and screen sharing streams). The local client's callback returns
AliRtcVideoTrackBoth, which indicates that both the camera and screen sharing streams are available.The remote user stops publishing the camera stream but keeps the screen sharing stream (publishing state: camera and screen sharing streams -> screen sharing stream only). The local client's callback returns
AliRtcVideoTrackScreen, which indicates that only the screen sharing stream is available.The remote user then stops publishing the screen sharing stream (publishing state: screen sharing stream only -> no video stream). The local client's callback returns
AliRtcVideoTrackNo, which indicates that no video stream is available.
Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID, a unique identifier assigned by the App server. |
audioTrack | The audio stream of the remote user after the change. | |
videoTrack | The video stream of the remote user after the change. |
onBye
Callback for when the user is kicked from the server or the channel is closed.
- (void)onBye:(int)code;When a user is disconnected for some reason or the session ends, this callback is triggered. Developers can learn the reason for the disconnection from the code parameter and handle it accordingly.
Trigger conditions
The current user is kicked from the server.
The session ends because the server actively removes the channel.
The user is passively disconnected, and the client needs to try to restore the session or reconnect.
Parameters
Parameter | Type | Description |
code | int | The message type. Valid values:
|
onAudioPublishStateChanged
Callback for audio publishing state changes.
- (void)onAudioPublishStateChanged:(AliRtcPublishState)oldState newState:(AliRtcPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;This callback listens for changes in the local user's audio publishing state.
Trigger conditions
When the user's audio publishing state changes, for example:
Publishing is stopped.
You 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 your role to viewer.
Parameters
Parameter | Type | Description |
oldState | The previous publishing state. | |
newStat | The current publishing state. | |
elapseSinceLastState | NSInteger | The time interval since the last state change, in milliseconds. |
channel | NSString *_Nonnull | The current channel ID. |
onAudioSubscribeStateChanged
Callback for audio subscription state 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 status of a remote user's audio stream changes. It provides details about the status change for a specific remote user and the time elapsed since the previous state.
Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID whose subscription state has changed. |
oldState | The previous subscription state. | |
newState | The current subscription state. | |
elapseSinceLastState | NSInteger | The time interval since the last state change, in milliseconds. |
channel | NSString *_Nonnull | The current channel ID. |
onUserAudioMuted
Notification that a user has muted their audio.
- (void)onUserAudioMuted:(NSString *_Nonnull)uid audioMuted:(BOOL)isMute;Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID of the user who muted their audio. |
isMute | BOOL | YES indicates muted. NO indicates unmuted. |
onUserAudioInterruptedBegin
Notification that a user's audio has been interrupted, typically when the audio is preempted by a phone call.
- (void)onUserAudioInterruptedBegin:(NSString *_Nonnull)uid;Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID of the user whose audio was interrupted. |
onUserAudioInterruptedEnded
Notification that a user's audio interruption has ended. This corresponds to onUserAudioInterruptedBegin.
- (void)onUserAudioInterruptedEnded:(NSString *_Nonnull)uid;Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID of the user whose audio interruption has ended. |
onVideoPublishStateChanged
Callback for video publishing state changes.
- (void)onVideoPublishStateChanged:(AliRtcPublishState)oldState newState:(AliRtcPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;This callback listens for changes in the local user's video publishing state.
Parameters
Parameter | Type | Description |
oldState | The previous publishing state. | |
newState | The current publishing state. | |
elapseSinceLastState | NSInteger | The time interval since the last state change, in milliseconds. |
channel | NSString *_Nonnull | The current channel ID. |
onVideoSubscribeStateChanged
Callback for camera stream subscription state changes.
- (void)onVideoSubscribeStateChanged:(NSString *_Nonnull)uid oldState:(AliRtcSubscribeState)oldState newState:(AliRtcSubscribeState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;This callback notifies the local user of changes in the subscription state of a remote user's camera stream. Through this callback, you can learn about the subscription state changes of a specific remote user's camera stream and the time interval from the previous state to the current state.
Related callbacks
Video streams mainly include camera streams and screen sharing streams. This method is for camera stream subscription state changes. The related callback method for screen sharing streams is onScreenShareSubscribeStateChanged.
Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID whose subscription state has changed. |
oldState | The previous subscription state. | |
newState | The current subscription state. | |
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;Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID of the user who muted their video. |
isMute | BOOL | YES indicates that black frames are published. NO indicates that normal streaming is resumed. |
onUserVideoEnabled
Notification that local video capture has been disabled or re-enabled.
- (void)onUserVideoEnabled:(NSString *_Nullable)uid videoEnabled:(BOOL)isEnable;Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID of the user who called EnableLocalVideo. |
isMute | BOOL | YES indicates that camera stream capture is enabled. NO indicates that camera stream capture is disabled. |
onUserWillResignActive
Callback for when a remote user's application moves to the background.
- (void)onUserWillResignActive:(NSString *_Nonnull)uid;Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID of the user whose application has moved to the background. |
onUserWillBecomeActive
Callback for when a remote user's application returns to the foreground.
- (void)onUserWillBecomeActive:(NSString *_Nonnull)uid;Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The user ID of the user whose application has returned to the foreground. |
onRtcStats
Real-time data callback, which is triggered every 2 seconds.
- (void)onRtcStats:(AliRtcStats)stats;Parameters
Parameter | Type | Description |
stats | The data callback. |
onRtcLocalVideoStats
Local video statistics, which are triggered every 2 seconds.
- (void)onRtcLocalVideoStats:(AliRtcLocalVideoStats *_Nonnull)localVideoStats;Parameters
Parameter | Type | Description |
localVideoStats | The local video statistics. |
onRtcRemoteVideoStats
Remote video statistics, which are triggered every 2 seconds.
- (void)onRtcRemoteVideoStats:(AliRtcRemoteVideoStats *_Nonnull)remoteVideoStats;Parameters
Parameter | Type | Description |
remoteVideoStats | The remote video statistics. |
onRtcLocalAudioStats
Local audio statistics, which are triggered every 2 seconds.
- (void)onRtcLocalAudioStats:(AliRtcLocalAudioStats *_Nonnull)localAudioStats;Parameters
Parameter | Type | Description |
localAudioStats | The local audio statistics. |
onRtcRemoteAudioStats
Remote audio statistics, which are triggered every 2 seconds.
- (void)onRtcRemoteAudioStats:(AliRtcRemoteAudioStats *_Nonnull)remoteAudioStats;Metric descriptions
Parameter | Type | Description |
remoteAudioStats | The remote audio statistics. |
onMediaExtensionMsgReceived
Callback for receiving media extension messages.
- (void)onMediaExtensionMsgReceived:(NSString *_Nonnull)uid payloadType:(int)payloadType message:(NSData *_Nonnull)data;When one party sends a message using sendMediaExtensionMsg, other parties receive the data through this callback.
Parameters
Parameter | Type | Description |
uid | NSString | The user ID. |
payloadType | int | The payload type. |
message | NSData * | The media extension message. |
onAudioRouteChanged
Callback for audio route changes, for Android and iOS only.
- (void)onAudioRouteChanged:(AliRtcAudioRouteType)routing;Parameters
Parameter | Type | Description |
routing | The route type. |
onSnapshotComplete
Snapshot callback.
- (void)onSnapshotComplete:(NSString*_Nullable)uid videoTrack:(AliRtcVideoTrack)videoTrack image:(UIImage* _Nullable)image success:(BOOL)success;Parameters
Parameter | Type | Description |
image | UIImage * | The image type. |
success | BOOL | Whether the operation was successful. |
onLocalAudioStateChanged
Callback for local audio capture device state.
- (void)onLocalAudioStateChanged:(AliRtcLocalAudioStateType)state message:(NSString *_Nullable)msg;Callback for the results of startAudioCapture and stopAudioCapture.
Parameters
Parameter | Type | Description |
state | The device state, of type AliRtcLocalAudioStateType. | |
msg | NSString * | A descriptive message about the device state change. |
onLocalVideoStateChanged
Callback for local video capture device state.
- (void)onLocalVideoStateChanged:(AliRtcLocalVideoStateType)state message:(NSString *_Nullable)msg;Parameters
Parameter | Type | Description |
state | The device state, of type AliRtcLocalVideoStateType. | |
msg | NSString * | A descriptive message about the device state change. |
onRemoteUserSubscribedDataChannel
Callback that indicates that data channel messages can be sent.
- (void)onRemoteUserSubscribedDataChannel:(NSString *_Nonnull)uid;This callback is triggered when a remote user subscribes to the data channel. It notifies the local user that the specified remote user is ready to receive custom messages. Developers can then safely call sendDataChannelMessage to send data to them. This callback is a key mechanism for ensuring reliable message delivery and preventing packet loss or failure when you send messages to a user who has not yet subscribed to the data channel.
This callback is triggered only in AI scenarios.
Parameters
Parameter | Type | Description |
uid | NSString * | The user ID. |
onDataChannelMessage
Data channel message callback.
- (void)onDataChannelMessage:(NSString *_Nonnull)uid controlMsg:(AliRtcDataChannelMsg*_Nonnull)controlMsg;The ARTC SDK provides the ability to send and receive custom messages, which allows real-time custom message data to be sent alongside audio and video data. This callback is used to receive custom messages from the data channel. For specific usage, see Sending and receiving custom messages.
In interactive scenarios, streamers can send and receive messages, while viewers can only receive them.
This feature is disabled by default. To enable it, you can call the
setParametermethod with{\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}}after you create the engine. This can be done before or after you join a channel.
When this is triggered
After the sender calls sendDataChannelMessage to send a custom message, if the receiver has enabled the data channel feature, this callback is triggered on the receiver's side.
Metric description
Parameter | Type | Description |
uid | NSString * | The user ID. |
controlMsg | The data channel message. |
onScreenSharePublishStateChanged
Callback for screen sharing publishing state changes.
- (void)onScreenSharePublishStateChanged:(AliRtcPublishState)oldState newState:(AliRtcPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState channel:(NSString *_Nonnull)channel;Parameters
Parameter | Type | Description |
oldState | The probing result. 0 indicates success. -1 indicates failure due to poor network conditions. | |
newState | The previous publishing state. | |
newState | The new publishing state. | |
elapseSinceLastState | NSInteger | The time interval since the last state change (in milliseconds). |
channel | NSString * | The current channel ID. |
onCapturedAudioFrame
Callback for captured raw data.
- (BOOL)onCapturedAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;This callback retrieves the raw audio data that is captured by the current device. It is disabled by default. To retrieve this audio data:
Enable this callback for the audioSource in enableAudioFrameObserver(true, audioSource, config). The config parameter can also set the sample rate, number of channels, and read/write mode for the audio data.
Call registerAudioFrameObserver to register an audio data receiving object.
This method supports setting the sample rate, number of channels, and read/write mode.
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
This method supports setting the sample rate and number of channels.
This method supports read/write mode.
Limits
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | The video frame. |
Return value
true: success
onProcessCapturedAudioFrame
Callback for data after 3A processing.
- (BOOL)onProcessCapturedAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;This callback retrieves the audio data after it has been processed by 3A. It is disabled by default. To retrieve this audio data:
Enable this callback for the audioSource in enableAudioFrameObserver(true, audioSource, config). The config parameter can also set the sample rate, number of channels, and read/write mode for the audio data.
Call registerAudioFrameObserver to register an audio data receiving object.
This method supports setting the sample rate, number of channels, and read/write mode.
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
The method supports setting the sample rate and number of channels.
This method supports read/write mode.
Limits
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | The video frame. |
Return value
true: success
onPublishAudioFrame
Callback for published stream data.
- (BOOL)onPublishAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;This callback retrieves the published audio data. It is disabled by default. To retrieve this audio data:
Enable this callback for the audioSource in enableAudioFrameObserver(true, audioSource, config). The config parameter can also set the sample rate, number of channels, and read/write mode for the audio data.
Call registerAudioFrameObserver to register an audio data receiving object.
This method supports setting the sample rate and number of channels, but can be set only to read-only mode.
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
The method supports setting the sample rate and number of channels.
This method supports read/write mode.
Limits
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | The video frame. |
Return value
true: success
onPlaybackAudioFrame
Callback for playback data.
- (BOOL)onPlaybackAudioFrame:(AliRtcAudioFrame* _Nonnull)frame;This callback retrieves the playback audio data. It is disabled by default. To retrieve this audio data:
Enable this callback for the audioSource in enableAudioFrameObserver(true, audioSource, config). The config parameter can also set the sample rate, number of channels, and read/write mode for the audio data.
Call registerAudioFrameObserver to register an audio data receiving object.
This method supports setting the sample rate, number of channels, and read/write mode.
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
The method supports setting the sample rate and number of channels.
This method supports read/write mode.
Limits
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | The video frame. |
Return value
true: success
onRemoteUserAudioFrame
Callback for remote stream pulling data.
- (BOOL)onRemoteUserAudioFrame:(NSString *_Nullable)uid frame:(AliRtcAudioFrame* _Nonnull)frame;This callback retrieves the pulled remote audio data of a specified user. It is disabled by default. To retrieve this audio data:
Enable this callback for the audioSource in enableAudioFrameObserver(true, audioSource, config). The config parameter can also set the sample rate, number of channels, and read/write mode for the audio data.
Call registerAudioFrameObserver to register an audio data receiving object.
This method does not support setting the sample rate or number of channels, but it does support setting the read/write mode.
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
The method does not support setting the sample rate or number of channels.
This method supports read/write mode.
Limits
Do not perform any time-consuming operations in this callback function because it may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | The video frame. |
Return value
true: success
onDestroyCompletion
Callback for when the engine is released. The engine is considered released only after this callback is executed.
- (void)onDestroyCompletion;This callback indicates that the SDK engine instance has been destroyed and a new one can be created.
Wait for the onDestroyCompletion callback before you execute other methods to avoid blocking the main thread.
When this is triggered
This callback is triggered after the engine is destroyed when the user calls destroy[2/2].
onTextureCreate
Callback for OpenGL context creation.
- (void)onTextureCreate:(void *_Nullable)context;This callback is triggered when the SDK's internal OpenGL context is created.
Trigger conditions
This callback is triggered when the SDK's internal OpenGL context is created, which allows developers to initialize related resources.
Parameters
Parameter | Type | Description |
context | void * | The OpenGL context. |
onTextureUpdate
Callback for OpenGL texture updates.
- (int)onTextureUpdate:(int)textureId width:(int)width height:(int)height videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;This callback is triggered after each video frame is uploaded to an OpenGL texture. When an external OpenGL texture data listener is registered, you can process the texture in this callback and return the processed texture ID.
This callback must return a valid texture ID. If no processing is done, it must return the textureId parameter.
Trigger conditions
This callback is triggered after each video frame is uploaded to an OpenGL texture. When an external OpenGL texture data listener is registered, you can process the texture in this callback and return the processed texture ID.
Parameters
Parameter | Type | Description |
textureId | int | The OpenGL context. |
width | int | The video width. |
height | int | The video height. |
videoSample | The video frame data. |
Return value
Returns the new or old texture ID. If a value less than 0 is returned, the texture ID is considered not updated.
onTextureDestory
Callback for OpenGL context destruction.
- (void)onTextureDestory;This callback is triggered when the SDK's internal OpenGL context is destroyed.
Trigger conditions
This callback is triggered when the SDK's internal OpenGL context is destroyed, which allows developers to clean up related resources.
onCaptureVideoSample
Callback for captured video frames.
- (BOOL)onCaptureVideoSample:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;This method is a callback for retrieving local video capture data. It is used to retrieve the raw video frames, such as YUV data, that are captured by the local camera. Developers can use this callback to implement custom video processing logic, such as adding filters, watermarks, or transcoding, and decide whether to return the processed data to the SDK for subsequent encoding or rendering. To send the processed video to the SDK, return true.
When this is triggered
After you call <a baseurl="t2309850_v9_0_0.xdita" data-node="4087266" data-root="16090" data-tag="xref" href="#9a3437ab16j1w" id="6c93b9cf8e771">registerVideoSampleObserver</a> to register a video data observer, the SDK captures the video frames.
Parameters
Parameter | Type | Description |
videoSource | The video stream type. | |
videoSample | The raw video data. |
Return value
YES: Needs to be written back to the SDK. This is valid only for I420 and CVPixelBuffer on iOS/macOS.
NO: Does not need to be written back to the SDK.
onPreEncodeVideoSample
Callback for local video data before encoding.
- (BOOL)onPreEncodeVideoSample:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;
This method is a callback for retrieving local video data before encoding. It is used to retrieve the raw video data, such as YUV format, before the SDK encodes the video frame. Developers can use this callback to implement custom processing logic, such as adding watermarks, adjusting colors, or transcoding, and decide whether to return the processed data to the SDK for subsequent encoding.
Parameters
Parameter | Type | Description |
videoSource | The video stream type. | |
videoSample | The raw video data. |
Return value
YES: Needs to be written back to the SDK. This is valid only for I420 and CVPixelBuffer on iOS/macOS.
NO: Does not need to be written back to the SDK.
onRemoteVideoSample
Callback for subscribed remote video data.
- (BOOL)onRemoteVideoSample:(NSString *_Nonnull)uid videoSource:(AliRtcVideoSource)videoSource videoSample:(AliRtcVideoDataSample *_Nonnull)videoSample;This method is a callback for retrieving subscribed remote video data. It is used to retrieve the raw video frame data, such as YUV format, of a remote user. Developers can use this callback to implement custom processing logic, such as adding filters, watermarks, or transcoding, and decide whether to return the processed data to the SDK for subsequent rendering.
Parameters
Parameter | Type | Description |
uid | NSString * | The user ID. |
videoSource | The video stream type. | |
videoSample | The raw video data. |
Return value
YES: Needs to be written back to the SDK. This is valid only for I420 and CVPixelBuffer on iOS/macOS.
NO: Does not need to be written back to the SDK.
onGetVideoFormatPreference
Video data output format.
- (AliRtcVideoFormat)onGetVideoFormatPreference;The application can return the desired output video data format. The default is AliRtcYUV420.
Return value
The desired video output format.
onGetVideoObservedFramePosition
Video data output position.
- (NSInteger)onGetVideoObservedFramePosition;Return value
The desired video output. See {@link AliRtcVideoObserPosition}.
onAudioEffectFinished
Callback for when local sound effect playback finishes.
- (void)onAudioEffectFinished:(int)soundId;Parameters
Parameter | Type | Description |
soundId | int | The ID of the sound effect that has finished playing. |
onAudioVolumeCallback
Callback for the audio volume, voice status, and UID of the subscribed audio.
- (void)onAudioVolumeCallback:(NSArray <AliRtcUserVolumeInfo *> *_Nullable)array totalVolume:(int)totalVolume;This method is a callback for retrieving subscribed remote video data. It is used to retrieve the raw video frame data, such as YUV format, of a remote user. Developers can use this callback to implement custom processing logic, such as adding filters, watermarks, or transcoding, and decide whether to return the processed data to the SDK for subsequent rendering.
Parameters
Parameter | Type | Description |
array | NSArray <AliRtcUserVolumeInfo *> *_Nullable | An array of user volume information, including user UID, voice status, and volume.
|
totalVolume | int | The total mixed volume, ranging from [0, 255]. In the local user's callback, totalVolume is the mixed volume of the local user. In the remote user's callback, totalVolume is the total mixed volume of all speakers. |
onActiveSpeaker
Callback for the current speaker.
- (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 for the remote user with the highest volume and counts the number of times that user is identified as the loudest speaker. In the current time period, the remote user with the highest cumulative count is considered the most active user.
Trigger conditions
If there are two or more users in the channel and there is an active remote user, the SDK triggers this callback and reports the UID of the most active remote user.
If the most active remote user remains the same, the SDK does not trigger the
onActiveSpeakercallback 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.
Parameters
Parameter | Type | Description |
uid | NSString *_Nonnull | The ID of the current speaker. |
onPublishLiveStreamStateChanged
Callback for bypass stream publishing state changes.
- (void)onPublishLiveStreamStateChanged:(NSString *_Nonnull)streamURL state:(AliRtcLiveTranscodingState)state errCode:(AliRtcTrascodingLiveStreamErrorCode)errCode;Parameters
Parameter | Type | Description |
streamURL | NSString * | The stream URL. |
state | The state. | |
errCode | The error code. |
onPublishTaskStateChanged
Callback for bypass task state changes.
- (void)onPublishTaskStateChanged:(NSString *_Nonnull)streamURL state:(AliRtcTrascodingLiveTaskStatus)state;Parameters
Parameter | Type | Description |
streamURL | NSString * | The stream URL. |
state | The state. |
onNetworkQualityChanged
Callback for network quality changes.
- (void)onNetworkQualityChanged:(NSString *_Nonnull)uid
upNetworkQuality:(AliRtcNetworkQuality)upQuality
downNetworkQuality:(AliRtcNetworkQuality)downQuality;Parameters
Parameter | Type | Description |
uid | NSString* | The user ID. If empty, it indicates the uplink and downlink network status of the local user. |
upQuality | The uplink network status. | |
downQuality | The downlink network status. |
onLastmileDetectResultWithQuality
Callback for network quality probing.
- (void)onLastmileDetectResultWithQuality:(AliRtcNetworkQuality)networkQuality;Parameters
Parameter | Type | Description |
networkQuality | The network quality. |
onLastmileDetectResultWithBandWidth
Callback for network quality probing results.
- (void)onLastmileDetectResultWithBandWidth:(int)code result:(AliRtcNetworkQualityProbeResult* _Nonnull)result;Parameters
Parameter | Type | Description |
code | int | The probing result. 0 indicates success. -1 indicates failure due to poor network conditions. |
result | The network quality. |
onOccurError
If an error occurs in the engine, this callback notifies the application.
- (void)onOccurError:(int)error message:(NSString *_Nonnull)message;Parameters
Parameter | Type | Description |
error | int | The error type. See {@link AliRtcErrorCode}. |
message | NSString * | The error description. |
onFirstAudioPacketSentWithTimecost
Callback for the first audio packet sent.
- (void)onFirstAudioPacketSentWithTimecost:(AliRtcAudioTrack)track timeCost:(int)timeCost;Parameters
Parameter | Type | Description |
track | The track. | |
timeCost | int | The time taken to send. |
onFirstVideoFrameReceivedWithUid
Callback for the first video frame received.
- (void)onFirstVideoFrameReceivedWithUid:(NSString *_Nonnull)uid
videoTrack:(AliRtcVideoTrack)videoTrack
timeCost:(int)timeCost;Description
Parameter | Type | Description |
uid | NSString * | The user ID. |
videoTrack | The video stream label. | |
timeCost | int | The time taken (in milliseconds). |
onFirstVideoPacketSentWithVideoTrack
Callback for the first video packet sent.
- (void)onFirstVideoPacketSentWithVideoTrack:(AliRtcVideoTrack)videoTrack
timeCost:(int)timeCost;Parameters
Parameter | Type | Description |
videoTrack | The video stream label. | |
timeCost | int | The time taken (in milliseconds). |
onFirstAudioPacketReceivedWithUid
Callback for the first audio packet received.
- (void)onFirstAudioPacketReceivedWithUid:(NSString *_Nonnull)uid
track:(AliRtcAudioTrack)track
timeCost:(int)timeCost;Parameters
Parameter | Type | Description |
uid | NSString * | The user ID. |
videoTrack | The audio stream label. | |
timeCost | int | The time taken (in milliseconds). |
onFirstRemoteAudioDecodedWithUid
Callback for the first decoded remote audio frame.
- (void)onFirstRemoteAudioDecodedWithUid:(NSString *_Nonnull)uid track:(AliRtcAudioTrack)track elapsed:(int)elapsed;Parameters
Parameter | Type | Description |
uid | NSString * | The user ID. |
track | The audio stream label. | |
elapsed | int | The time taken (in milliseconds). |
onFirstRemoteVideoFrameDrawn
This message is triggered when the first video frame of a remote user is displayed.
- (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 | The audio stream label. | |
width | int | The width. |
height | int | The height. |
elapsed | int | The total delay from when the local user joined the channel until this callback was triggered (in milliseconds). |
onFirstLocalVideoFrameDrawn
This message is triggered when the first video frame starts to display in the preview.
- (void)onFirstLocalVideoFrameDrawn:(int)width height:(int)height elapsed:(int)elapsed;Parameters
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 delay from when the local user joined the channel until this callback was triggered (in milliseconds). |
onTestAudioVolumeCallback
Volume callback for pre-call audio capture detection.
- (void)onTestAudioVolumeCallback:(int)volume;Parameters
Parameter | Type | Description |
volume | int | The volume [0..100]. |
onAudioAccompanyStateChanged
Callback for local audio mixing playback state.
- (void)onAudioAccompanyStateChanged:(AliRtcAudioAccompanyStateCode)playState
errorCode:(AliRtcAudioAccompanyErrorCode)errorCode;Parameters
Parameter | Type | Description |
playState | The status of the music accompaniment. | |
errorCode | The error code. |
onRemoteAudioAccompanyStarted
Callback for when a remote user starts audio mixing playback.
- (void)onRemoteAudioAccompanyStarted:(NSString *_Nonnull)uid;Parameters
Parameter | Type | Description |
uid | NSString * | The user ID. |
onRemoteAudioAccompanyFinished
Callback for when a remote user finishes audio mixing playback.
- (void)onRemoteAudioAccompanyFinished:(NSString *_Nonnull)uid;Parameters
Parameter | Type | Description |
uid | NSString * | The user ID. |
setParameter
Sets custom parameters.
- (int)setParameter:(NSString * _Nonnull)param;Metric descriptions
Parameter | Type | Description |
param | String | The custom parameter. |
getParameter
Retrieves custom parameters.
- (NSString * _Nonnull)getParameter:(NSString * _Nonnull)param;Parameters
Parameter | Type | Description |
param | String | The custom parameter. |
enableAudioFrameObserver
Sets audio callback parameters.
- (int)enableAudioFrameObserver:(bool)enable audioSource: (AliRtcAudioSource)audioSource config:(AliRtcAudioFrameObserverConfig*_Nullable)config;This method enables or disables callbacks for a specified type of audio data, which allows developers to retrieve various types of raw and encoded audio data. It is disabled by default. To enable it, you can call this method.
When you call this method to enable audio data callbacks for a specific AliRtcAudioSource, you must also use the registerAudioFrameObserver method to pass in an audio data receiving object.
When to call
You can call this method when you need to retrieve audio data.
Parameters
Parameter | Type | Description |
enable | bool | Whether to allow data callbacks. |
audioSource | The callback data source type. | |
config | AliRtcAudioFrameObserverConfig | The callback parameter settings. |
registerAudioFrameObserver
Registers for audio data output.
- (int)registerAudioFrameObserver:(id<AliRtcAudioFrameDelegate> _Nullable)observer;This method registers a receiving object for audio callback data.
When to call
When you need the SDK to trigger the onCapturedAudioFrame, onProcessCapturedAudioFrame, onPublishAudioFrame, onPlaybackAudioFrame, and onRemoteUserAudioFrame callbacks to retrieve various types of audio data, you need to call this method to provide an audio data receiving object. To unregister, you can call this method again and pass in nil.
Limits
You need to call enableAudioFrameObserver to enable callbacks for a specific AliRtcAudioSource. Otherwise, the passed observer does not receive data.
Metric descriptions
Parameter | Type | Description |
observer | AliRtcAudioFrameDelegate | The audio data callback. |
registerVideoSampleObserver
Registers for video data output.
- (void)registerVideoSampleObserver;unRegisterVideoSampleObserver
Unregisters from video data output.
- (void)unregisterVideoSampleObserver;setLogDirPath
Sets the path to save SDK log files.
You must call this method before you call any other SDK methods to avoid log loss. The application must 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 save log files.
|
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setLogLevel
Sets the log level.
- (void)setLogLevel:(AliRtcLogLevel)logLevel;Parameters
Name | Type | Description |
logLevel | The log level. The default is AliRtcLogLevelInfo. |
setAudioSessionOperationRestriction
Sets the SDK's control permissions for AVAudioSession.
- (int)setAudioSessionOperationRestriction:(AliRtcAudioSessionOperationRestriction)restriction;Parameters
Name | Type | Description |
restriction | The SDK's control permissions. The default is AliRtcAudioSessionOperationRestrictionNone. |
setDeviceOrientationMode
Sets the device orientation.
- (int)setDeviceOrientationMode:(AliRtcOrientationMode)mode;Metric descriptions
Name | Type | Description |
mode | The device orientation. |
Return value
0 indicates success. A non-zero value indicates failure.
getNetworkTime
Retrieves the timeline time.
-(long long)getNetworkTime;Return value
The timestamp.
sendDataChannelMessage
-(int) sendDataChannelMessage:(AliRtcDataChannelMsg* _Nonnull)controlMsg;The ARTC SDK provides the ability to send and receive custom messages, which allows real-time custom message data to be sent alongside audio and video data. You can call this method to send real-time control instructions, status synchronization data, or other business messages while you transmit audio and video. For specific usage, see Sending and receiving custom messages.
The custom message channel is disabled by default. To use this feature, you can call the
setParametermethod with ("{\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}}") to enable the custom message channel. This can be done before or after you join a channel.The message can be any data, such as text.
Related callbacks
After the sender successfully enables the custom message channel, they can call this method to send custom messages. The receiver retrieves the custom messages by listening to the
onDataChannelMessagecallback.
Limits
Streamers can send and receive messages. Viewers can only receive messages.
You need to call setParameter to enable the custom message channel.
Data sending is limited to:
A maximum bitrate of 30 KB/s.
The data channel can send a maximum of 60 data packets per second, with each packet up to 1 KB.
Parameters
Name | Type | Description |
controlMsg | Control message for accompaniment. |
Return value
0 indicates success. A non-zero value indicates failure.
startScreenShare
Starts sharing the screen and audio stream.
- (int)startScreenShare:(NSString * _Nonnull)appGroup
mode:(AliRtcScreenShareMode)mode;Parameters
Name | Description |
appGroup | The app's package name, such as @"group.com.aliyun.rtc.demo". |
mode | The screen sharing type. For more information, see AliRtcScreenShareMode.. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
startScreenShare
Starts sharing the screen video stream.
This method is about to be deprecated. Use the new method startScreenShare instead.
- (int)startScreenShare;Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
stopScreenShare
Stops the screen sharing stream, including the shared audio stream.
- (int)stopScreenShare;Response description
0 indicates that the method call was successful. A non-zero value indicates failure.
isScreenSharePublished
Checks whether screen sharing is being published.
- (BOOL)isScreenSharePublished;Return value
true: Screen sharing is being published. false: Screen sharing is not being published.
setScreenShareEncoderConfiguration
Sets the screen sharing encoder settings.
- (void)setScreenShareEncoderConfiguration:(AliRtcScreenShareEncoderConfiguration* _Nonnull)config;This method sets the video parameters for the screen stream video encoding properties, such as resolution, frame rate, bitrate, and video orientation. All set parameters have corresponding range limits. If a set parameter is outside the valid range, the SDK automatically adjusts it. This method can be called before or after you join a channel. To set the screen stream video encoding properties only once per session, we recommend that you call it before you join.
Parameters
Name | Type | Description |
config | The screen sharing video encoding parameters, such as resolution, frame rate, bitrate, and video orientation. All set parameters have corresponding range limits. If a set parameter is outside the valid range. |
setAudioShareAppVolume
Sets the volume of the shared audio stream.
- (int)setAudioShareAppVolume:(int)volume;Parameters
Name | Description |
volume | The volume level. The range is [0, 100]. The default value is 50. |
Return value
0 indicates that the method call was successful. A non-zero value indicates failure.
setGlobalEnvironment
Sets the global environment.
- (BOOL) setGlobalEnvironment:(AlivcGlobalEnv)env;This method specifies the SDK's global operating environment, which primarily affects the destination for log reporting and instrumentation data.
When set to the domestic environment, logs and instrumentation are reported to data centers in the Chinese mainland.
When set to the overseas environment, the relevant data is routed to data centers outside China, such as Singapore.
When to call
You can call this method early in the application's initialization.
Limits
This setting is global and needs to be called only once.
Calling it multiple times overwrites the previous environment configuration, but it may affect established connections or session states. Do not switch it dynamically during runtime.
Examples
var sdkEnv: AlivcGlobalEnv = .DEFAULT
let sdkEnvResult = AlivcBase.environmentManager.setGlobalEnvironment(self.sdkEnv)
"Set RTC environment to: \(sdkEnv) result: \(sdkEnvResult)".printLog()AlivcGlobalEnv env = AlivcGlobalEnv_DEFAULT;
AlivcBase.EnvironmentManager.globalEnvironment = env;Parameters
Parameter | Type | Description |
env |
| Specifies the global environment. The following enumeration values are supported: |
Return value
Returns an int type result code:
0: Indicates success.A non-
0value indicates failure.