|
@@ -278,66 +278,72 @@ export class RoomAssistant {
|
|
*/
|
|
*/
|
|
async startCall(roomId, userId, user) {
|
|
async startCall(roomId, userId, user) {
|
|
try {
|
|
try {
|
|
- if (user.oid) {
|
|
|
|
- console.log("hasDuplicateUser-存在oid", user.oid);
|
|
|
|
- const hasDuplicateUser = await this.getOpenidInRoom(roomId, user.oid);
|
|
|
|
- if (hasDuplicateUser && hasDuplicateUser.length > 0) {
|
|
|
|
- const removeAll = [];
|
|
|
|
- Array.from(hasDuplicateUser).forEach((duplicateUser) => {
|
|
|
|
- if (duplicateUser.userId !== user.userId) {
|
|
|
|
- console.log("duplicateUser-去重用户", duplicateUser);
|
|
|
|
- const deleteUserKey = `user:${duplicateUser.userId}`;
|
|
|
|
- console.log("deleteUserKey", deleteUserKey);
|
|
|
|
- removeAll.push(removeRoomUser(roomId, deleteUserKey));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- const res = await Promise.all(removeAll);
|
|
|
|
- console.log("去重完成", res);
|
|
|
|
|
|
+ const res = this.checkRoomMaximum(roomId);
|
|
|
|
+ if (!res.isMax) {
|
|
|
|
+ if (user.oid) {
|
|
|
|
+ console.log("hasDuplicateUser-存在oid", user.oid);
|
|
|
|
+ const hasDuplicateUser = await this.getOpenidInRoom(roomId, user.oid);
|
|
|
|
+ if (hasDuplicateUser && hasDuplicateUser.length > 0) {
|
|
|
|
+ const removeAll = [];
|
|
|
|
+ Array.from(hasDuplicateUser).forEach((duplicateUser) => {
|
|
|
|
+ if (duplicateUser.userId !== user.userId) {
|
|
|
|
+ console.log("duplicateUser-去重用户", duplicateUser);
|
|
|
|
+ const deleteUserKey = `user:${duplicateUser.userId}`;
|
|
|
|
+ console.log("deleteUserKey", deleteUserKey);
|
|
|
|
+ removeAll.push(removeRoomUser(roomId, deleteUserKey));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ const res = await Promise.all(removeAll);
|
|
|
|
+ console.log("去重完成", res);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if (!this.room.isHoster(user.role)) {
|
|
|
|
- this.room.logger.info("不是房主", JSON.stringify(user));
|
|
|
|
- await this.joinRoom(roomId, userId, user);
|
|
|
|
- } else {
|
|
|
|
- const hasRoom = await this.redis.hVals(getInKey(roomId));
|
|
|
|
- if (hasRoom.length === 0) {
|
|
|
|
- this.room.logger.info("房主主动创建房间 :", { roomId, userId });
|
|
|
|
- await this.buildRoom(roomId, userId, user);
|
|
|
|
|
|
+ if (!this.room.isHoster(user.role)) {
|
|
|
|
+ this.room.logger.info("不是房主", JSON.stringify(user));
|
|
|
|
+ await this.joinRoom(roomId, userId, user);
|
|
} else {
|
|
} else {
|
|
- //TODO
|
|
|
|
- const checkIsRoomMaster = await isRoomMaster(roomId, userId);
|
|
|
|
- console.log("isRoomMaster", checkIsRoomMaster);
|
|
|
|
- if (checkIsRoomMaster) {
|
|
|
|
- this.room.logger.info("房主已存在房间 :", { roomId, userId, from: user.from });
|
|
|
|
- await this.joinRoom(roomId, userId, user);
|
|
|
|
- // this.notifyUserJitter(roomId);
|
|
|
|
|
|
+ const hasRoom = await this.redis.hVals(getInKey(roomId));
|
|
|
|
+ if (hasRoom.length === 0) {
|
|
|
|
+ this.room.logger.info("房主主动创建房间 :", { roomId, userId });
|
|
|
|
+ await this.buildRoom(roomId, userId, user);
|
|
} else {
|
|
} else {
|
|
- this.room.logger.error("存在非法房主", userId);
|
|
|
|
|
|
+ //TODO
|
|
|
|
+ const checkIsRoomMaster = await isRoomMaster(roomId, userId);
|
|
|
|
+ console.log("isRoomMaster", checkIsRoomMaster);
|
|
|
|
+ if (checkIsRoomMaster) {
|
|
|
|
+ this.room.logger.info("房主已存在房间 :", { roomId, userId, from: user.from });
|
|
|
|
+ await this.joinRoom(roomId, userId, user);
|
|
|
|
+ // this.notifyUserJitter(roomId);
|
|
|
|
+ } else {
|
|
|
|
+ this.room.logger.error("存在非法房主", userId);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- user.isInRoom = true;
|
|
|
|
- this.hasCall = true;
|
|
|
|
- const AllRoomUsers = await getAllRoomUsers(roomId);
|
|
|
|
- const roomConfig = await getRoomConfig(roomId);
|
|
|
|
- await updateRoomUser(roomId, userId, user);
|
|
|
|
- this.room.logger.info("roomId", roomId);
|
|
|
|
- this.room.logger.info("AllRoomUsers", AllRoomUsers.length);
|
|
|
|
|
|
+ user.isInRoom = true;
|
|
|
|
+ this.hasCall = true;
|
|
|
|
+ const AllRoomUsers = await getAllRoomUsers(roomId);
|
|
|
|
+ const roomConfig = await getRoomConfig(roomId);
|
|
|
|
+ await updateRoomUser(roomId, userId, user);
|
|
|
|
+ this.room.logger.info("roomId", roomId);
|
|
|
|
+ this.room.logger.info("AllRoomUsers", AllRoomUsers.length);
|
|
|
|
|
|
- this.socket.emit(EVENT.roomIn, {
|
|
|
|
- user,
|
|
|
|
- roomsPerson: AllRoomUsers,
|
|
|
|
- roomsConfig: roomConfig,
|
|
|
|
- });
|
|
|
|
- this.socket.emit(EVENT.someOneInRoom, {
|
|
|
|
- user,
|
|
|
|
- roomsPerson: AllRoomUsers,
|
|
|
|
- });
|
|
|
|
- this.socket.broadcast.to(roomId).emit(EVENT.someOneInRoom, {
|
|
|
|
- user,
|
|
|
|
- roomsPerson: AllRoomUsers,
|
|
|
|
- });
|
|
|
|
|
|
+ this.socket.emit(EVENT.roomIn, {
|
|
|
|
+ user,
|
|
|
|
+ roomsPerson: AllRoomUsers,
|
|
|
|
+ roomsConfig: roomConfig,
|
|
|
|
+ });
|
|
|
|
+ this.socket.emit(EVENT.someOneInRoom, {
|
|
|
|
+ user,
|
|
|
|
+ roomsPerson: AllRoomUsers,
|
|
|
|
+ });
|
|
|
|
+ this.socket.broadcast.to(roomId).emit(EVENT.someOneInRoom, {
|
|
|
|
+ user,
|
|
|
|
+ roomsPerson: AllRoomUsers,
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ this.room.logger.warn("超出房间上限", res.num);
|
|
|
|
+
|
|
|
|
+ }
|
|
// await this.notifyUsersChange(roomId, user, true);
|
|
// await this.notifyUsersChange(roomId, user, true);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
this.room.logger.error("assistant::startCall:", error);
|
|
this.room.logger.error("assistant::startCall:", error);
|
|
@@ -418,6 +424,24 @@ export class RoomAssistant {
|
|
users: AllRoomUsers,
|
|
users: AllRoomUsers,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async checkRoomMaximum(roomId) {
|
|
|
|
+ const roomConfigRes = await getRoomConfig(roomId);
|
|
|
|
+ const userLimitNum = Number(roomConfigRes.userLimitNum) || 50;
|
|
|
|
+ const users = await getAllRoomUsers(roomId);
|
|
|
|
+ if (users && users.length > Number(userLimitNum)) {
|
|
|
|
+ return Promise.resolve({
|
|
|
|
+ isMax: true,
|
|
|
|
+ num: userLimitNum,
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ return Promise.resolve({
|
|
|
|
+ isMax: false,
|
|
|
|
+ num: userLimitNum,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// 主动断开
|
|
// 主动断开
|
|
async disconnect() {
|
|
async disconnect() {
|
|
try {
|
|
try {
|