|
@@ -1,6 +1,6 @@
|
|
|
// 房间行为助手
|
|
|
import { EVENT, CODEMEG, FROMTYPE } from "../../enum/index.js";
|
|
|
-import { getCurrentUser, updateUser, removeRoomAllUsers, getAllRoomUsers, updateRoomUser } from "../../service/userService.js";
|
|
|
+import { getCurrentUser, updateUser, removeRoomAllUsers, getAllRoomUsers, updateRoomUser, removeRoomUser } from "../../service/userService.js";
|
|
|
import { setRoomConfig, getRoomConfig, isRoomMaster } from "../../service/roomConfigService.js";
|
|
|
import { subClient } from "../../connection/redis.js";
|
|
|
|
|
@@ -38,9 +38,9 @@ export class RoomAssistant {
|
|
|
*/
|
|
|
async kickPersion(roomId, userId) {
|
|
|
console.log("kickPersion", roomId, userId);
|
|
|
- getInKey(roomId)
|
|
|
+ getInKey(roomId);
|
|
|
try {
|
|
|
- const hasJoin = await this.redis.HVALS( getInKey(roomId), userId);
|
|
|
+ const hasJoin = await this.redis.HVALS(getInKey(roomId), userId);
|
|
|
// const blackListId = ""
|
|
|
if (hasJoin.length > 0) {
|
|
|
await this.redis.hDel(getInKey(roomId), userId);
|
|
@@ -115,7 +115,7 @@ export class RoomAssistant {
|
|
|
// return;
|
|
|
// }
|
|
|
const reveseMic = Number(isAllowMic) === 0 ? 1 : 0;
|
|
|
- console.log("设置MIC权当前用户:: %s 新MIC权", user, reveseMic);
|
|
|
+ console.log("设置MIC权当前用户:: %s 新MIC权", user.userId, reveseMic);
|
|
|
const userObj = Object.assign({}, user, { isAllowMic: reveseMic });
|
|
|
const roomObj = Object.assign({}, roomConfigRes, { allowMicId: user.userId });
|
|
|
|
|
@@ -201,9 +201,12 @@ export class RoomAssistant {
|
|
|
async leaveRoom(roomId, userId, user) {
|
|
|
try {
|
|
|
await this.redis.hDel(getInKey(roomId), userId);
|
|
|
- this.room.logger.info("离开房间", userId, AllRoomUsers);
|
|
|
+ await removeRoomUser(roomId, userId);
|
|
|
const AllRoomUsers = await getAllRoomUsers(roomId);
|
|
|
const roomConfig = await getRoomConfig(roomId);
|
|
|
+
|
|
|
+ this.room.logger.info("离开房间", userId, AllRoomUsers);
|
|
|
+
|
|
|
this.socket.broadcast.to(roomId).emit(EVENT.roomOut, {
|
|
|
user,
|
|
|
roomsPerson: AllRoomUsers,
|
|
@@ -308,13 +311,14 @@ export class RoomAssistant {
|
|
|
/**
|
|
|
* 通知房间人员变动
|
|
|
*/
|
|
|
- async notifyUsersChange(roomId, user) {
|
|
|
+ async notifyUsersChange(roomId, user, inter = true) {
|
|
|
const AllRoomUsers = await getAllRoomUsers(roomId);
|
|
|
// const roomConfig = await getRoomConfig(roomId);
|
|
|
this.room.logger.info("notifyUsersChange", roomId, AllRoomUsers.length);
|
|
|
+ const actionName = inter ? "inRoom" : "outRoom";
|
|
|
this.socket.broadcast.to(roomId).emit(EVENT.roomPersonChange, {
|
|
|
user: user,
|
|
|
- // actionName: "outRoom",
|
|
|
+ actionName: actionName,
|
|
|
roomsPerson: AllRoomUsers,
|
|
|
});
|
|
|
}
|
|
@@ -334,13 +338,19 @@ export class RoomAssistant {
|
|
|
}
|
|
|
// 主动断开
|
|
|
async disconnect() {
|
|
|
- const syncId = this.room.syncId;
|
|
|
- const roomId = this.room.roomId;
|
|
|
- const userId = this.room.userId;
|
|
|
- this.socket.leave(syncId);
|
|
|
- this.socket.leave(roomId);
|
|
|
- await this.redis.del(getInKey(syncId));
|
|
|
- await this.redis.del(getInKey(userId));
|
|
|
+ try {
|
|
|
+ const syncId = this.room.syncId;
|
|
|
+ const roomId = this.room.roomId;
|
|
|
+ const userId = this.room.userId;
|
|
|
+ this.socket.leave(syncId);
|
|
|
+ this.socket.leave(roomId);
|
|
|
+ await removeRoomUser(roomId, userId);
|
|
|
+ await this.redis.del(getInKey(syncId));
|
|
|
+ await this.redis.del(getInKey(userId));
|
|
|
+ this.notifyUsersChange(roomId, this.room.user, false);
|
|
|
+ } catch (error) {
|
|
|
+ console.log("disconnect::error", error);
|
|
|
+ }
|
|
|
}
|
|
|
// RoomSessionId 房间有效时间
|
|
|
setRoomUnlimit(roomSessionId) {
|