mirror of
https://github.com/jcreek/EstimationPoker.git
synced 2026-07-13 02:53:46 +00:00
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:
@@ -1,6 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
const changesLog = [
|
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 the ability to kick a user' },
|
||||||
{ timestamp: '2024-01-05T00:00:00', message: 'Added update notes' }
|
{ timestamp: '2024-01-05T00:00:00', message: 'Added update notes' }
|
||||||
];
|
];
|
||||||
@@ -13,8 +20,8 @@
|
|||||||
// Get the user's last visit timestamp from localStorage
|
// Get the user's last visit timestamp from localStorage
|
||||||
let lastVisitTimestamp = localStorage.getItem('lastVisitTimestamp');
|
let lastVisitTimestamp = localStorage.getItem('lastVisitTimestamp');
|
||||||
|
|
||||||
// If lastVisitTimestamp is null or undefined, set it to 0
|
// If lastVisitTimestamp is null or undefined, set it to today's date
|
||||||
lastVisitTimestamp = lastVisitTimestamp ? lastVisitTimestamp : '0';
|
lastVisitTimestamp = lastVisitTimestamp ? lastVisitTimestamp : new Date().toISOString();
|
||||||
|
|
||||||
// Filter changes made after the user's last visit
|
// Filter changes made after the user's last visit
|
||||||
newChanges = changesLog.filter((change) => change.timestamp > lastVisitTimestamp);
|
newChanges = changesLog.filter((change) => change.timestamp > lastVisitTimestamp);
|
||||||
|
|||||||
@@ -171,12 +171,16 @@ wss.on('connection', (ws: WebSocket, req) => {
|
|||||||
console.log('kick user message received');
|
console.log('kick user message received');
|
||||||
if (room) {
|
if (room) {
|
||||||
const userIdToKick = data.userId;
|
const userIdToKick = data.userId;
|
||||||
|
|
||||||
const ws = room.getWebSocketByUserId(userIdToKick);
|
const ws = room.getWebSocketByUserId(userIdToKick);
|
||||||
console.log(userIdToKick, ws);
|
console.log(userIdToKick, ws);
|
||||||
if (ws) {
|
if (ws) {
|
||||||
console.log('closing ws');
|
console.log('closing ws');
|
||||||
ws.close();
|
ws.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove them from the room even if the active websocket can't be found or can't be closed
|
||||||
|
room.removeUser(userIdToKick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user