gemercheung il y a 3 ans
Parent
commit
6e1cc02fc4

+ 3 - 3
src/controller/connectController.js

@@ -36,13 +36,13 @@ export class ConnectController extends BasicController {
         setTimeout(async () => {
         setTimeout(async () => {
           // 有可客户端主动断开时
           // 有可客户端主动断开时
           if (Number(user.onlineStatus) === 1) {
           if (Number(user.onlineStatus) === 1) {
-            const res = await this.roomController.roomAssistant.checkRoomMaximum(roomId);
-            if (!res.isMax) {
+            // const res = await this.roomController.roomAssistant.checkRoomMaximum(roomId);
+            if (!this.roomController.roomAssistant.roomMax) {
               console.log("已在线,被断开后", user);
               console.log("已在线,被断开后", user);
               user.onlineStatus = 0;
               user.onlineStatus = 0;
               await updateRoomUser(roomId, userId, user);
               await updateRoomUser(roomId, userId, user);
               await this.roomController.roomAssistant.notifyUsersChange(roomId, user, false);
               await this.roomController.roomAssistant.notifyUsersChange(roomId, user, false);
-            }
+            } 
           }
           }
         }, 1000);
         }, 1000);
 
 

+ 2 - 3
src/controller/room/assistant.js

@@ -15,6 +15,7 @@ export class RoomAssistant {
     this.roomId = null;
     this.roomId = null;
     this.hasCall = false;
     this.hasCall = false;
     this.room = room;
     this.room = room;
+    this.roomMax = false;
   }
   }
 
 
   /**
   /**
@@ -278,9 +279,7 @@ export class RoomAssistant {
    */
    */
   async startCall(roomId, userId, user) {
   async startCall(roomId, userId, user) {
     try {
     try {
-      const res = await this.checkRoomMaximum(roomId);
-      console.log("checkRoomMaximum:", res);
-      if (!res.isMax) {
+      if (!this.roomMax) {
         if (user.oid) {
         if (user.oid) {
           console.log("hasDuplicateUser-存在oid", user.oid);
           console.log("hasDuplicateUser-存在oid", user.oid);
           const hasDuplicateUser = await this.getOpenidInRoom(roomId, user.oid);
           const hasDuplicateUser = await this.getOpenidInRoom(roomId, user.oid);

+ 19 - 13
src/controller/room/index.js

@@ -98,6 +98,10 @@ export class RoomController extends BasicController {
         //   this.logger.info("已存在默认助手变更:" + "room助手ID: " + assistantId + " userId: " + this.user.userId);
         //   this.logger.info("已存在默认助手变更:" + "room助手ID: " + assistantId + " userId: " + this.user.userId);
         // }
         // }
       }
       }
+      //检查房间人数
+      const res = await this.roomAssistant.checkRoomMaximum(roomId);
+      console.log("checkRoomMaximum:", res);
+      this.roomAssistant.roomMax = res.isMax;
 
 
       // if (assistantId && Number(this.userId) !== Number(assistantId) && !this.isHoster(this.user.role)) {
       // if (assistantId && Number(this.userId) !== Number(assistantId) && !this.isHoster(this.user.role)) {
       //   userObj.role = "customer";
       //   userObj.role = "customer";
@@ -220,19 +224,21 @@ export class RoomController extends BasicController {
 
 
     this.socket.on(EVENT.changeOnlineStatus, async (data) => {
     this.socket.on(EVENT.changeOnlineStatus, async (data) => {
       try {
       try {
-        const user = await this.currentUser();
-        user.onlineStatus = Number(data.status);
-        await updateRoomUser(this.roomId, this.userId, user);
-        this.user = user;
-        //更新一份
-        let actionName = Number(user.onlineStatus) === 1 ? "inRoom" : "leaveRoom";
-        this.logger.info("changeOnlineStatus", JSON.stringify(user));
-        const AllRoomUsers = await getAllRoomUsers(this.roomId);
-        this.socket.broadcast.to(this.roomId).emit(EVENT.roomPersonChange, {
-          roomsPerson: AllRoomUsers,
-          actionName,
-          user: user,
-        });
+        if (!this.roomAssistant.roomMax) {
+          const user = await this.currentUser();
+          user.onlineStatus = Number(data.status);
+          await updateRoomUser(this.roomId, this.userId, user);
+          this.user = user;
+          //更新一份
+          let actionName = Number(user.onlineStatus) === 1 ? "inRoom" : "leaveRoom";
+          this.logger.info("changeOnlineStatus", JSON.stringify(user));
+          const AllRoomUsers = await getAllRoomUsers(this.roomId);
+          this.socket.broadcast.to(this.roomId).emit(EVENT.roomPersonChange, {
+            roomsPerson: AllRoomUsers,
+            actionName,
+            user: user,
+          });
+        }
       } catch (error) {
       } catch (error) {
         this.logger.error("event:changeOnlineStatus", error);
         this.logger.error("event:changeOnlineStatus", error);
       }
       }