AliRTCEngine interface

更新时间:
复制 MD 格式

This topic describes the Golang engine API for the ApsaraVideo for Media Streaming Linux SDK.

API reference

API

Description

CreateAliRTCEngine

Creates an AliRTCEngineInterface instance.

Release

Releases the AliRTCEngineInterface instance.

GetEventHandler

Gets the event handler.

JoinChannel

Joins a channel. This simplified method omits the nonce and timestamp parameters, simplifying integration with third-party SDKs.

LeaveChannel

Leaves the channel.

IsLocalVideoStreamPublished

Checks whether publishing the camera track is enabled.

IsLocalScreenPublishEnabled

Checks whether publishing the screen sharing stream is enabled.

IsLocalAudioStreamPublished

Checks whether publishing the audio track is enabled.

IsDualStreamPublished

Checks whether publishing simulcast for the camera track is enabled.

SetExternalVideoSource

Enables or disables an external video source.

PushExternalVideoFrame

Pushes external video frames. This method does not support video resolutions of 2K or higher.

SetExternalAudioSource

Enables or disables publishing from an external audio source.

PushExternalAudioFrameRawData

Pushes external raw audio data.

SetAudioProfile

Sets the audio profile.

SetExternalAudioPublishVolume

Sets the publishing volume of the external audio source.

GetExternalAudioPublishVolume

Gets the publishing volume of the external audio source.

SendMediaExtensionMsg

Sends SEI (Supplemental Enhancement Information). The maximum length is 4,096 bytes. Use this method to transmit small amounts of application data.

PublishLocalDualStream

Enables or disables publishing the secondary stream.

PublishLocalVideoStream

Enables or disables publishing the local video stream from the camera.

PublishLocalAudioStream

Enables or disables publishing the local audio stream.

PublishScreenShareStream

Enables or disables publishing the screen sharing stream.

SubscribeRemoteAudioStream

Stops or resumes subscribing to the audio stream of a specified remote user. Call this method after joining a channel.

SubscribeRemoteVideoStream

Stops or resumes subscribing to the video stream of a remote user. Call this method after joining a channel.

SetVideoEncoderConfiguration

Sets the video encoder configuration for the camera stream.

SetScreenShareEncoderConfiguration

Sets the video encoder configuration for the screen sharing stream.

SetRemoteVideoStreamType

Sets the subscribed video stream type to either the high-resolution stream or the low-resolution stream.

MuteLocalCamera

Mutes or unmutes the local video stream.

MuteLocalMic

Mutes or unmutes the local audio stream.

SetClientRole

Sets the user role.

SetRemoteDefaultVideoStreamType

Sets the default video stream type to subscribe to.

LeaveOnceNoStreamer

After joining a channel as an audience member, if all broadcasters in the channel stop publishing streams, the SDK immediately triggers the OnError callback with the ERR_NO_PEOPLE error code.

SetPeriodForCheckPeople

After joining a channel, if no other users join within a specified period, the SDK triggers the OnError callback with the ERR_NO_PEOPLE error code.

SetParameter

Sets custom configurations by using a JSON-formatted string, such as enabling or disabling the data channel.

GenerateToken

Locally generates the token for JoinChannel, bypassing app server authentication.

SendDataChannelMessage

Sends a message through the data channel.

OnError

Reports an error from the engine.

OnWarning

Reports a warning from the engine.

OnJoinChannelResult

Reports the result of joining a channel.

OnDataChannelMsg

Reports data received from a remote user through the data channel.

OnLeaveChannelResult

Reports the result of leaving a channel.

OnRemoteUserOnLineNotify

Occurs when a remote user joins the channel in communication mode, or when a broadcaster joins the channel in interactive mode.

OnRemoteUserOffLineNotify

Occurs when a remote user leaves the channel in communication mode, or when a broadcaster leaves the channel in interactive mode.

OnRemoteTrackAvailableNotify

Occurs when an audio or video track from a remote user becomes available or unavailable.

OnAudioSubscribeStateChanged

Reports a change in the audio subscription state.

OnVideoSubscribeStateChanged

Reports a change in the camera stream subscription state.

OnSubscribeStreamTypeChanged

Reports a change in the subscribed stream type (high-resolution stream or low-resolution stream).

OnScreenShareSubscribeStateChanged

Reports a change in the screen sharing stream subscription state.

OnScreenSharePublishStateChanged

Reports a change in the publishing state of the screen sharing stream.

OnDualStreamPublishStateChanged

Reports a change in the secondary stream publishing state.

OnVideoPublishStateChanged

Reports a change in the local video publishing state.

OnAudioPublishStateChanged

Reports a change in the local audio publishing state.

OnSubscribeAudioFrame

Provides the raw audio data from each remote user before it is mixed.

OnSubscribeMixAudioFrame

Provides the mixed audio data of all subscribed remote users.

OnRemoteVideoSample

Provides the raw video data from subscribed remote streams.

OnRemoteVideoEncodedSample

Provides the encoded video data from a remote user before it is decoded.

OnMediaExtensionMsgReceived

Occurs when an SEI message is received.

OnUpdateRoleNotify

Occurs when the user role changes.

OnSubscribeAudioAac

A custom callback for audio archiving that provides AAC-encoded audio from individual streams.

OnSubscribeMixedAudioAac

A custom callback for audio archiving that provides AAC-encoded audio from the mixed stream.

OnPushAudioFrameBufferFull

Indicates that the audio buffer is full, which can happen when audio data is pushed too quickly or at a non-uniform rate.

OnPushVideoFrameBufferFull

Indicates that the video buffer is full, which can happen when video data is pushed too quickly or at a non-uniform rate.

API

CreateAliRTCEngine

Creates an AliRTCEngineInterface instance.

func CreateAliRTCEngine(eventHandler EngineEventHandlerInterface, lowPort, highPort int, logPath, coreServicePath string, h5mode bool, extra string) AliRTCEngineInterface

Parameters

Parameter

Type

Description

eventHandler

EngineEventHandlerInterface *

The object that handles engine event callbacks.

lowPort

int

The lower limit of the port number range. A port is randomly selected from the range between lowPort and highPort for inter-process communication.

highPort

int

The upper limit of the port number range.

logPath

str

The path to the SDK's runtime log file.

coreServicePath

str

The path to AliRtcCoreService.

h5mode

bool

H5 compatibility mode. You can set this to false in most cases.

extra

str

A JSON-formatted string for additional SDK configurations.

Returns An AliRTCEngineInterface instance.

Release

Releases resources held by the AliRTCEngineInterface instance.

Release() error

GetEventHandler

Retrieves the event handler.

GetEventHandler() EngineEventHandlerInterface

Returns: The event handler instance.

JoinChannel

This syntactic sugar method joins a channel without requiring nonce and timestamp parameters, simplifying compatibility with third-party SDKs.

JoinChannel(token, channelId, userId, userName string, config *JoinChannelConfig) int
Important

This is an asynchronous method. To confirm if the join is successful, listen for the OnJoinChannelResult callback.

Parameters

Parameter

Type

Description

token

str

The authentication token used to join the channel.

channelId

str

The channel ID. It must match the channelId used to generate the token.

userId

str

The user ID. It must match the userId used to generate the token.

userName

str

The user's display name (not the user ID).

config

JoinChannelConfig

Optional settings for joining the channel.

Returns A return value of 0 indicates the method call succeeded. Any non-zero value indicates failure.

LeaveChannel

Leaves a channel.

LeaveChannel() int

Returns

IsLocalVideoStreamPublished

Checks if the camera track is published.

IsLocalVideoStreamPublished() bool

Returns
true if the camera track is published; false otherwise.

IsLocalScreenPublishEnabled

Checks if publishing the local screen track is enabled.

IsLocalScreenPublishEnabled() bool

return value
true if publishing is enabled; false otherwise.

IsLocalAudioStreamPublished

Checks if publishing the local audio track is allowed.

IsLocalAudioStreamPublished() bool

Returns: true if publishing is allowed; false otherwise.

IsDualStreamPublished

Checks if simulcast publishing for the camera track is enabled.

IsDualStreamPublished() bool

Returns true if enabled; false otherwise.

SetExternalVideoSource

Enables the external video source.

SetExternalVideoSource(enable bool, sourceType VideoSource, renderMode RenderMode) int

Once enabled, use the PushExternalVideoFrame method to push video data.

Parameters

Parameter

Type

Description

enable

bool

true enables the external video source, and false disables it.

sourceType

VideoSource

Specifies the stream type.

renderMode

RenderMode

Specifies the render mode.

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

PushExternalVideoFrame

Pushes an external video frame. Video resolutions of 2K or higher are not supported.

PushExternalVideoFrame(frame *VideoDataSample, sourceType VideoSource) int

Input video frames can be in multiple formats, such as YUV and RGB.

Parameters

Parameter

Type

Description

frame

VideoDataSample

The frame data.

sourceType

VideoSource

The stream type.

Returns A return value of 0 indicates a successful call. Any other value indicates a failed call. If the method returns ERR_AUDIO_BUFFER_FULL, adjust the sending rate.

SetExternalAudioSource

Enables or disables publishing from an external audio source.

SetExternalAudioSource(enable bool, sampleRate, channelsPerFrame int) int

Call SetExternalAudioPublishVolume to set the publish volume.

Parameters

Parameter

Type

Description

enable

bool

Specifies whether to enable the external audio source:

sampleRate

int

The sample rate of the external audio source, in Hz. For example, 16000 or 48000.

channelsPerFrame

int

The number of audio channels. For example, 1 for mono or 2 for stereo.

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

PushExternalAudioFrameRawData

Pushes external audio data for streaming.

PushExternalAudioFrameRawData(audioSamples []byte, sampleLength int, timestamp int64) int

Parameters

Parameter

Type

Description

audioSamples

bytes

The audio data.

sampleLength

int

The audio data length.

timestamp

int

The timestamp of the audio data.

Returns A return value of 0 indicates success; any other value indicates failure. If ERR_AUDIO_BUFFER_FULL is returned, retry the operation after a delay equal to the audio data's duration.

SetAudioProfile

Sets the audio profile.

SetAudioProfile(audioProfile AudioQualityMode, audioScene AudioSceneMode) int

Parameters

Parameter

Type

Description

audioProfile

AudioQualityMode

Specifies the settings for audio capture and encoding.

audioScene

AudioSceneMode

Specifies the audio scene mode.

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

SetExternalAudioPublishVolume

Sets the publishing volume of the external audio input.

SetExternalAudioPublishVolume(volume int) int

Parameters

Parameter

Type

Description

volume

int

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

Returns A return value of 0 indicates a successful method call; any other value indicates a failure.

GetExternalAudioPublishVolume

Gets the volume for mixing external audio into the published stream.

GetExternalAudioPublishVolume() int

Returns
The mixing volume.

SendMediaExtensionMsg

Sends Supplemental Enhancement Information (SEI) containing small amounts of application data. The maximum length is 4,096 bytes.

SendMediaExtensionMsg(message []byte, length, repeatCount, delay int, isKeyFrame bool) int

Parameters

Parameter

Type

Description

message

bytes

The SEI payload.

length

int

The length of the SEI message, in bytes.

repeatCount

int

The number of times to repeat the message to mitigate message loss caused by network packet loss.

delay

int

The delay before sending the message, in milliseconds.

isKeyFrame

bool

Set to true to attach the SEI only to keyframes.

Returns 0 on success. Any other value indicates failure.

PublishLocalDualStream

Enables or disables publishing the secondary video stream.

PublishLocalDualStream(enabled bool) int

The secondary video stream is published only if the primary video stream is also being published. Before enabling the secondary video stream, call the PublishLocalVideoStream method to publish the primary video stream. By default, the SDK does not publish the secondary video stream. You can call this method before joining a channel to change this default setting. This setting takes effect when you start publishing the primary video stream.

Parameters

Parameter

Type

Description

enabled

bool

Whether to enable the secondary video stream.

Returns

PublishLocalVideoStream

Enables or disables publishing the local video stream from the camera.

PublishLocalVideoStream(enabled bool) int

By default, the SDK publishes the local video stream. Call this method before joining a channel to change this setting. This setting takes effect after you join a channel.

Parameters

Parameter

Type

Description

enabled

bool

Specifies whether to publish the local video stream.

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

PublishLocalAudioStream

Enables or disables publishing the local audio stream.

PublishLocalAudioStream(enabled bool) int

By default, the SDK publishes the local audio stream. You can call this method before joining a channel to change this default setting. The change takes effect after you join the channel.

Parameters

Parameter

Type

Description

enabled

bool

Whether to publish the local audio stream.

Returns A return value of 0 indicates the method call succeeded; any other value indicates it failed.

PublishScreenShareStream

Starts publishing the screen share stream.

PublishScreenShareStream(enabled bool) int

Parameters

Parameter

Type

Description

enabled

bool

Specifies whether to publish the screen share stream. Set to true to start publishing the stream, or false to stop publishing.

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

SubscribeRemoteAudioStream

Subscribes to or unsubscribes from the audio stream of a specified remote user. You must join a channel before calling this method.

SubscribeRemoteAudioStream(uid string, sub bool) int

Parameters

Parameter

Type

Description

uid

str

The unique user ID of the remote user, assigned by the application server.

sub

bool

Specifies whether to subscribe to the remote user's audio stream.

Returns A return value of 0 indicates success; any other value indicates failure.

SubscribeRemoteVideoStream

Subscribes to or unsubscribes from the video stream of a specified remote user. You must call this method during a call. Calling it before joining a channel has no effect.

SubscribeRemoteVideoStream(uid string, videoTrack VideoTrack, sub bool) int

Parameters

Parameter

Type

Description

uid

string

The user ID of the remote user. Your application server assigns this unique identifier.

videoTrack

VideoTrack

The video stream type.

sub

bool

Specifies whether to subscribe to the remote user's video stream.

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

SetVideoEncoderConfiguration

Sets the video encoder configuration for the camera stream.

SetVideoEncoderConfiguration(config AliEngineVideoEncoderConfiguration) int

This method sets video parameters for the camera stream, such as resolution, frame rate, bitrate, and video orientation. If you set a parameter outside its valid range, the SDK automatically adjusts it. You can call this method either before or after you join a meeting. If you only need to set the video encoder configuration once per meeting, call this method before joining the meeting.

Parameters

Parameter

Type

Description

config

AliEngineVideoEncoderConfiguration

The video encoder configuration. For details, see AliEngineVideoEncoderConfiguration.

SetScreenShareEncoderConfiguration

Sets the screen share encoder configuration.

SetScreenShareEncoderConfiguration(config AliEngineScreenShareEncoderConfiguration) int

Sets the video parameters for the screen share, such as resolution, frame rate, bitrate, and video orientation. All parameters have valid ranges. If you set a parameter outside its valid range, the SDK automatically adjusts it to a supported value. You can call this method either before or after you join a meeting. If you only need to set the encoder configuration once per meeting, call this method before you join the meeting.

Parameters

Parameter

Type

Description

config

AliEngineScreenShareEncoderConfiguration

The predefined screen share encoder configuration. For details, see AliEngineScreenShareEncoderConfiguration.

SetRemoteVideoStreamType

Sets the type of remote camera stream to receive: the high-resolution stream or the low-resolution stream.

SetRemoteVideoStreamType(uid string, streamType AliEngineVideoStreamType) int

By default, a publisher does not send the low-resolution stream. A subscriber can subscribe to either the high-resolution or low-resolution stream only after the publisher enables dual-stream mode by calling PublishLocalDualStream(true). Otherwise, the subscriber can only receive the high-resolution stream.

Parameters

Parameter

Type

Description

uid

str

The unique identifier for the user, assigned by your application server.

streamType

AliEngineVideoStreamType

Specifies the stream type. - AliEngineVideoStreamTypeNone: Invalid parameter. This setting has no effect. - AliEngineVideoStreamTypeHigh: The high-resolution stream. - AliEngineVideoStreamTypeLow: The low-resolution stream.

Returns 0 indicates the method call succeeded. A non-zero value indicates the method call failed.

MuteLocalCamera

Mutes or unmutes the local video stream.

MuteLocalCamera(mute bool) int

Parameters

Parameter

Type

Description

mute

bool

true to mute the local video stream; false to unmute.

Return value A return value of 0 indicates a successful method call; any other value indicates failure.

MuteLocalMic

Mutes or unmutes the local audio.

MuteLocalMic(mute bool) int

Parameters

Parameter

Type

Description

mute

bool

Whether to mute the local audio.

Returns 0 on success; any other value indicates failure.

SetClientRole

Sets the user role.

SetClientRole(clientRole AliEngineClientRole) int

This method can be called only when the channel profile is AliRtcChannelProfileCommunication. You can set the user role either before or after joining a channel. A successful change triggers the onUpdateRoleNotify callback. To switch a user's role from Interactive to Live, you must first stop stream publishing. Otherwise, the method call fails. When the channel profile is AliRtcChannelProfileInteractiveLive, the default user role is AliRtcClientRoleLive.

Parameters

Parameter

Type

Description

clientRole

AliEngineClientRole

The user role.

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

SetRemoteDefaultVideoStreamType

Sets the default video stream type for subscriptions.

SetRemoteDefaultVideoStreamType(streamType AliEngineVideoStreamType) int

Parameters

Parameter

Type

Description

streamType

AliEngineVideoStreamType

The video stream type: high-quality stream or low-quality stream.

Return valuesA return value of 0 indicates success. Any other value indicates failure.

LeaveOnceNoStreamer

After you join a room in audience mode, the SDK triggers the OnError callback with the ERR_NO_PEOPLE error code if all streamers stop publishing.

LeaveOnceNoStreamer(enable bool) int

This feature is designed for moderation scenarios.

Parameters

Parameter

Type

Description

enable

bool

Enables or disables this feature. true: Enable. false: Disable.

SetPeriodForCheckPeople

After a user joins a channel, the SDK triggers the OnError callback with the ERR_NO_PEOPLE error code if no other users join within the specified period.

SetPeriodForCheckPeople(seconds int) int

Consequently, the join fails, and the OnJoinChannelResult callback returns -1. This feature is designed for moderation scenarios. By default, the maximum duration for checking an empty room is 5 seconds.

Parameters

Parameter

Type

Description

seconds

int

The maximum time in seconds to check for an empty room. A value of 0 or less disables this feature.

SetParameter

Sets a custom configuration using a JSON-formatted string. For example, you can use this method to enable or disable the dataChannel.

SetParameter(params string) int

Parameters

Parameter

Type

Description

params

string

The custom configuration.

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

Generate token

Generates the token required by JoinChannel. This method allows you to generate the token locally, bypassing the app server for authentication.

GenerateToken(authInfo AuthInfo, appkey string) string

Use this token to authenticate a user when they join a channel.

Parameters

Parameter

Type

Description

authInfo

AuthInfo

An object that contains custom configuration. You must populate its appid, nonce, and timestamp fields before calculating the token.

appkey

str

The key corresponding to the appid, required to calculate the token.

SendDataChannelMessage

Sends data through the data channel.

SendDataChannelMessage(ctrlMsg AliEngineDataChannelMsg) int
Note

The ARTC data channel feature requires an active audio or video stream. Ensure you publish an audio or video stream.

Limitations

  • Users with the host role can send and receive messages. Users with the audience role can only receive messages.

  • You must call setParameter to enable the custom message channel.

  • The following limits apply to data transmission:

    • The maximum bitrate is 30 KB/s.

    • The data channel supports a maximum of 60 data packets per second, with each packet up to 1 KB.

Parameters

Parameter

Type

Description

ctrlMsg

AliEngineDataChannelMsg

Contains the data to send and any control instructions.

Returns 0 indicates success. Any other value indicates failure.

OnError

Notifies your application when the engine encounters an error.

OnError(errorCode ErrorCode)

Parameters

Parameter

Type

Description

error_code

ERROR_CODE

Indicates the type of error that occurred.

OnWarning

Notifies the business layer of warnings from the engine.

OnWarning(warningCode WarningCode)

Parameter description

Parameter

Type

Description

warning_code

WarningCode

Warning type

OnJoinChannelResult

Reports the result of joining a channel.

OnJoinChannelResult(result int, channel, userId string)

After the application calls the JoinChannel method, the SDK triggers this callback to report the result of joining the channel.

Parameters

Parameter

Type

Description

result

int

The result of joining the channel. A value of 0 indicates success, while a non-zero value is an error code.

channel

string

The channel ID.

userId

string

The user ID.

OnDataChannelMsg

Occurs when a message is received from a remote user through the data channel.

OnDataChannelMsg(uid string, msg AliEngineDataChannelMsg)
Note

The ARTC data channel requires an active audio and video stream. To send a message, you must publish a stream. To receive a message, you must subscribe to a stream.

Parameters

Parameter

Type

Description

uid

string

The user ID of the message sender.

msg

AliEngineDataChannelMsg

The message received from the remote user.

OnLeaveChannelResult

Reports the result of leaving a channel.

OnLeaveChannelResult(result int)

When your app calls the LeaveChannel method, the SDK triggers this callback to report the result of leaving the channel. If you destroy the SDK instance immediately after calling LeaveChannel, you will not receive this callback.

Parameters

Parameter

Type

Description

result

int

The result of leaving the channel. A value of 0 indicates success, and a non-zero value is an error code.

OnRemoteUserOnLineNotify

Occurs when a remote user in communication mode, or a broadcaster in interactive mode, joins a channel.

OnRemoteUserOnLineNotify(uid string)

The SDK triggers this callback in the following scenarios:

  1. In communication mode: The SDK triggers this callback when a remote user joins the channel. If other users are already in the channel when the local user joins, the SDK also triggers this callback for each existing user.

  2. In interactive mode:

    1. The SDK triggers this callback when a remote user with the broadcaster role joins the channel. If other broadcasters are already in the channel when the local user joins, the SDK also triggers this callback for each existing broadcaster.

    2. The SDK triggers this callback when a remote user with the audience role calls SetClientRole to switch their role to broadcaster (AliEngineClientRoleInteractive).

Callback behavior in interactive mode:

  1. Broadcasters receive this callback when other broadcasters join the channel.

  2. Audience members receive this callback when broadcasters join the channel.

  3. Broadcasters do not receive this callback when audience members join the channel.

Parameters

Parameter

Type

Description

uid

string

The user ID. This is a unique identifier assigned by your app server.

OnRemoteUserOffLineNotify

Triggered when a remote user in communication mode or a broadcaster in interactive mode leaves the channel.

OnRemoteUserOffLineNotify(uid string)

The SDK triggers this callback in the following scenarios:

  1. In communication mode: When a remote user leaves the channel.

  2. In interactive mode:

    1. When a remote user with the broadcaster role (AliEngineClientRoleInteractive) leaves the channel.

    2. When a remote broadcaster calls SetClientRole to switch their role to audience (AliEngineClientRoleLive).

For users in communication mode and for broadcasters in interactive mode, the SDK also triggers this callback when a remote user times out. A timeout occurs if the SDK does not receive data from the user for an extended period.

Parameters

Parameter

Type

Description

uid

str

The unique user ID of the user who has left the channel, assigned by your app server.

OnRemoteTrackAvailableNotify

Occurs when a remote user's audio or video track becomes available or unavailable.

OnRemoteTrackAvailableNotify(uid string, audioTrack AudioTrack, videoTrack VideoTrack)

This callback is triggered in the following scenarios:

  1. A remote user starts publishing an audio or video track.

  2. A remote user stops publishing an audio or video track.

  3. In interactive mode, a user calls SetClientRole to switch to the broadcaster role (AliEngineClientRoleInteractive) and starts publishing a track.

This callback is triggered only for users in communication mode and for broadcasters in interactive mode.

Parameters

Parameter

Type

Description

uid

str

The unique user ID assigned by your application server.

audioTrack

AudioTrack

The audio track. For details, see AudioTrack.

videoTrack

VideoTrack

The video track. For details, see VideoTrack.

OnAudioSubscribeStateChanged

Fires when the audio subscription state changes.

OnAudioSubscribeStateChanged(uid string, oldState, newState AliEngineSubscribeState, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

uid

str

The unique identifier of the remote user, assigned by your application server.

oldState

AliEngineSubscribeState

The previous subscription state. For details, see AliEngineSubscribeState: Subscription state.

newState

AliEngineSubscribeState

The current subscription state. For details, see AliEngineSubscribeState: Subscription state.

elapseSinceLastState

int

The time elapsed (in milliseconds) since the last state change.

channel

str

The ID of the channel.

OnVideoSubscribeStateChanged

Occurs when the camera stream subscription state changes.

OnVideoSubscribeStateChanged(uid string, oldState, newState AliEngineSubscribeState, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

uid

str

The user ID of the remote user, assigned by your application server.

oldState

AliEngineSubscribeState

The previous subscription state. For details, see AliEngineSubscribeState: subscription state.

newState

AliEngineSubscribeState

The current subscription state. For details, see AliEngineSubscribeState: subscription state.

elapseSinceLastState

int

The elapsed time (in milliseconds) since the last state change.

channel

str

The current channel ID.

OnSubscribeStreamTypeChanged

Occurs when the subscribed stream type changes.

OnSubscribeStreamTypeChanged(uid string, oldStreamType, newStreamType AliEngineVideoStreamType, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

uid

str

The user ID, a unique identifier assigned by your App server.

oldStreamType

AliEngineVideoStreamType

The previous stream type. For details, see AliEngineVideoStreamType: video stream type.

newStreamType

AliEngineVideoStreamType

The current stream type. For details, see AliEngineVideoStreamType: video stream type.

elapseSinceLastState

int

Time elapsed since the last stream type change, in milliseconds.

channel

str

The current channel ID.

OnScreenShareSubscribeStateChanged

Triggered when the subscription state of the screen sharing stream changes.

OnScreenShareSubscribeStateChanged(uid string, oldState, newState AliEngineSubscribeState, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

uid

str

The user's unique identifier, assigned by your app server.

oldState

AliEngineSubscribeState

The previous subscription state. For details, see AliEngineSubscribeState: Subscription state.

newState

AliEngineSubscribeState

The current subscription state. For details, see AliEngineSubscribeState: Subscription state.

elapseSinceLastState

int

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

channel

str

The current channel ID.

OnScreenSharePublishStateChanged

Triggered when the screen sharing publish state changes.

OnScreenSharePublishStateChanged(oldState, newState AliEnginePublishState, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

oldState

AliEnginePublishState

The previous publish state.

newState

AliEnginePublishState

The current publish state.

elapseSinceLastState

int

Elapsed time, in milliseconds, since the last state change.

channel

string

The ID of the current channel.

OnDualStreamPublishStateChanged

Called when the publishing state of the secondary stream changes.

OnDualStreamPublishStateChanged(oldState, newState AliEnginePublishState, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

oldState

AliEnginePublishState

The previous publishing state.

newState

AliEnginePublishState

The current publishing state.

elapseSinceLastState

int

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

channel

str

The current channel ID.

OnVideoPublishStateChanged

Triggered when the video publish state changes.

OnVideoPublishStateChanged(oldState, newState AliEnginePublishState, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

oldState

AliEnginePublishState

The previous publish state.

newState

AliEnginePublishState

The current publish state.

elapseSinceLastState

int

Elapsed time in milliseconds since the last state change.

channel

string

The channel ID.

OnAudioPublishStateChanged

Indicates that the audio publish state has changed.

OnAudioPublishStateChanged(oldState, newState AliEnginePublishState, elapseSinceLastState int, channel string)

Parameters

Parameter

Type

Description

oldState

AliEnginePublishState

The previous publish state.

newState

AliEnginePublishState

The current publish state.

elapseSinceLastState

int

Time elapsed since the last state change.

channel

string

The channel ID.

onSubscribeAudioFrame

Provides the raw audio data from each remote user before audio mixing.

OnSubscribeAudioFrame(uid string, frame AudioFrame)

The audio data in this callback is from a single remote user. For details, see AudioFormatPcmBeforMixing.

Parameters

Parameter

Type

Description

uid

str

The remote user ID.

frame

AudioFrame

The audio frame. For details, see the AudioFrame class.

OnSubscribeMixAudioFrame

This callback provides the mixed audio data that the local user has subscribed to.

OnSubscribeMixAudioFrame(frame AudioFrame)

This is the mixed audio from all remote users, ready for playback. For details, see AudioFormatMixedPcm.

Parameters

Parameter

Type

Description

frame

AudioFrame

The audio frame. See AudioFrame: Audio frame class.

OnRemoteVideoSample

Provides the remote video data from a user you have subscribed to.

OnRemoteVideoSample(uid string, frame VideoFrame)

Parameters

Parameter

Type

Description

uid

string

The user ID of the remote user.

frame

VideoFrame

An object containing the raw video data.

OnRemoteVideoEncodedSample

Occurs when the SDK receives an encoded video sample from a subscribed remote user before decoding.

OnRemoteVideoEncodedSample(uid string, frame VideoFrame)

Parameters

Parameter

Type

Description

uid

str

The user ID.

frame

VideoFrame

The encoded video sample, a NALU.

OnMediaExtensionMsgReceived

Occurs when a media extension message is received.

OnMediaExtensionMsgReceived(userid string, message []byte, size int)

When a party calls SendMediaExtensionMsg, other parties receive the message through this callback.

Parameters

Parameter

Type

Description

userid

str

The sender's user ID.

message

bytes

The content of the extension message.

size

int

The length of the extension message.

OnUpdateRoleNotify

Occurs when the user role changes.

OnUpdateRoleNotify(oldRole, newRole AliEngineClientRole)

The SDK triggers this callback after you successfully call SetClientRole.

Parameters

Parameter

Type

Description

oldRole

AliEngineClientRole

The previous user role. For details, see AliEngineClientRole: user role type.

newRole

AliEngineClientRole

The new user role. For details, see AliEngineClientRole: user role type.

OnSubscribeAudioAac

A custom audio archiving callback that provides the AAC-transcoded audio data for each subscribed stream.

OnSubscribeAudioAac(uid string, frame AudioFrame)

Parameters

Parameter

Type

Description

uid

string

The remote user ID.

frame

AudioFrame

The audio frame containing the AAC-transcoded audio data. For details, see AudioFrame: Audio frame class.

OnSubscribeMixedAudioAac

A callback for custom audio archiving that provides mixed audio data transcoded to the AAC format.

OnSubscribeMixedAudioAac(frame AudioFrame)

Parameters

Parameter

Type

Description

frame

AudioFrame

Mixed audio data transcoded to the AAC format. For details, see AudioFrame.

OnPushAudioFrameBufferFull

The SDK triggers this callback when audio data is pushed too fast or unevenly, filling the audio buffer.

OnPushAudioFrameBufferFull(isFull bool)

Parameters

Parameter

Type

Description

isFull

bool

Indicates whether the audio buffer is full. If true, wait briefly before pushing more audio data.

OnPushVideoFrameBufferFull

Triggered when the SDK's video buffer fills up because video data is pushed too fast or at a non-uniform rate.

OnPushVideoFrameBufferFull(isFull bool)

Parameters

Parameter

Type

Description

isFull

bool

Indicates whether the SDK's video buffer is full. If true, temporarily stop pushing video data.