自习室优化ok
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:app/data/models/meeting_room_dto.dart';
|
||||
import 'package:app/request/dto/room/room_list_item_dto.dart';
|
||||
import 'package:app/request/dto/room/room_info_dto.dart';
|
||||
import 'package:app/request/dto/room/room_type_dto.dart';
|
||||
import 'package:app/request/dto/room/room_user_dto.dart';
|
||||
import 'package:app/request/dto/room/rtc_token_dto.dart';
|
||||
import 'package:app/request/websocket/room_protocol.dart';
|
||||
@@ -13,18 +14,17 @@ import 'type.dart';
|
||||
|
||||
class TchRoomVM extends ChangeNotifier {
|
||||
TchRoomVM({
|
||||
required this.roomInfo,
|
||||
String? start,
|
||||
required RoomListItemDto info,
|
||||
}) {
|
||||
roomInfo = MeetingRoomDto.fromRoomListItem(info).copyWith(roomStatus: -1);
|
||||
_startRoom();
|
||||
}
|
||||
|
||||
///学生摄像头列表
|
||||
List<RoomUserDto> _students = [];
|
||||
|
||||
///房间的基础信息
|
||||
final RoomInfoDto roomInfo;
|
||||
int roomStatus = -1; // //-1加载中,0没开始,1进行中,2关闭
|
||||
///房间的基础信息,其中状态-1加载中,0没开始,1进行中,2关闭
|
||||
late MeetingRoomDto roomInfo;
|
||||
|
||||
///老师选中的学生id
|
||||
int activeSId = 0;
|
||||
@@ -42,8 +42,6 @@ class TchRoomVM extends ChangeNotifier {
|
||||
|
||||
///websocket管理
|
||||
final RoomWebSocket _ws = RoomWebSocket();
|
||||
|
||||
// bool wsConnected = false; // socket连接状态
|
||||
StreamSubscription<RoomMessage>? _sub;
|
||||
|
||||
RtcTokenDto? get rtcToken => _ws.rtcToken;
|
||||
@@ -61,8 +59,8 @@ class TchRoomVM extends ChangeNotifier {
|
||||
// 自习室人员变化
|
||||
if (msg.event == RoomEvent.changeUser) {
|
||||
final list = RoomUserDto.listFromJson(msg.data['user_list']);
|
||||
final room = RoomTypeDto.fromJson(msg.data['room_info']);
|
||||
roomStatus = room.roomStatus;
|
||||
final room = RoomInfoDto.fromJson(msg.data['room_info']);
|
||||
_updateRoomInfo(room);
|
||||
onStudentChange(list);
|
||||
} else if ([
|
||||
RoomEvent.openSpeaker,
|
||||
@@ -74,11 +72,26 @@ class TchRoomVM extends ChangeNotifier {
|
||||
RoomEvent.handUp,
|
||||
].contains(msg.event)) {
|
||||
onSyncStudentItem(RoomUserDto.fromJson(msg.data));
|
||||
} else if (msg.event == RoomEvent.fileUploadComplete) {
|
||||
updateStudentFile(
|
||||
msg.data['user_id'],
|
||||
(msg.data['flies'] as List).map((e) => e.toString()).toList(),
|
||||
);
|
||||
}
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///更新房间信息
|
||||
void _updateRoomInfo(RoomInfoDto info) {
|
||||
roomInfo = roomInfo.copyWith(
|
||||
roomStatus: info.roomStatus,
|
||||
actualStartTime: info.roomStartTime,
|
||||
boardUuid: info.boardUuid,
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///自习室的开关
|
||||
/// - [isOpen]: 是否开启
|
||||
void toggleRoom({required bool isOpen}) {
|
||||
@@ -92,6 +105,7 @@ class TchRoomVM extends ChangeNotifier {
|
||||
///学生选择
|
||||
void selectStudent(int id) {
|
||||
activeSId = id;
|
||||
clearHandUp(id);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -114,20 +128,38 @@ class TchRoomVM extends ChangeNotifier {
|
||||
student.speekerStatus = isOpen ? 0 : 1;
|
||||
data['is_mute'] = isOpen ? 1 : 0;
|
||||
} else if (action == StudentAction.camera) {
|
||||
//如果是摄像头,只能关
|
||||
if (student.cameraStatus == 0) return;
|
||||
//如果是摄像头
|
||||
bool isOpen = student.cameraStatus == 1;
|
||||
student.cameraStatus = 0;
|
||||
data['is_mute'] = 1;
|
||||
data['is_mute'] = isOpen ? 1 : 0;
|
||||
} else if (action == StudentAction.microphone) {
|
||||
//如果是麦克风,只能关
|
||||
if (student.microphoneStatus == 0) return;
|
||||
//如果是麦克风
|
||||
bool isOpen = student.microphoneStatus == 1;
|
||||
student.microphoneStatus = 0;
|
||||
data['is_mute'] = 1;
|
||||
data['is_mute'] = isOpen ? 1 : 0;
|
||||
}
|
||||
notifyListeners();
|
||||
_ws.send(RoomCommand.switchStudentCamera, data);
|
||||
}
|
||||
|
||||
///关闭全部学生的摄像头或者扬声器
|
||||
void closeAllStudentAction(StudentAction action) {
|
||||
_students.forEach((item) {
|
||||
if (action == StudentAction.speaker) {
|
||||
item.speekerStatus = 0;
|
||||
} else if (action == StudentAction.camera) {
|
||||
item.cameraStatus = 0;
|
||||
}
|
||||
});
|
||||
notifyListeners();
|
||||
Map<String, dynamic> data = {
|
||||
'target_user_id': "all",
|
||||
"mute_type": action.value,
|
||||
"is_mute": 1,
|
||||
};
|
||||
_ws.send(RoomCommand.switchStudentCamera, data);
|
||||
}
|
||||
|
||||
//清除全部学生举手,或者是指定
|
||||
void clearHandUp(int? id) {
|
||||
Map<String, dynamic> data = {};
|
||||
@@ -155,13 +187,28 @@ class TchRoomVM extends ChangeNotifier {
|
||||
/// 同步单个学生的最新状态
|
||||
void onSyncStudentItem(RoomUserDto userInfo) {
|
||||
final index = _students.indexWhere((t) => t.userId == userInfo.userId);
|
||||
print(userInfo.toString());
|
||||
if (index != -1) {
|
||||
_students[index] = userInfo;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
///更新学生的文件
|
||||
void updateStudentFile(int uId, List<String> files) {
|
||||
final index = _students.indexWhere((t) => t.userId == uId);
|
||||
if (index != -1) {
|
||||
_students[index].filesList = files;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
///结束会议
|
||||
void endRoom() {
|
||||
roomInfo = roomInfo.copyWith(roomStatus: 2);
|
||||
_ws.send(RoomCommand.closeRoom);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
//销毁
|
||||
@override
|
||||
void dispose() {
|
||||
|
||||
Reference in New Issue
Block a user