gemercheung vor 2 Jahren
Ursprung
Commit
7a61419c1a

+ 1 - 1
src/app.module.ts

@@ -1,5 +1,5 @@
 import { ConfigModule } from '@nestjs/config';
-import { NacosService, NacosModule } from 'nest-nacos';
+// import { NacosService, NacosModule } from 'nest-nacos';
 import { getEnvPath } from './common/helper/env.helper';
 const envFilePath: string = getEnvPath(`${__dirname}/common/envs`);
 const config = ConfigModule.forRoot({

+ 1 - 1
src/interceptor/http-execption/http-execption.filter.ts

@@ -5,7 +5,7 @@ import {
   HttpException,
 } from '@nestjs/common';
 import { Request, Response } from 'express';
-import { execPath } from 'process';
+// import { execPath } from 'process';
 
 @Catch(HttpException)
 export class HttpExceptionFilter implements ExceptionFilter {

+ 7 - 1
src/room/actions/action.d.ts

@@ -19,7 +19,8 @@ type actionType =
   | 'error'
   | 'sync-floor'
   | 'room-valid-time'
-  | 'users-kicked';
+  | 'users-kicked'
+  | 'set-assistant';
 
 interface DanmakuDataType {
   nickname: string;
@@ -48,3 +49,8 @@ interface KickStateType {
   userId: string;
   roomId?: string;
 }
+interface SetAssistantType {
+  type: actionType['set-assistant'];
+  userId: string;
+  roomId?: string;
+}

+ 19 - 3
src/room/actions/actions.service.ts

@@ -12,7 +12,7 @@ export class ActionsService {
     private roomService: RoomService,
     @Inject(forwardRef(() => UsersService))
     private userService: UsersService,
-  ) {}
+  ) { }
 
   async handleAllAction(socket: Socket, data: ActionsParams): Promise<void> {
     const isSocketLeader = () => {
@@ -31,8 +31,7 @@ export class ActionsService {
     }
 
     this.roomService.logger.warn(
-      `当前--broadcast:${roomId}, data:${JSON.stringify(data)}action:${
-        data.type
+      `当前--broadcast:${roomId}, data:${JSON.stringify(data)}action:${data.type
       } ,isLeader:${isSocketLeader()}`,
       'handleAllAction',
     );
@@ -63,6 +62,11 @@ export class ActionsService {
         const kickParams = data as any as KickStateType;
         isSocketLeader() && (await this.handleKickState(socket, kickParams));
         break;
+      case 'set-assistant':
+        const assistantParams = data as any as SetAssistantType;
+        isSocketLeader() &&
+          (await this.handleSetAssitant(socket, assistantParams));
+        break;
       default:
         break;
     }
@@ -114,4 +118,16 @@ export class ActionsService {
       await this.roomService.handleKickAction(roomId, userId);
     }
   }
+  /**
+   *  处理
+   * @param socket;
+   * @param data;
+   */
+  async handleSetAssitant(socket: Socket, data: SetAssistantType) {
+    if (data) {
+      const roomId = socket.data.user.RoomId || '';
+      const userId = data.userId;
+      await this.roomService.handleKickAction(roomId, userId);
+    }
+  }
 }

+ 19 - 0
src/room/room.service.ts

@@ -348,4 +348,23 @@ export class RoomService {
       .emit('action', { type: 'leader-dismiss' });
     return Promise.resolve(true);
   }
+
+  /**
+   * 设置助手
+   */
+
+  async handleSetRoomAssitant(
+    socket: Socket,
+    roomId: string,
+    userId: string,
+    status: boolean,
+  ): Promise<boolean> {
+    const assistant = await this.userService.getUsersBy(roomId, userId);
+    assistant.IsOnline = status;
+    const updated = await this.userService.updateUsers(assistant);
+    if (updated) {
+      this.handleRoomStatusAction(socket);
+    }
+    return Promise.resolve(true);
+  }
 }