Browse Source

feat(rtc): 添加一对一RTC频道连接和终止功能

- 在api_urls.dart中新增connectOneOnOneRtcChannel和terminateOneOnOneRtcChannel接口常量
- 在rtc_api.dart中添加connectOneOnOneRtcChannel和terminateOneOnOneRtcChannel接口定义
- 在call_controller.dart的通话建立时调用connectOneOnOneRtcChannel接口
- 在call_controller.dart的通话结束时根据通话状态调用terminateOneOnOneRtcChannel接口
- 更新live_room_action_bar.dart中的充值按钮样式为文本按钮
- 修改live_room_pay_item.dart中价格显示格式,去掉小数点后数字
master
Jolie 3 months ago
parent
commit
86953b2deb
6 changed files with 114 additions and 25 deletions
  1. 22
      lib/controller/message/call_controller.dart
  2. 6
      lib/network/api_urls.dart
  3. 12
      lib/network/rtc_api.dart
  4. 68
      lib/network/rtc_api.g.dart
  5. 29
      lib/widget/live/live_room_action_bar.dart
  6. 2
      lib/widget/live/live_room_pay_item.dart

22
lib/controller/message/call_controller.dart

@ -388,6 +388,15 @@ class CallController extends GetxController {
// channelId
_callChannelId = channelId;
// RTC频道接口
final connectResponse = await _networkService.rtcApi
.connectOneOnOneRtcChannel({'channelId': channelId});
if (!connectResponse.data.isSuccess) {
SmartDialog.showToast(connectResponse.data.message);
return false;
}
print('✅ [CallController] 已调用连接一对一RTC频道接口,channelId: $channelId');
//
if (callType == CallType.voice) {
//
@ -735,6 +744,19 @@ class CallController extends GetxController {
return;
}
print('✅ [CallController] 已调用取消一对一RTC频道接口,channelId: $_callChannelId');
} else if (callSession != null &&
callDurationSeconds.value > 0 &&
_callChannelId != null &&
_callChannelId!.isNotEmpty) {
//
final response = await _networkService.rtcApi.terminateOneOnOneRtcChannel(
{'channelId': _callChannelId!},
);
if (!response.data.isSuccess) {
SmartDialog.showToast(response.data.message);
return;
}
print('✅ [CallController] 已调用终止一对一RTC频道接口,channelId: $_callChannelId');
}
if (_callChannelId != null &&

6
lib/network/api_urls.dart

@ -137,6 +137,12 @@ class ApiUrls {
static const String cancelOneOnOneRtcChannel =
'dating-agency-chat-audio/user/cancel/one-on-one/rtc-channel';
static const String connectOneOnOneRtcChannel =
'dating-agency-chat-audio/user/connect/one-on-one/rtc-channel';
static const String terminateOneOnOneRtcChannel =
'dating-agency-chat-audio/user/terminate/one-on-one/rtc-channel';
static const String getAppVersion =
'dating-agency-uec/user/get/app-version/update';

12
lib/network/rtc_api.dart

@ -111,4 +111,16 @@ abstract class RtcApi {
Future<HttpResponse<BaseResponse<dynamic>>> cancelOneOnOneRtcChannel(
@Body() Map<String, dynamic> data,
);
/// RTC频道
@POST(ApiUrls.connectOneOnOneRtcChannel)
Future<HttpResponse<BaseResponse<dynamic>>> connectOneOnOneRtcChannel(
@Body() Map<String, dynamic> data,
);
/// RTC频道
@POST(ApiUrls.terminateOneOnOneRtcChannel)
Future<HttpResponse<BaseResponse<dynamic>>> terminateOneOnOneRtcChannel(
@Body() Map<String, dynamic> data,
);
}

68
lib/network/rtc_api.g.dart

@ -638,6 +638,74 @@ class _RtcApi implements RtcApi {
return httpResponse;
}
@override
Future<HttpResponse<BaseResponse<dynamic>>> connectOneOnOneRtcChannel(
Map<String, dynamic> data,
) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(data);
final _options = _setStreamType<HttpResponse<BaseResponse<dynamic>>>(
Options(method: 'POST', headers: _headers, extra: _extra)
.compose(
_dio.options,
'dating-agency-chat-audio/user/connect/one-on-one/rtc-channel',
queryParameters: queryParameters,
data: _data,
)
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
);
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late BaseResponse<dynamic> _value;
try {
_value = BaseResponse<dynamic>.fromJson(
_result.data!,
(json) => json as dynamic,
);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
final httpResponse = HttpResponse(_value, _result);
return httpResponse;
}
@override
Future<HttpResponse<BaseResponse<dynamic>>> terminateOneOnOneRtcChannel(
Map<String, dynamic> data,
) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(data);
final _options = _setStreamType<HttpResponse<BaseResponse<dynamic>>>(
Options(method: 'POST', headers: _headers, extra: _extra)
.compose(
_dio.options,
'dating-agency-chat-audio/user/terminate/one-on-one/rtc-channel',
queryParameters: queryParameters,
data: _data,
)
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
);
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late BaseResponse<dynamic> _value;
try {
_value = BaseResponse<dynamic>.fromJson(
_result.data!,
(json) => json as dynamic,
);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
final httpResponse = HttpResponse(_value, _result);
return httpResponse;
}
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
if (T != dynamic &&
!(requestOptions.responseType == ResponseType.bytes ||

29
lib/widget/live/live_room_action_bar.dart

@ -88,30 +88,11 @@ class LiveRoomActionBar extends StatelessWidget {
// ),
// ),
// SizedBox(width: 8.w),
InkWell(
onTap: onChargeTap,
child: Container(
width: 38.w,
height: 38.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(38.w)),
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color.fromRGBO(255, 43, 110, 1),
Color.fromRGBO(255, 52, 26, 1),
],
),
),
child: Center(
child: Image.asset(
Assets.imagesRoseWhite,
width: 14.w,
height: 25.w,
),
),
),
TextButton(
onPressed: onChargeTap,
child: Text('充值', style: TextStyle(
color: Colors.white
),)
),
SizedBox(width: 16.w),
],

2
lib/widget/live/live_room_pay_item.dart

@ -70,7 +70,7 @@ class _LiveRoomPayItemState extends State<LiveRoomPayItem> {
),
),
Text(
"${(widget.item["price"] as num?)?.toStringAsFixed(1) ?? '0.0'}",
"${(widget.item["price"] as num?)?.toStringAsFixed(0) ?? '0.0'}",
style: TextStyle(
fontSize: 11.w,
color: const Color.fromRGBO(144, 144, 144, 1),

Loading…
Cancel
Save