Merge pull request #31 from jcreek/30-kick-user-does-not-remove-a-user-from-the-room-if-their-websocket-connection-is-closed

30 kick user does not remove a user from the room if their websocket connection is closed
This commit is contained in:
Josh Creek
2024-04-04 12:14:12 +01:00
committed by GitHub
2 changed files with 14 additions and 3 deletions
+10 -3
View File
@@ -1,6 +1,13 @@
<script lang="ts">
const changesLog = [
{ timestamp: '2024-02-11T19:00:00', message: 'Added celebration when all users have the same estimate (cred: O. Nicholass)' },
{
timestamp: '2024-02-11T19:00:00',
message: 'Added fix to ensure that kicking a user always works'
},
{
timestamp: '2024-02-11T19:00:00',
message: 'Added celebration when all users have the same estimate (cred: O. Nicholass)'
},
{ timestamp: '2024-01-05T00:00:00', message: 'Added the ability to kick a user' },
{ timestamp: '2024-01-05T00:00:00', message: 'Added update notes' }
];
@@ -13,8 +20,8 @@
// Get the user's last visit timestamp from localStorage
let lastVisitTimestamp = localStorage.getItem('lastVisitTimestamp');
// If lastVisitTimestamp is null or undefined, set it to 0
lastVisitTimestamp = lastVisitTimestamp ? lastVisitTimestamp : '0';
// If lastVisitTimestamp is null or undefined, set it to today's date
lastVisitTimestamp = lastVisitTimestamp ? lastVisitTimestamp : new Date().toISOString();
// Filter changes made after the user's last visit
newChanges = changesLog.filter((change) => change.timestamp > lastVisitTimestamp);
+4
View File
@@ -171,12 +171,16 @@ wss.on('connection', (ws: WebSocket, req) => {
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();
}
// Remove them from the room even if the active websocket can't be found or can't be closed
room.removeUser(userIdToKick);
}
}
});