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 showRestartButton = false;
|
||||||
let showEstimates = false;
|
let showEstimates = false;
|
||||||
let disableEstimates: boolean = false;
|
let disableEstimates: boolean = false;
|
||||||
|
let audioElement;
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
showModal = false;
|
showModal = false;
|
||||||
@@ -134,6 +135,8 @@
|
|||||||
if (usersList && typeof usersList.triggerEmoji === 'function') {
|
if (usersList && typeof usersList.triggerEmoji === 'function') {
|
||||||
usersList.triggerEmoji(message.cardId, message.emoji);
|
usersList.triggerEmoji(message.cardId, message.emoji);
|
||||||
}
|
}
|
||||||
|
} else if (message.type === 'nudge') {
|
||||||
|
audioElement.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,6 +193,8 @@
|
|||||||
<EstimateGroupsList {estimateGroups} />
|
<EstimateGroupsList {estimateGroups} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<audio src="/call-to-attention.mp3" bind:this={audioElement}></audio>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.button-container {
|
.button-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -26,6 +26,15 @@ export class Room {
|
|||||||
return this.users.get(ws);
|
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) {
|
broadcast(message: any) {
|
||||||
this.users.forEach((user, client) => {
|
this.users.forEach((user, client) => {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
|
|||||||
+32
-2
@@ -96,13 +96,43 @@ wss.on('connection', (ws: WebSocket, req) => {
|
|||||||
estimate
|
estimate
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const users = room.getUsers();
|
||||||
|
let timeout = undefined;
|
||||||
|
|
||||||
const allEstimates = room.getAllEstimates();
|
const allEstimates = room.getAllEstimates();
|
||||||
if (allEstimates.size === room.getUsers().length) {
|
if (allEstimates.size === users.length) {
|
||||||
const users = room.getUsers();
|
// If all users have estimated, clear the timeout
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = undefined;
|
||||||
|
|
||||||
broadcastToRoom(room.id, {
|
broadcastToRoom(room.id, {
|
||||||
type: 'estimation-closed',
|
type: 'estimation-closed',
|
||||||
groupedEstimates: groupEstimates(users)
|
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