diff --git a/server/socket/src/gateway/room.gateway.ts b/server/socket/src/gateway/room.gateway.ts index 731386d4..eb1f336f 100644 --- a/server/socket/src/gateway/room.gateway.ts +++ b/server/socket/src/gateway/room.gateway.ts @@ -31,28 +31,44 @@ export class RoomGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa } @SubscribeMessage('join-room') - handleJoinRoom(client: Socket, { field, img, nickname, roomId }: IRoomRequest): void { + handleJoinRoom(client: Socket, { field, img, nickname, roomId, maxHead }: IRoomRequest): void { + client.leave(client.id); //verify-room에서 생성한 룸을 삭제합니다. 이제 사용될 일이 없어서.. client.join(roomId); - if (!this.userList[roomId]) this.userList[roomId] = {}; - this.userList[roomId][nickname] = { + if (!this.userList[roomId]) this.userList[roomId] = { list: {}, maxHead: maxHead }; + this.userList[roomId]['list'][nickname] = { field: field, img: img, }; - this.server.to(roomId).emit('user-list', this.userList[roomId]); + this.server.to(roomId).emit('user-list', this.userList[roomId]['list']); } @SubscribeMessage('leave-room') handleLeaveRoom(client: Socket, { nickname, roomId }: IRoomRequest): void { client.leave(roomId); - delete this.userList[roomId][nickname]; - this.server.to(roomId).emit('user-list', this.userList[roomId]); + delete this.userList[roomId]['list'][nickname]; + this.server.to(roomId).emit('user-list', this.userList[roomId]['list']); } @SubscribeMessage('kick-room') handleKickRoom(client: Socket, { roomId, kickNickname }: IRoomRequest): void { if (!kickNickname) return; - delete this.userList[roomId][kickNickname]; - this.server.to(roomId).emit('user-list', this.userList[roomId]); + delete this.userList[roomId]['list'][kickNickname]; + this.server.to(roomId).emit('user-list', this.userList[roomId]['list']); + } + + @SubscribeMessage('verify-room') + handleVerifyRoom(client: Socket, { roomId }: IRoomRequest): void { + client.join(client.id); //해당 사용자한테만 전송될 수 있게 + if (!this.userList[roomId]) { + this.server.to(client.id).emit('is-verify', true); + return; + } + if (Object.keys(this.userList[roomId]['list']).length < this.userList[roomId]['maxHead']) { + this.server.to(client.id).emit('is-verify', true); + return; + } + + this.server.to(client.id).emit('is-verify', false); } afterInit(server: Server) {