Skip to content

Commit

Permalink
Merge pull request #20 from SWM-FIRE/FIRE-336-be-특정-방에-접속중인-socket들의-…
Browse files Browse the repository at this point in the history
…id를-모두-반환할-수-있도록-개발

FIRE-336 Update video gateway
  • Loading branch information
IamGroooooot authored Jul 26, 2022
2 parents db84ec9 + 14bdc04 commit ad40b21
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/gateways/video.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,42 @@ export class VideoGateway implements OnGatewayInit, OnGatewayDisconnect {
@WebSocketServer()
server: Server;

private activeSockets: { room: string; id: string }[] = [];
private activeSockets: { room: string; id: string; uid: string }[] = [];

private logger: Logger = new Logger('RoomGateway');

@SubscribeMessage('joinRoom')
public joinRoom(client: Socket, room: string): void {
public joinRoom(client: Socket, { room, uid }): void {
const existingSocket = this.activeSockets?.find(
(socket) => socket.room === room && socket.id === client.id,
);

if (!existingSocket) {
this.activeSockets = [...this.activeSockets, { id: client.id, room }];
this.activeSockets = [
...this.activeSockets,
{ id: client.id, room, uid },
];

client.emit(`${room}-update-user-list`, {
users: this.activeSockets
.filter((socket) => socket.room === room && socket.id !== client.id)
.map((existingSocket) => existingSocket.id),
current: client.id,
.map((existingSocket) => {
return {
id: existingSocket.id,
uid: existingSocket.uid,
};
}),
current: { id: client.id, uid: uid },
});

client.broadcast.emit(`${room}-add-user`, {
user: client.id,
uid: uid,
});
}
return this.logger.log(`Client ${client.id} joined ${room}`);
return this.logger.log(
`Client::socket(${client.id})/uid(${uid}):: joined ${room}`,
);
}

@SubscribeMessage('call-user')
Expand Down

0 comments on commit ad40b21

Please sign in to comment.