import 'package:dating_touchme_app/model/rtc/rtc_channel_data.dart'; import 'package:dating_touchme_app/network/network_service.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; /// 通话相关控制器 class CallController extends GetxController { CallController({NetworkService? networkService}) : _networkService = networkService ?? Get.find(); final NetworkService _networkService; /// 当前频道信息 final Rxn rtcChannel = Rxn(); /// 是否正在创建频道 final RxBool isCreatingChannel = false.obs; /// 创建一对一RTC频道 /// [type] 1为音频,2为视频 Future createOneOnOneRtcChannel({required int type}) async { if (isCreatingChannel.value) { print('⚠️ 正在创建频道,请稍候'); return null; } // 验证 type 参数 if (type != 1 && type != 2) { SmartDialog.showToast('类型参数错误:1为音频,2为视频'); return null; } isCreatingChannel.value = true; try { final response = await _networkService.rtcApi.createOneOnOneRtcChannel({ 'type': type, }); if (response.data.isSuccess && response.data.data != null) { rtcChannel.value = response.data.data; print('✅ 创建一对一RTC频道成功: ${response.data.data?.channelId}'); return response.data.data; } else { final message = response.data.message.isNotEmpty ? response.data.message : '创建频道失败'; SmartDialog.showToast(message); print('❌ 创建一对一RTC频道失败: $message'); return null; } } catch (e) { final errorMessage = '创建频道异常:$e'; SmartDialog.showToast(errorMessage); print('❌ $errorMessage'); return null; } finally { isCreatingChannel.value = false; } } @override void onClose() { super.onClose(); rtcChannel.value = null; } }