From c3a9b053922b7c65dde9f5878fc29432aca4af28 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 21 May 2026 22:42:52 -0400 Subject: [PATCH] Announce participant joins and leaves --- static/protocol.js | 13 +++++++++++-- static/skald.js | 13 ++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/static/protocol.js b/static/protocol.js index 20a7964..11ebe7e 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -189,7 +189,7 @@ function ServerConnection() { * onuser is called whenever a user in the hall changes. The users * array has already been updated. * - * @type{(this: ServerConnection, id: string, kind: string) => void} + * @type{(this: ServerConnection, id: string, kind: string, user: user|null) => void} */ this.onuser = null; /** @@ -450,6 +450,7 @@ ServerConnection.prototype.connect = function(url) { m.error || null, m.value || null); break; case 'user': + let user = null; switch(m.kind) { case 'add': if(m.id in sc.users) @@ -460,6 +461,7 @@ ServerConnection.prototype.connect = function(url) { data: m.data || {}, streams: {}, }; + user = sc.users[m.id]; break; case 'change': if(!(m.id in sc.users)) { @@ -475,10 +477,17 @@ ServerConnection.prototype.connect = function(url) { sc.users[m.id].permissions = m.permissions || []; sc.users[m.id].data = m.data || {}; } + user = sc.users[m.id]; break; case 'delete': if(!(m.id in sc.users)) console.warn(`Unknown user ${m.id} ${m.username}`); + user = sc.users[m.id] || { + username: m.username || '', + permissions: [], + data: {}, + streams: {}, + }; for(let t in sc.transferredFiles) { let f = sc.transferredFiles[t]; if(f.userid === m.id) @@ -491,7 +500,7 @@ ServerConnection.prototype.connect = function(url) { return; } if(sc.onuser) - sc.onuser.call(sc, m.id, m.kind); + sc.onuser.call(sc, m.id, m.kind, user); break; case 'chat': case 'chathistory': diff --git a/static/skald.js b/static/skald.js index 2e9f97b..7d727ce 100644 --- a/static/skald.js +++ b/static/skald.js @@ -1876,19 +1876,26 @@ function delUser(id) { /** * @param {string} id * @param {string} kind + * @param {user|null} userinfo */ -function gotUser(id, kind) { +function gotUser(id, kind, userinfo) { + let username = userinfo && userinfo.username ? userinfo.username : '(anon)'; + let isRemote = id !== serverConnection.id; switch(kind) { case 'add': addUser(id, serverConnection.users[id]); - if(userNotificationSoundsReady && id !== serverConnection.id) + if(userNotificationSoundsReady && isRemote) { + localMessage(`${username} joined the hall.`); playNotificationSound('user-joined'); + } if(Object.keys(serverConnection.users).length == 3) reconsiderSendParameters(); break; case 'delete': - if(userNotificationSoundsReady && id !== serverConnection.id) + if(userNotificationSoundsReady && isRemote) { + localMessage(`${username} left the hall.`); playNotificationSound('user-left'); + } delUser(id); if(Object.keys(serverConnection.users).length < 3) scheduleReconsiderParameters();