process Consumer Transports Audio
Adjusts the audio state of consumer transports based on provided streams.
This function examines each audio consumer transport:
If a transport's
producerIdmatches an entry inlStreamsand is currently paused, it resumes the transport.If a transport's
producerIddoes not match any entry inlStreamsand is unpaused, it pauses the transport.The function incorporates a delay before pausing to allow for smoother transitions.
Parameters:
options(ProcessConsumerTransportsAudioOptions):consumerTransports: List of audio transports that may need to be paused or resumed.lStreams: List of streams that represent valid audio sources for the transports.parameters: Contains sleep function and getUpdatedAllParams method.
Behavior:
Pausing and Resuming: Pauses transports not found in
lStreamsand resumes those that are.Delay Handling: A short delay is added before pausing transports to optimize timing.
Socket Events: Emits
consumer-pauseandconsumer-resumeevents to synchronize states.
Example Usage:
val parameters = object : ProcessConsumerTransportsAudioParameters {
override val sleep = { options -> delay(options.ms) }
override fun getUpdatedAllParams() = this
}
processConsumerTransportsAudio(
ProcessConsumerTransportsAudioOptions(
consumerTransports = listOf(transport1, transport2),
lStreams = listOf(stream1, stream2),
parameters = parameters
)
)Error Handling:
Logs any errors encountered during the processing of transports.