translationSubscribed function

Future<void> translationSubscribed(
  1. TranslationSubscribedOptions options
)

Handles the translation:subscribed socket event. Called when successfully subscribed to a translation channel.

Implementation

Future<void> translationSubscribed(TranslationSubscribedOptions options) async {
  try {
    final data = options.data;

    // Update listen preferences
    options.updateListenPreferences?.call((prev) {
      final next = Map<String, String>.from(prev);
      next[data.speakerId] = data.language;
      return next;
    });

    // Update producer map if we have a producer ID
    if (data.producerId != null && data.originalProducerId != null) {
      options.updateTranslationProducerMap?.call((prev) {
        final next = Map<String, Map<String, String>>.from(prev);
        next[data.originalProducerId!] = {
          ...(next[data.originalProducerId!] ?? {}),
          data.language: data.producerId!,
        };
        return next;
      });
    }

    // Start consuming if producer is ready
    if (data.producerId != null && options.startConsumingTranslation != null) {
      await options.startConsumingTranslation!(data.producerId!, data.speakerId,
          data.language, data.originalProducerId ?? '');
    }

    if (data.channelCreated) {
      options.showAlert?.call(
        message:
            'Translation channel created for ${getLanguageName(data.language)}',
        type: 'success',
        duration: 2000,
      );
    }
  } catch (e) {
    // Handle error silently
  }
}