Przeglądaj źródła

进入房间前去重

gemercheung 3 lat temu
rodzic
commit
7f37532865
2 zmienionych plików z 15 dodań i 18 usunięć
  1. 14 0
      src/controller/room/assistant.js
  2. 1 18
      src/controller/room/index.js

+ 14 - 0
src/controller/room/assistant.js

@@ -276,6 +276,20 @@ export class RoomAssistant {
    */
    */
   async startCall(roomId, userId, user) {
   async startCall(roomId, userId, user) {
     try {
     try {
+      if (user.oid) {
+        const hasDuplicateUser = await this.getOpenidInRoom(this.roomId, user.oid);
+        console.log("hasDuplicateUser-1", typeof hasDuplicateUser);
+        if (hasDuplicateUser && hasDuplicateUser.length > 0) {
+          this.logger.info("hasDuplicateUser-2", hasDuplicateUser);
+          const removeAll = [];
+          Array.from(hasDuplicateUser).forEach((duplicateUser) => {
+            removeAll.push(removeRoomUser(this.roomId, duplicateUser.userId));
+          });
+          const res = await Promise.all(removeAll);
+          console.log("去重完成", res);
+        }
+      }
+
       if (!this.room.isHoster(user.role)) {
       if (!this.room.isHoster(user.role)) {
         this.room.logger.info("不是房主", JSON.stringify(user));
         this.room.logger.info("不是房主", JSON.stringify(user));
         await this.joinRoom(roomId, userId, user);
         await this.joinRoom(roomId, userId, user);

+ 1 - 18
src/controller/room/index.js

@@ -102,24 +102,7 @@ export class RoomController extends BasicController {
           userObj.role = "customer";
           userObj.role = "customer";
         }
         }
       }
       }
-      if (user.oid) {
-        const hasDuplicateUser = await this.roomAssistant.getOpenidInRoom(this.roomId, user.oid);
-        console.log("hasDuplicateUser", typeof hasDuplicateUser);
-        if (hasDuplicateUser && hasDuplicateUser.length > 0) {
-          this.logger.info(
-            "hasDuplicateUser",
-            hasDuplicateUser.reduce((prev, current) => {
-              prev.concat(current.userId);
-            }, []),
-          );
-          const removeAll = [];
-          Array.from(hasDuplicateUser).forEach((duplicateUser) => {
-            removeAll.push(removeRoomUser(this.roomId, duplicateUser.userId));
-          });
-          const res = Promise.all(removeAll);
-          console.log("去重完成");
-        }
-      }
+ 
       // 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";
       // }
       // }