Browse Source
feat(rtc): 添加一对一RTC频道功能
feat(rtc): 添加一对一RTC频道功能
- 在api_urls.dart中新增createOneOnOneRtcChannel API路径 - 创建新的CallController用于管理通话相关逻辑 - 实现createOneOnOneRtcChannel方法支持音频视频通话 - 将call_manager.dart从message目录移动到rtc目录 - 在CallManager中集成RTC频道创建流程 - 更新通话消息发送逻辑包含频道ID信息 - 调整相关页面和组件的导入路径以适配目录变更 - 修复user_api.g.dart中的API路径格式问题master
11 changed files with 143 additions and 8 deletions
Unified View
Diff Options
-
68lib/controller/message/call_controller.dart
-
5lib/controller/message/chat_controller.dart
-
2lib/im/im_manager.dart
-
2lib/network/api_urls.dart
-
6lib/network/rtc_api.dart
-
34lib/network/rtc_api.g.dart
-
2lib/network/user_api.g.dart
-
2lib/pages/message/chat_page.dart
-
2lib/pages/message/video_call_page.dart
-
26lib/rtc/call_manager.dart
-
2lib/widget/message/video_call_overlay_widget.dart
@ -0,0 +1,68 @@ |
|||||
|
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<NetworkService>(); |
||||
|
|
||||
|
final NetworkService _networkService; |
||||
|
|
||||
|
/// 当前频道信息 |
||||
|
final Rxn<RtcChannelData> rtcChannel = Rxn<RtcChannelData>(); |
||||
|
|
||||
|
/// 是否正在创建频道 |
||||
|
final RxBool isCreatingChannel = false.obs; |
||||
|
|
||||
|
/// 创建一对一RTC频道 |
||||
|
/// [type] 1为音频,2为视频 |
||||
|
Future<RtcChannelData?> 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; |
||||
|
} |
||||
|
} |
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save