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
* 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':