translationError function

Future<void> translationError(
  1. TranslationErrorOptions options
)

Handles the translation:error socket event. Called when a translation operation fails.

Implementation

Future<void> translationError(TranslationErrorOptions options) async {
  try {
    final data = options.data;
    String message = data.error;

    // Provide user-friendly messages for known error codes
    switch (data.code) {
      case 'max_channels':
        if (data.availableChannels != null &&
            data.availableChannels!.isNotEmpty) {
          message =
              'Maximum ${data.maxChannels ?? 5} translation channels reached. Available: ${data.availableChannels!.join(', ')}';
        } else {
          message = data.message ??
              'Maximum translation channels reached. Please wait for a slot to open.';
        }
        break;
      case 'speaker_not_found':
        message = 'Speaker not found or has left the meeting.';
        break;
      case 'language_not_allowed':
        message =
            'This language is not available for translation in this room.';
        break;
      default:
        message =
            data.error.isNotEmpty ? data.error : 'Translation error occurred';
    }

    options.showAlert?.call(
      message: message,
      type: 'danger',
      duration: 5000,
    );
  } catch (e) {
    // Handle error silently
  }
}