Announce participant joins and leaves

This commit is contained in:
Storm Dragon
2026-05-21 22:42:52 -04:00
parent eae4afb7ce
commit c3a9b05392
2 changed files with 21 additions and 5 deletions
+11 -2
View File
@@ -189,7 +189,7 @@ function ServerConnection() {
* onuser is called whenever a user in the hall changes. The users * onuser is called whenever a user in the hall changes. The users
* array has already been updated. * 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; this.onuser = null;
/** /**
@@ -450,6 +450,7 @@ ServerConnection.prototype.connect = function(url) {
m.error || null, m.value || null); m.error || null, m.value || null);
break; break;
case 'user': case 'user':
let user = null;
switch(m.kind) { switch(m.kind) {
case 'add': case 'add':
if(m.id in sc.users) if(m.id in sc.users)
@@ -460,6 +461,7 @@ ServerConnection.prototype.connect = function(url) {
data: m.data || {}, data: m.data || {},
streams: {}, streams: {},
}; };
user = sc.users[m.id];
break; break;
case 'change': case 'change':
if(!(m.id in sc.users)) { 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].permissions = m.permissions || [];
sc.users[m.id].data = m.data || {}; sc.users[m.id].data = m.data || {};
} }
user = sc.users[m.id];
break; break;
case 'delete': case 'delete':
if(!(m.id in sc.users)) if(!(m.id in sc.users))
console.warn(`Unknown user ${m.id} ${m.username}`); 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) { for(let t in sc.transferredFiles) {
let f = sc.transferredFiles[t]; let f = sc.transferredFiles[t];
if(f.userid === m.id) if(f.userid === m.id)
@@ -491,7 +500,7 @@ ServerConnection.prototype.connect = function(url) {
return; return;
} }
if(sc.onuser) if(sc.onuser)
sc.onuser.call(sc, m.id, m.kind); sc.onuser.call(sc, m.id, m.kind, user);
break; break;
case 'chat': case 'chat':
case 'chathistory': case 'chathistory':
+10 -3
View File
@@ -1876,19 +1876,26 @@ function delUser(id) {
/** /**
* @param {string} id * @param {string} id
* @param {string} kind * @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) { switch(kind) {
case 'add': case 'add':
addUser(id, serverConnection.users[id]); addUser(id, serverConnection.users[id]);
if(userNotificationSoundsReady && id !== serverConnection.id) if(userNotificationSoundsReady && isRemote) {
localMessage(`${username} joined the hall.`);
playNotificationSound('user-joined'); playNotificationSound('user-joined');
}
if(Object.keys(serverConnection.users).length == 3) if(Object.keys(serverConnection.users).length == 3)
reconsiderSendParameters(); reconsiderSendParameters();
break; break;
case 'delete': case 'delete':
if(userNotificationSoundsReady && id !== serverConnection.id) if(userNotificationSoundsReady && isRemote) {
localMessage(`${username} left the hall.`);
playNotificationSound('user-left'); playNotificationSound('user-left');
}
delUser(id); delUser(id);
if(Object.keys(serverConnection.users).length < 3) if(Object.keys(serverConnection.users).length < 3)
scheduleReconsiderParameters(); scheduleReconsiderParameters();