|
@@ -10,7 +10,7 @@ import { UsersService } from './users/users.service';
|
|
export class RoomService {
|
|
export class RoomService {
|
|
constructor(
|
|
constructor(
|
|
@Inject(forwardRef(() => SocketGateway))
|
|
@Inject(forwardRef(() => SocketGateway))
|
|
- private readonly socketGateway: SocketGateway,
|
|
|
|
|
|
+ public readonly socketGateway: SocketGateway,
|
|
@InjectRedis() private readonly redis: Redis,
|
|
@InjectRedis() private readonly redis: Redis,
|
|
private readonly userService: UsersService,
|
|
private readonly userService: UsersService,
|
|
private readonly actionsService: ActionsService,
|
|
private readonly actionsService: ActionsService,
|
|
@@ -25,7 +25,7 @@ export class RoomService {
|
|
private get _userId(): string {
|
|
private get _userId(): string {
|
|
return this._userInfo.UserId;
|
|
return this._userInfo.UserId;
|
|
}
|
|
}
|
|
- private get _isLeader(): boolean {
|
|
|
|
|
|
+ public get _isLeader(): boolean {
|
|
return this._userInfo.Role === 'leader';
|
|
return this._userInfo.Role === 'leader';
|
|
}
|
|
}
|
|
|
|
|
|
@@ -60,7 +60,7 @@ export class RoomService {
|
|
);
|
|
);
|
|
const roomUsers = await this.userService.getRoomUsers(this._roomId);
|
|
const roomUsers = await this.userService.getRoomUsers(this._roomId);
|
|
this.isJoin &&
|
|
this.isJoin &&
|
|
- this.socketGateway.server.to(this._roomId).emit('action', {
|
|
|
|
|
|
+ this.socketGateway._socket.to(this._roomId).emit('action', {
|
|
type: 'rooms-status',
|
|
type: 'rooms-status',
|
|
members: roomUsers,
|
|
members: roomUsers,
|
|
});
|
|
});
|
|
@@ -76,7 +76,7 @@ export class RoomService {
|
|
false,
|
|
false,
|
|
);
|
|
);
|
|
const roomUsers = await this.userService.getRoomUsers(this._roomId);
|
|
const roomUsers = await this.userService.getRoomUsers(this._roomId);
|
|
- this.socketGateway.server.to(this._roomId).emit('action', {
|
|
|
|
|
|
+ this.socketGateway._socket.to(this._roomId).emit('action', {
|
|
type: 'rooms-status',
|
|
type: 'rooms-status',
|
|
members: roomUsers,
|
|
members: roomUsers,
|
|
});
|
|
});
|
|
@@ -106,7 +106,7 @@ export class RoomService {
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
blockJoin = true;
|
|
blockJoin = true;
|
|
- this.socketGateway.server.emit('action', {
|
|
|
|
|
|
+ this.socketGateway._socket.emit('action', {
|
|
type: 'invalid-master',
|
|
type: 'invalid-master',
|
|
code: 303,
|
|
code: 303,
|
|
});
|
|
});
|
|
@@ -120,17 +120,28 @@ export class RoomService {
|
|
|
|
|
|
if (!blockJoin) {
|
|
if (!blockJoin) {
|
|
if (!isExist) {
|
|
if (!isExist) {
|
|
- this.userService.insertUser(this._userInfo);
|
|
|
|
|
|
+ await this.userService.insertUser(this._userInfo);
|
|
} else {
|
|
} else {
|
|
- this.userService.updateUsers(this._userInfo);
|
|
|
|
|
|
+ const updated = await this.userService.updateUsers(this._userInfo);
|
|
|
|
+ if (!updated) {
|
|
|
|
+ this.socketGateway._socket.emit('action', {
|
|
|
|
+ type: 'error',
|
|
|
|
+ code: 405,
|
|
|
|
+ });
|
|
|
|
+ this.logger.warn(
|
|
|
|
+ `same userId in room not matchRole `,
|
|
|
|
+ 'join-error',
|
|
|
|
+ );
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
const roomUsers = await this.userService.getRoomUsers(this._roomId);
|
|
const roomUsers = await this.userService.getRoomUsers(this._roomId);
|
|
- this.socketGateway.server.emit('join', {
|
|
|
|
|
|
+ this.socketGateway._socket.emit('join', {
|
|
user: this._userInfo,
|
|
user: this._userInfo,
|
|
members: roomUsers,
|
|
members: roomUsers,
|
|
});
|
|
});
|
|
if (!this._userInfo.IsClient) {
|
|
if (!this._userInfo.IsClient) {
|
|
- this.socketGateway.server.to(this._roomId).emit('action', {
|
|
|
|
|
|
+ this.socketGateway._socket.broadcast.to(this._roomId).emit('action', {
|
|
type: 'user-join',
|
|
type: 'user-join',
|
|
user: this._userInfo,
|
|
user: this._userInfo,
|
|
members: roomUsers,
|
|
members: roomUsers,
|
|
@@ -143,7 +154,7 @@ export class RoomService {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- this.socketGateway.server.emit('action', { type: 'error', code: 403 });
|
|
|
|
|
|
+ this.socketGateway._socket.emit('action', { type: 'error', code: 403 });
|
|
this.logger.warn(`403:not roomId and userId`, 'join-error');
|
|
this.logger.warn(`403:not roomId and userId`, 'join-error');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -153,7 +164,6 @@ export class RoomService {
|
|
*/
|
|
*/
|
|
async handleUserAction(message: any) {
|
|
async handleUserAction(message: any) {
|
|
this.actionsService.handleAllAction(message);
|
|
this.actionsService.handleAllAction(message);
|
|
- // this.socketGateway.server.to(this._roomId).emit('action', message);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -161,7 +171,7 @@ export class RoomService {
|
|
* @param message
|
|
* @param message
|
|
*/
|
|
*/
|
|
async handleSyncAction(message: any) {
|
|
async handleSyncAction(message: any) {
|
|
- this.socketGateway.server.to(this._roomId).emit('sync', message);
|
|
|
|
|
|
+ this.socketGateway._socket.broadcast.to(this._roomId).emit('sync', message);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -169,7 +179,9 @@ export class RoomService {
|
|
* @param message
|
|
* @param message
|
|
*/
|
|
*/
|
|
async handlePaintAction(message: any) {
|
|
async handlePaintAction(message: any) {
|
|
- this.socketGateway.server.to(this._roomId).emit('paint', message);
|
|
|
|
|
|
+ this.socketGateway._socket.broadcast
|
|
|
|
+ .to(this._roomId)
|
|
|
|
+ .emit('paint', message);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -178,7 +190,7 @@ export class RoomService {
|
|
*/
|
|
*/
|
|
async handleKickAction(userId: string) {
|
|
async handleKickAction(userId: string) {
|
|
await this.userService.deleteRoomUser(this._roomId, userId);
|
|
await this.userService.deleteRoomUser(this._roomId, userId);
|
|
- this.socketGateway.server.to(this._roomId).emit('action', {
|
|
|
|
|
|
+ this.socketGateway._socket.broadcast.to(this._roomId).emit('action', {
|
|
type: 'kick-user',
|
|
type: 'kick-user',
|
|
data: {
|
|
data: {
|
|
userId: userId,
|
|
userId: userId,
|
|
@@ -192,7 +204,7 @@ export class RoomService {
|
|
async handleRoomDismiss(): Promise<void> {
|
|
async handleRoomDismiss(): Promise<void> {
|
|
await this.userService.delRoom(this._roomId);
|
|
await this.userService.delRoom(this._roomId);
|
|
await this.userService.delRoomConfig(this._roomId);
|
|
await this.userService.delRoomConfig(this._roomId);
|
|
- this.socketGateway.server
|
|
|
|
|
|
+ this.socketGateway._socket
|
|
.to(this._roomId)
|
|
.to(this._roomId)
|
|
.emit('action', { type: 'leader-dismiss' });
|
|
.emit('action', { type: 'leader-dismiss' });
|
|
}
|
|
}
|