mirror of
https://github.com/jcreek/EstimationPoker.git
synced 2026-07-12 18:43:47 +00:00
feat(#4): Add sound alert for a user who hasn't done an estimate when everyone else has
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
let showRestartButton = false;
|
||||
let showEstimates = false;
|
||||
let disableEstimates: boolean = false;
|
||||
let audioElement;
|
||||
|
||||
function closeModal() {
|
||||
showModal = false;
|
||||
@@ -134,6 +135,8 @@
|
||||
if (usersList && typeof usersList.triggerEmoji === 'function') {
|
||||
usersList.triggerEmoji(message.cardId, message.emoji);
|
||||
}
|
||||
} else if (message.type === 'nudge') {
|
||||
audioElement.play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +193,8 @@
|
||||
<EstimateGroupsList {estimateGroups} />
|
||||
{/if}
|
||||
|
||||
<audio src="/call-to-attention.mp3" bind:this={audioElement}></audio>
|
||||
|
||||
<style>
|
||||
.button-container {
|
||||
display: flex;
|
||||
|
||||
@@ -26,6 +26,15 @@ export class Room {
|
||||
return this.users.get(ws);
|
||||
}
|
||||
|
||||
getWebSocketByUser(user: User): WebSocket | null {
|
||||
for (const [ws, u] of this.users) {
|
||||
if (u === user) {
|
||||
return ws;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
broadcast(message: any) {
|
||||
this.users.forEach((user, client) => {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
|
||||
+32
-2
@@ -96,13 +96,43 @@ wss.on('connection', (ws: WebSocket, req) => {
|
||||
estimate
|
||||
});
|
||||
|
||||
const allEstimates = room.getAllEstimates();
|
||||
if (allEstimates.size === room.getUsers().length) {
|
||||
const users = room.getUsers();
|
||||
let timeout = undefined;
|
||||
|
||||
const allEstimates = room.getAllEstimates();
|
||||
if (allEstimates.size === users.length) {
|
||||
// If all users have estimated, clear the timeout
|
||||
clearTimeout(timeout);
|
||||
timeout = undefined;
|
||||
|
||||
broadcastToRoom(room.id, {
|
||||
type: 'estimation-closed',
|
||||
groupedEstimates: groupEstimates(users)
|
||||
});
|
||||
} else if (allEstimates.size === users.length - 1) {
|
||||
// The last user has 30 seconds to add their estimation, otherwise send the nudge message
|
||||
let notEstimatedUser: User | undefined = undefined;
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
if (!allEstimates.has(users[i].name)) {
|
||||
notEstimatedUser = users[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (notEstimatedUser !== undefined) {
|
||||
const ws = room.getWebSocketByUser(notEstimatedUser);
|
||||
if (ws) {
|
||||
// Cancel the old timeout if it's still running
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
// Set a new timeout
|
||||
timeout = setTimeout(() => {
|
||||
if (!room!.getAllEstimates().has(notEstimatedUser!.name)) {
|
||||
ws.send(JSON.stringify({ type: 'nudge' }));
|
||||
}
|
||||
}, 30000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user