processConsumerTransportsAudio

Adjusts the audio state of consumer transports based on provided streams.

This function examines each audio consumer transport:

  • If a transport's producerId matches an entry in lStreams and is currently paused, it resumes the transport.

  • If a transport's producerId does not match any entry in lStreams and 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 lStreams and resumes those that are.

  • Delay Handling: A short delay is added before pausing transports to optimize timing.

  • Socket Events: Emits consumer-pause and consumer-resume events 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.