stream Success Audio Switch
Manages switching to a new audio stream, updating the audio producer, local streams, and UI state as necessary.
This function handles the transition to a new audio stream by performing several key actions:
Audio Device Check: Checks if the audio device has changed. If so, it closes the current audio producer, updates the audio device ID, and prepares the new audio stream for transmission.
Local Stream Update: Updates
localStreamandlocalStreamAudiowith the new audio track.Transport Handling: Creates a new audio send transport if one does not exist; otherwise, it connects to the existing transport with the updated audio parameters.
UI and Event Handling: Updates UI elements based on user level, screen lock status, and if video is already on.
Workflow:
Extract Audio Track: Gets the audio track and device ID from the new stream
Device Change Detection: Compares new device ID with current device ID
Producer Management: Closes existing producer if device changed
Socket Emission: Pauses audio on the server side
Stream Updates: Updates local audio streams
Transport Handling: Creates or connects transport as needed
Pause Handling: Pauses producer if audio was paused
UI Refresh: Updates UI if needed based on user level
Parameters
Options containing the new audio stream and parameters
Example:
val options = StreamSuccessAudioSwitchOptions(
stream = newAudioStream,
parameters = streamSuccessAudioSwitchParams,
audioConstraints = mapOf("echoCancellation" to true)
)
streamSuccessAudioSwitch(options)Note:
Matches Flutter's stream_success_audio_switch.dart implementation.