Skip to content

Commit

Permalink
fix(채팅): 소켓 이벤트 미발행 해결 (스코프 문제)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsween5723 committed Jan 8, 2024
1 parent 9d6e86a commit 5fc226e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/room/room.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export class RoomGateway
extends CommonGateway
implements OnGatewayDisconnect, OnGatewayInit, OnGatewayConnection
{
@WebSocketServer()
public io;

constructor(protected jwtService: CustomJwtService) {
super(jwtService);
}
Expand Down
8 changes: 6 additions & 2 deletions src/room/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class RoomService {
);
const participantIds = this.getParticipantIds(meeting);
await this.userService.addRoom(chatRoom, participantIds);
this.roomGateway.io
this.roomGateway.io.server
.of('/chat-rooms')
.in(participantIds)
.emit('room-append', { ...chatRoom, id: chatRoom._id, meeting });
}
Expand Down Expand Up @@ -117,17 +118,20 @@ export class RoomService {
console.log(createdChat);
console.log(chat.roomId);
this.detailGateway.io.server
.of(`/chat-rooms/${chat.roomId}`)
.to(chat.roomId)
.emit('chat-append', createdChat);
const sockets = await this.detailGateway.io.server
.of(`/chat-rooms/${chat.roomId}`)
.in(chat.roomId)
.fetchSockets();
const alreadyIn = sockets.map((socket) => socket.handshake.auth.userId);
const notIn = users
.filter((user) => !alreadyIn.includes(user.id))
.map((user) => user.id);
await this.userService.unreadItemPlus(notIn, room._id);
this.roomGateway.io
this.roomGateway.io.server
.of('/chat-rooms')
.to(users.map((user) => user.id))
.emit('last-chat-append', createdChat);
return createdChat;
Expand Down

0 comments on commit 5fc226e

Please sign in to comment.