|
@@ -1,10 +1,9 @@
|
|
|
-import { InjectRedis } from '@liaoliaots/nestjs-redis';
|
|
|
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
|
|
|
-import { Redis } from 'ioredis';
|
|
|
import { Socket } from 'socket.io';
|
|
|
|
|
|
import { SocketGateway } from 'src/socket/socket.gateway';
|
|
|
import { ActionsService } from './actions/actions.service';
|
|
|
+import { DelayService } from './delay/delay.service';
|
|
|
import { UsersService } from './users/users.service';
|
|
|
|
|
|
@Injectable()
|
|
@@ -12,10 +11,11 @@ export class RoomService {
|
|
|
constructor(
|
|
|
@Inject(forwardRef(() => SocketGateway))
|
|
|
public readonly socketGateway: SocketGateway,
|
|
|
- @InjectRedis() private readonly redis: Redis,
|
|
|
+ // @InjectRedis() private readonly redis: Redis,
|
|
|
private readonly userService: UsersService,
|
|
|
private readonly actionsService: ActionsService,
|
|
|
- ) { }
|
|
|
+ private readonly delayService: DelayService,
|
|
|
+ ) {}
|
|
|
public readonly logger = new Logger('user');
|
|
|
public _sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
|
public _userInfo = {} as UserInfoType;
|
|
@@ -91,6 +91,9 @@ export class RoomService {
|
|
|
this.initUserProfile(userInfo);
|
|
|
socket.data.user = this._userInfo;
|
|
|
await this.handleUserOnline(socket);
|
|
|
+ //test
|
|
|
+ this.delayService.handleOffline();
|
|
|
+
|
|
|
let blockJoin = false;
|
|
|
if (this._roomId?.length && this._userId?.length) {
|
|
|
//房主设置房间配置
|
|
@@ -204,7 +207,6 @@ export class RoomService {
|
|
|
});
|
|
|
}
|
|
|
const res = await this.userService.deleteRoomUser(RoomId, userId);
|
|
|
- // console.log('kick-user', delUser.id, RoomId, userId);
|
|
|
if (res) {
|
|
|
this.socketGateway.server.to(RoomId).emit('action', {
|
|
|
type: 'user-leave',
|
|
@@ -245,11 +247,15 @@ export class RoomService {
|
|
|
const res = await this.userService.deleteRoomUser(roomId, userId);
|
|
|
console.log('user-exit', delUser.id, roomId, userId);
|
|
|
if (res) {
|
|
|
- this.socketGateway.server.to(roomId).emit('action', {
|
|
|
- type: 'user-leave',
|
|
|
- user: delUser,
|
|
|
- members: filterRoomUser,
|
|
|
- });
|
|
|
+ if (socket.data.user?.Role === 'leader') {
|
|
|
+ this.handleRoomDismiss(roomId);
|
|
|
+ } else {
|
|
|
+ this.socketGateway.server.to(roomId).emit('action', {
|
|
|
+ type: 'user-leave',
|
|
|
+ user: delUser,
|
|
|
+ members: filterRoomUser,
|
|
|
+ });
|
|
|
+ }
|
|
|
socket.disconnect(true);
|
|
|
}
|
|
|
}
|