consumers/translation_consumer_switch library
Translation Consumer Switch Utilities
Provides functions to switch between original audio and translated audio by pausing/resuming the appropriate consumers.
Key concepts:
- When a user subscribes to a translation, the original audio consumer should be paused
- When translation stops or user unsubscribes, resume the original audio consumer
- Translation producers are consumed via the regular pipe producer flow (newPipeProducer)
- We just need to pause/resume the original audio consumers
- IMPORTANT: Must respect breakout room state - don't resume audio for speakers not in our room
The consumer transports array contains objects with:
- consumerTransport: The mediasoup Transport object
- serverConsumerTransportId: ID on the server
- producerId: The producer being consumed
- consumer: The mediasoup Consumer object
- socket_: The socket used for this transport
Classes
- ActiveTranslationConsumer
- Active translation consumer info
- PauseOriginalProducerOptions
- Options for pausing original producer
- ResumeOriginalProducerOptions
- Options for resuming original producer
- StopConsumingTranslationOptions
- Options for stopping translation consumption
- TranslationConsumerSwitchParameters
- Parameters for translation consumer switch operations
- TranslationConsumptionStatus
- Result of checking if consuming translation for speaker
Functions
-
findOriginalProducerForSpeaker(
String speakerId, List< Map< allAudioStreams) → String?String, dynamic> > - Find the original producer ID for a speaker from all audio streams. This is needed when we receive a translation producer and need to pause the original.
-
getActiveTranslationConsumers(
Map< String, dynamic> translationProducerMap, List<TransportType> consumerTransports, Map<String, String> speakerIdByProducerId) → List<ActiveTranslationConsumer> - Get all active translation consumers from the map.
-
isConsumingTranslationForSpeaker(
String speakerId, List< TransportType> consumerTransports, Map<String, dynamic> translationProducerMap) → TranslationConsumptionStatus - Check if we're currently consuming a translation for a given speaker. Looks for consumers that have translation metadata attached.
-
isSpeakerInMyBreakoutRoom(
String speakerName, TranslationConsumerSwitchParameters parameters) → bool - Check if a speaker is in the current user's breakout room (or main room). Returns true if the speaker's audio should be active (they are in our room).
-
pauseOriginalProducer(
PauseOriginalProducerOptions options) → Future< void> - Pause the original audio producer consumer when switching to translation. This saves bandwidth by not receiving audio we won't use.
-
resumeOriginalProducer(
ResumeOriginalProducerOptions options) → Future< void> - Resume the original audio producer consumer when translation stops.
-
stopConsumingTranslation(
StopConsumingTranslationOptions options) → Future< String?> - Stop consuming a translation producer and close its consumer. Returns the original producer ID if found, so caller can resume it.
-
syncTranslationStateAfterBreakoutChange(
Map< String, dynamic> translationProducerMap, Map<String, String> speakerIdByProducerId, TranslationConsumerSwitchParameters parameters) → Future<void> - Handle breakout room changes for translation audio.
Typedefs
-
PauseOriginalProducerType
= Future<
void> Function(PauseOriginalProducerOptions options) -
ResumeOriginalProducerType
= Future<
void> Function(ResumeOriginalProducerOptions options) -
StopConsumingTranslationType
= Future<
String?> Function(StopConsumingTranslationOptions options)