resumeOriginalProducer function

Future<void> resumeOriginalProducer(
  1. ResumeOriginalProducerOptions options
)

Resume the original audio producer consumer when translation stops.

NOTE: Only resumes if the speaker is in our breakout room. If they're not, their audio should stay paused (controlled by breakout room logic).

Implementation

Future<void> resumeOriginalProducer(
    ResumeOriginalProducerOptions 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 resumed
    if (!transport.consumer.paused) {
      return;
    }

    // Resume on server first
    transport.socket_.emitWithAck(
      'consumer-resume',
      {'serverConsumerId': transport.serverConsumerTransportId},
      ack: (response) {
        if (response is Map && response['resumed'] == true) {
          transport.consumer.resume();
        }
      },
    );
  } catch (e) {
    // Transport not found or other error - silently ignore
  }
}