enableSendMediaStream controls whether the client sends audio or video media streams to the AI service, giving you precise control over when media transmission starts in AOQ protocol scenarios.
Overview
enableSendMediaStream controls whether the client sends audio or video media streams to the AI service. In AOQ protocol scenarios, some models require a session.updated confirmation before they can accept media data. Use this API to start sending at the right time.
API definition
iOS / Mac
// iOS / Mac
func enableSendMediaStream(_ trackType: AoqTrackType, enable: Bool)Android
// Android
void enableSendMediaStream(AoqTrackType trackType, boolean enable)HarmonyOS (ArkTS)
// HarmonyOS (ArkTS)
enableSendMediaStream(trackType: AoqTrackType, enable: boolean): voidParameters:
Parameter | Type | Description |
trackType | AoqTrackType | Media track type: |
enable | Bool |
|
Control flow
A typical media stream control flow is as follows:
Example (iOS Swift)
Disable sending before connect
// Disable audio and video sending before connecting to prevent the model
// from receiving data before it is ready
engine.enableSendMediaStream(.audio, enable: false)
engine.enableSendMediaStream(.video, enable: false)
// Initiate the connection
engine.connect(config)Enable after receiving session.updated
func onDataMsg(_ msg: AoqDataMsg) {
guard let obj = try? JSONSerialization.jsonObject(with: msg.data) as? [String: Any],
let type = obj["type"] as? String else { return }
if type == "session.updated" {
// The AI has confirmed the session configuration; start sending media
engine.enableSendMediaStream(.audio, enable: true)
engine.enableSendMediaStream(.video, enable: true)
}
}Important notes
When to call: Must be called after
createEngine. Calling before the engine is created has no effect.Default behavior: If this API is not called, the SDK starts sending media streams immediately after a successful connection.
Model compatibility: Some models require a
session.updatedevent before they accept media data. Use the "disable first, then enable" pattern for maximum compatibility.Independent control: Audio and video can be controlled independently — for example, you can send audio without sending video.
Common scenarios
Scenario | Action | Description |
Before connecting to the model |
| Wait for session.updated before sending |
After receiving session.updated |
| AI is ready; start sending |