Browse Source

助手默认进入

gemercheung 3 năm trước cách đây
mục cha
commit
e9caff09f0
2 tập tin đã thay đổi với 17 bổ sung9 xóa
  1. 10 3
      src/controller/room/assistant.js
  2. 7 6
      src/controller/room/index.js

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

@@ -18,9 +18,9 @@ export class RoomAssistant {
 
   /**
    * 准备房间
-   * @param {*} roomSessionId 
-   * @param {*} roomId 
-   * @returns 
+   * @param {*} roomSessionId
+   * @param {*} roomId
+   * @returns
    */
   async prepearRoom(roomSessionId, roomId) {
     // const uRoomId = await this.redis.get(getInKey(roomSessionId));
@@ -113,6 +113,13 @@ export class RoomAssistant {
       this.room.logger.error("setAssistant:error", error);
     }
   }
+
+  async getRoomAssistant(roomId) {
+    const roomConfig = await getRoomConfig(roomId);
+    const config = JSON.parse(roomConfig);
+    const assistantId = config.assistantId || "";
+    return Promise.resolve(assistantId);
+  }
   /**
    * 设置MIC权 LEADER(权限) 房主或助手
    * 主要

+ 7 - 6
src/controller/room/index.js

@@ -68,11 +68,7 @@ export class RoomController extends BasicController {
     let user = this.socket.handshake.query;
     this.logger.info("init-user-query:", this.socket.handshake.query);
     if (user) {
-      const checkAssistant = Number(user.userId) === Number(user.assistantId) && user.role !== "leader";
-      this.user = Object.assign({}, user, {
-        // roomType: user.roomType || "",
-        role: checkAssistant ? "assistant" : user.role,
-      });
+      this.user = Object.assign({}, user);
       this.user.sig = this.getSig(this.user.userId);
       const oneSceneNum = this.user.sceneNumber || this.user.sceneNum;
       const { userId, roomId } = this.user;
@@ -92,8 +88,14 @@ export class RoomController extends BasicController {
           order = 2;
           break;
       }
+      const assistantId = this.roomAssistant.getRoomAssistant(this.roomId);
+      if (assistantId && this.userId !== assistantId) {
+        this.logger.info("已存在用户并不是该用户:", this.user.role);
+        userObj.role = "customer";
+      }
       const userObj = { ...this.user, onlineStatus: 1, isConnected: true, order };
       this.logger.info("update-user-info:", userObj);
+
       updateUser(this.userId, userObj);
       // this.sysUsers.push(this.user);
       // 只有来源于小程序用户信息才记录到redis
@@ -103,7 +105,6 @@ export class RoomController extends BasicController {
           const checkoutMaster = await isRoomMaster(this.roomId, this.userId);
           const isNoExistMaster = "masterId" in roomConfig;
           // console.log("checkoutMaster-isNoExistMaster", checkoutMaster, !isNoExistMaster);
-
           if (checkoutMaster || !isNoExistMaster) {
             console.log("房主进入记录信息::: checkoutMaster: %s, isNoExistMaster: %s ,roomId %s", checkoutMaster, !isNoExistMaster, this.roomId);
             const roomConfig = {