gemercheung 2 年之前
父節點
當前提交
6c7ad59ae1
共有 4 個文件被更改,包括 8 次插入8 次删除
  1. 1 0
      src/room/actions/action.d.ts
  2. 5 6
      src/room/actions/actions.service.ts
  3. 1 1
      src/room/room.service.ts
  4. 1 1
      src/room/users/users.service.ts

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

@@ -26,6 +26,7 @@ interface DanmakuDataType {
   userId: string;
   mode: string;
   text: string;
+  roomId?: string;
 }
 
 interface MutedStateType {

+ 5 - 6
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 = () => {
@@ -43,11 +43,12 @@ export class ActionsService {
         params.nickname = data.data.Nickname;
         params.text = data.data.text;
         params.userId = data.data.UserId;
-        this.handleDanmaku(params);
+
+        this.handleDanmaku(params, roomId);
         break;
       case 'users-muted':
         const mutedParams = data as any as MutedStateType;
-        mutedParams.roomId = roomId;
+
         isSocketLeader() && (await this.handleMutedState(mutedParams));
         await this.roomService.handleRoomStatusAction(socket);
         break;
@@ -60,7 +61,6 @@ export class ActionsService {
         break;
       case 'users-kicked':
         const kickParams = data as any as KickStateType;
-        // console.log('kickParams', socket.data.user, kickParams);
         isSocketLeader() && (await this.handleKickState(socket, kickParams));
         break;
       default:
@@ -70,9 +70,8 @@ export class ActionsService {
     socket.broadcast.to(roomId).emit('action', data);
   }
 
-  async handleDanmaku(data: DanmakuDataType) {
+  async handleDanmaku(data: DanmakuDataType, roomId: string) {
     console.log('data', data);
-    const roomId = this.roomService._userInfo.RoomId;
     const time = Date.now();
     if (roomId) {
       this.redis.hset(

+ 1 - 1
src/room/room.service.ts

@@ -17,7 +17,7 @@ export class RoomService {
     private readonly actionsService: ActionsService,
     private readonly delayService: DelayService,
     private readonly tempService: TempService,
-  ) { }
+  ) {}
   public readonly logger = new Logger('user');
   public _sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
   public _userInfo = {} as UserInfoType;

+ 1 - 1
src/room/users/users.service.ts

@@ -10,7 +10,7 @@ export class UsersService {
     @InjectRedis() private readonly redis: Redis,
     @Inject(forwardRef(() => RoomService))
     private roomService: RoomService,
-  ) { }
+  ) {}
 
   async isUserInRooms(RoomId: string, UserId: string): Promise<boolean> {
     const res = await this.redis.hexists(