|
|
@ -3,6 +3,7 @@ import 'package:agora_rtc_engine/agora_rtc_engine.dart'; |
|
|
import 'package:audioplayers/audioplayers.dart'; |
|
|
import 'package:audioplayers/audioplayers.dart'; |
|
|
import 'package:dating_touchme_app/generated/assets.dart'; |
|
|
import 'package:dating_touchme_app/generated/assets.dart'; |
|
|
import 'package:dating_touchme_app/model/rtc/chat_audio_product_model.dart'; |
|
|
import 'package:dating_touchme_app/model/rtc/chat_audio_product_model.dart'; |
|
|
|
|
|
import 'package:dating_touchme_app/model/rtc/consume_rtc_channel_response.dart'; |
|
|
import 'package:dating_touchme_app/model/rtc/rtc_channel_data.dart'; |
|
|
import 'package:dating_touchme_app/model/rtc/rtc_channel_data.dart'; |
|
|
import 'package:dating_touchme_app/network/network_service.dart'; |
|
|
import 'package:dating_touchme_app/network/network_service.dart'; |
|
|
import 'package:dating_touchme_app/rtc/rtc_manager.dart'; |
|
|
import 'package:dating_touchme_app/rtc/rtc_manager.dart'; |
|
|
@ -117,6 +118,9 @@ class CallController extends GetxController { |
|
|
String? _callChannelId; |
|
|
String? _callChannelId; |
|
|
int? _callUid; |
|
|
int? _callUid; |
|
|
|
|
|
|
|
|
|
|
|
// 消费响应数据(用于显示玫瑰剩余数量和每分钟价格) |
|
|
|
|
|
final Rxn<ConsumeRtcChannelResponse> consumeResponse = Rxn<ConsumeRtcChannelResponse>(); |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
void onInit() { |
|
|
void onInit() { |
|
|
super.onInit(); |
|
|
super.onInit(); |
|
|
@ -450,9 +454,6 @@ class CallController extends GetxController { |
|
|
// 接收方接听后,立即调用一次消费接口并启动定时器 |
|
|
// 接收方接听后,立即调用一次消费接口并启动定时器 |
|
|
// 确保 _callChannelId 已设置 |
|
|
// 确保 _callChannelId 已设置 |
|
|
if (_callChannelId != null && _callChannelId!.isNotEmpty) { |
|
|
if (_callChannelId != null && _callChannelId!.isNotEmpty) { |
|
|
Future .delayed(Duration(seconds: 1), () async { |
|
|
|
|
|
await _consumeOneOnOneRtcChannel(); |
|
|
|
|
|
}); |
|
|
|
|
|
_startConsumeTimer(); |
|
|
_startConsumeTimer(); |
|
|
print('✅ [CallController] 接收方接听后已启动消费定时器'); |
|
|
print('✅ [CallController] 接收方接听后已启动消费定时器'); |
|
|
} |
|
|
} |
|
|
@ -591,6 +592,8 @@ class CallController extends GetxController { |
|
|
void _stopConsumeTimer() { |
|
|
void _stopConsumeTimer() { |
|
|
_consumeTimer?.cancel(); |
|
|
_consumeTimer?.cancel(); |
|
|
_consumeTimer = null; |
|
|
_consumeTimer = null; |
|
|
|
|
|
// 清空消费响应数据 |
|
|
|
|
|
consumeResponse.value = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 调用消费一对一RTC频道接口 |
|
|
/// 调用消费一对一RTC频道接口 |
|
|
@ -606,7 +609,28 @@ class CallController extends GetxController { |
|
|
'channelId': consumeChannelId, |
|
|
'channelId': consumeChannelId, |
|
|
}); |
|
|
}); |
|
|
if (response.data.isSuccess) { |
|
|
if (response.data.isSuccess) { |
|
|
print('✅ [CallController] 已调用消费一对一RTC频道接口,channelId: $consumeChannelId'); |
|
|
|
|
|
|
|
|
final consumeData = response.data.data; |
|
|
|
|
|
if (consumeData != null) { |
|
|
|
|
|
// 更新消费响应数据 |
|
|
|
|
|
consumeResponse.value = consumeData; |
|
|
|
|
|
|
|
|
|
|
|
print('✅ [CallController] 已调用消费一对一RTC频道接口,channelId: $consumeChannelId, isFree: ${consumeData.isFree}, status: ${consumeData.status}, availableBalance: ${consumeData.availableBalance}, unitSellingBalance: ${consumeData.unitSellingBalance}'); |
|
|
|
|
|
|
|
|
|
|
|
// 如果 status == 3,挂断通话 |
|
|
|
|
|
if (consumeData.status == 3) { |
|
|
|
|
|
print('⚠️ [CallController] 检测到 status=3,自动挂断通话'); |
|
|
|
|
|
await hangUpCall(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果是免费通话,停止定时器,不再调用消费接口 |
|
|
|
|
|
if (consumeData.isFree) { |
|
|
|
|
|
_stopConsumeTimer(); |
|
|
|
|
|
print('✅ [CallController] 检测到免费通话,已停止消费定时器'); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
print('✅ [CallController] 已调用消费一对一RTC频道接口,channelId: $consumeChannelId'); |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
print('⚠️ [CallController] 消费一对一RTC频道接口失败: ${response.data.message}'); |
|
|
print('⚠️ [CallController] 消费一对一RTC频道接口失败: ${response.data.message}'); |
|
|
} |
|
|
} |
|
|
|