Announce participant joins and leaves
This commit is contained in:
+11
-2
@@ -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':
|
||||
|
||||
+10
-3
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user