145 lines
4.2 KiB
Dart
145 lines
4.2 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:get/get.dart';
|
||
import 'package:signalr_core/signalr_core.dart';
|
||
import 'package:wgshare/common/store/user_store.dart';
|
||
|
||
import '../../common/config/request_config.dart';
|
||
import '../../common/mixins/request_tool_mixin.dart';
|
||
import '../../common/models/common/base_structure_result.dart';
|
||
import '../../common/models/meeting_room_info.dart';
|
||
import '../../common/models/meeting_room_user.dart';
|
||
import '../../utils/toast_utils.dart';
|
||
import 'meeting_main_state.dart';
|
||
|
||
class MeetingMainLogic extends GetxController with RequestToolMixin{
|
||
final MeetingMainState state = MeetingMainState();
|
||
|
||
@override
|
||
void onInit() async {
|
||
super.onInit();
|
||
|
||
// 接收参数
|
||
var data = Get.arguments;
|
||
state.roomNumber.value = data["roomNumber"];
|
||
|
||
signalRSocket();
|
||
}
|
||
|
||
@override
|
||
void onClose() {
|
||
super.onClose();
|
||
state.memberNameSearchController.dispose();
|
||
stopTime();
|
||
state.hubConnection.value?.stop();
|
||
}
|
||
|
||
/// 合并请求
|
||
/// 1.获取会议室信息
|
||
/// 2.获取会议室所有用户
|
||
/// 3.获取会议室Token
|
||
void mergeFetch() async {
|
||
ToastUtils.showLoading();
|
||
|
||
var results = await Future.wait([
|
||
getClient().getMeetingRoomInfo(state.roomNumber.value),
|
||
getClient().getMeetingRoomAllUser(state.roomNumber.value),
|
||
getClient().getMeetingToken(state.roomNumber.value)]);
|
||
|
||
doHttpGetMeetingRoomInfo(results[0].data as MeetingRoomInfo);
|
||
doHttpGetMeetingRoomAllUser(results[1].data as List<MeetingRoomUser>);
|
||
doHttpGetMeetingToken(results[2].data as String);
|
||
|
||
ToastUtils.dismiss();
|
||
}
|
||
|
||
/// Socket长连接
|
||
Future<void> signalRSocket() async {
|
||
state.hubConnection.value = HubConnectionBuilder().withUrl('${RequestConfig().baseUrl}/session-manage',
|
||
HttpConnectionOptions(
|
||
transport: HttpTransportType.longPolling,
|
||
accessTokenFactory: () async => await Future.value(UserStore.to.token),
|
||
logging: (level, message) => print("SignalR Socket:$message"),
|
||
)).build();
|
||
|
||
await state.hubConnection.value?.start();
|
||
|
||
joinChannel();
|
||
}
|
||
|
||
/// 加入会议室
|
||
void joinChannel() async {
|
||
await state.hubConnection.value?.invoke("joinChannel", args: [state.roomNumber.value, false, false, false]);
|
||
mergeFetch();
|
||
}
|
||
|
||
/// 改变会议信息浮层显示状态
|
||
void changeMeetingInfoState(bool isShow){
|
||
state.isShowMeetingInfoFloatingLayer.value = isShow;
|
||
}
|
||
|
||
/// 改变音频选择浮层显示状态
|
||
void changeMeetingAudioState(bool isShow){
|
||
state.isShowMeetingAudioFloatingLayer.value = isShow;
|
||
}
|
||
|
||
/// 改变当前页面状态
|
||
void changePageState(int pageState){
|
||
state.pageState.value = pageState;
|
||
}
|
||
|
||
/// 获取会议室信息
|
||
void doHttpGetMeetingRoomInfo(MeetingRoomInfo meetingRoomInfo) async {
|
||
state.meetingRoomInfo.value = meetingRoomInfo;
|
||
startTime();
|
||
}
|
||
|
||
/// 获取会议室所有用户
|
||
void doHttpGetMeetingRoomAllUser(List<MeetingRoomUser> meetingRoomUsers) async {
|
||
state.users.value = meetingRoomUsers;
|
||
state.cacheUsers.value = meetingRoomUsers;
|
||
}
|
||
|
||
/// 获取会议室Token
|
||
void doHttpGetMeetingToken(String meetingToken) async {
|
||
state.meetingToken.value = meetingToken;
|
||
}
|
||
|
||
/// 启动计时
|
||
void startTime(){
|
||
state.stopwatch.value.start();
|
||
state.timer.value = Timer.periodic(const Duration(milliseconds: 100), upTime);
|
||
}
|
||
|
||
/// 更新计时
|
||
void upTime(Timer t) {
|
||
if(state.stopwatch.value.isRunning){
|
||
state.duration.value =
|
||
"${state.stopwatch.value.elapsed.inHours.toString().padLeft(2, "0")}"
|
||
":${(state.stopwatch.value.elapsed.inMinutes % 60).toString().padLeft(2, "0")}"
|
||
":${(state.stopwatch.value.elapsed.inSeconds % 60).toString().padLeft(2, "0")}";
|
||
}
|
||
}
|
||
|
||
/// 停止计时
|
||
void stopTime() {
|
||
state.timer.value?.cancel();
|
||
state.stopwatch.value.stop();
|
||
}
|
||
|
||
/// 搜索成员
|
||
void searchMember(String value){
|
||
if(value.isNotEmpty){
|
||
List<MeetingRoomUser> memberSearchList = [];
|
||
for(var i = 0; i < state.cacheUsers.length; i++){
|
||
if(state.cacheUsers[i].userName.contains(value)){
|
||
memberSearchList.add(state.cacheUsers.value[i]);
|
||
}
|
||
}
|
||
state.users.value = memberSearchList;
|
||
}else{
|
||
state.users.value = state.cacheUsers.value;
|
||
}
|
||
}
|
||
}
|