Browse Source

feat(call): 实现通话拒绝功能和优化消息处理

- 将 _handleRtmMessage 方法改为异步方法以支持异步操作
- 添加对 reject 消息的处理逻辑,包括取消频道订阅和关闭通话界面
- 实现拒绝通话时调用RTC接口并发送拒绝消息到RTM频道
- 优化 channelId 验证逻辑,避免空值导致的错误
- 添加通话拒绝时的音频停止和会话清理功能
master
Jolie 3 months ago
parent
commit
b6e2d5b8de
1 changed files with 64 additions and 5 deletions
  1. 69
      lib/controller/message/call_controller.dart

69
lib/controller/message/call_controller.dart

@ -128,7 +128,7 @@ class CallController extends GetxController {
}
/// RTM
void _handleRtmMessage(MessageEvent event) {
Future<void> _handleRtmMessage(MessageEvent event) async {
try {
//
String messageText;
@ -161,9 +161,33 @@ class CallController extends GetxController {
} else if (event == 'hangup') {
// 退
print('📞 [CallController] 收到 hangup 消息,执行退出逻辑');
RTMManager.instance.unsubscribe(messageData['channelId']);
final channelId = messageData['channelId'] as String?;
if (channelId != null && channelId.isNotEmpty) {
RTMManager.instance.unsubscribe(channelId);
}
SmartDialog.dismiss(tag: 'video_call_invite_dialog');
_handleHangupMessage();
} else if (event == 'reject') {
// reject 退
print('📞 [CallController] 收到 reject 消息,执行退出逻辑');
final channelId = messageData['channelId'] as String?;
if (channelId != null && channelId.isNotEmpty) {
RTMManager.instance.unsubscribe(channelId);
print('✅ [CallController] 已取消订阅 RTM 频道: $channelId');
}
//
if (Get.isRegistered<OverlayController>()) {
final overlayController = Get.find<OverlayController>();
overlayController.hideVideoCall();
print('✅ [CallController] 已关闭通话小窗口');
}
// 退 VideoCallPage VideoCallPage
if (Get.currentRoute.contains('VideoCallPage')) {
Get.back();
print('✅ [CallController] 已退出 VideoCallPage');
}
//
await endCall(callDuration: callDurationSeconds.value);
}
}
} catch (e) {
@ -391,12 +415,47 @@ class CallController extends GetxController {
//
stopCallAudio();
// channelId
String? channelId;
if (message.body is EMCustomMessageBody) {
final customBody = message.body as EMCustomMessageBody;
final params = customBody.params;
if (params != null && params.containsKey('channelId')) {
channelId = params['channelId']?.toString();
}
}
// channelId
if (channelId != null && channelId.isNotEmpty) {
final response = await _networkService.rtcApi.refuseOneOnOneRtcChannel({
'channelId': channelId,
});
if (!response.data.isSuccess) {
SmartDialog.showToast(response.data.message);
return false;
}
print('✅ [CallController] 已调用拒绝一对一RTC频道接口,channelId: $channelId');
await RTMManager.instance.unsubscribe(channelId);
final callInfo = _parseCallInfo(message);
final callTypeStr = callInfo?['callType'] as String?;
final callType = callTypeStr == 'video' ? 'video' : 'voice';
// RTM
await RTMManager.instance.publishChannelMessage(
channelName: channelId,
message: json.encode({
'type': 'call_message',
'uid': 0,
'channelId': channelId,
'callType': callType,
'event': 'reject',
}),
);
}
//
currentCall.value = null;
// TODO: SDK
// await RTCManager.instance.rejectCall(message.from ?? '');
return true;
}

Loading…
Cancel
Save