mirror of
https://github.com/jcreek/EstimationPoker.git
synced 2026-07-13 19:13:44 +00:00
feat(#25): Add ability to kick a user
This commit is contained in:
@@ -66,6 +66,15 @@ export class Room {
|
||||
return null;
|
||||
}
|
||||
|
||||
getWebSocketByUserId(userId: String): WebSocket | null {
|
||||
for (const [ws, u] of this.users) {
|
||||
if (u.userId === userId) {
|
||||
return ws;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
broadcast(message: any) {
|
||||
this.users.forEach((user, client) => {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
|
||||
@@ -167,6 +167,17 @@ wss.on('connection', (ws: WebSocket, req) => {
|
||||
if (room) {
|
||||
broadcastToRoom(room.id, 'pong');
|
||||
}
|
||||
} else if (data.type === 'kick-user') {
|
||||
console.log('kick user message received');
|
||||
if (room) {
|
||||
const userIdToKick = data.userId;
|
||||
const ws = room.getWebSocketByUserId(userIdToKick);
|
||||
console.log(userIdToKick, ws);
|
||||
if (ws) {
|
||||
console.log('closing ws');
|
||||
ws.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user