|
|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
|