pauseOriginalProducer function
- PauseOriginalProducerOptions options
Pause the original audio producer consumer when switching to translation. This saves bandwidth by not receiving audio we won't use.
NOTE: Only pauses if the speaker is in our breakout room. If they're not, their audio is already paused by the breakout room logic.
Implementation
Future<void> pauseOriginalProducer(PauseOriginalProducerOptions options) async {
try {
final originalProducerId = options.originalProducerId;
final speakerId = options.speakerId;
final parameters = options.parameters;
final consumerTransports = parameters.consumerTransports;
// If we have a speakerId, check if they're in our breakout room
if (speakerId != null &&
!isSpeakerInMyBreakoutRoom(speakerId, parameters)) {
return;
}
// Find the consumer transport for this original producer
final transport = consumerTransports.firstWhere(
(t) => t.producerId == originalProducerId && t.consumer.kind == 'audio',
orElse: () => throw Exception('Transport not found'),
);
// Check if already paused
if (transport.consumer.paused) {
return;
}
// Pause locally
transport.consumer.pause();
// Notify server
transport.socket_.emit(
'consumer-pause',
{'serverConsumerId': transport.serverConsumerTransportId},
);
} catch (e) {
// Transport not found or other error - silently ignore
}
}