Browse Source

use JitsiParticipant to handle user roles

j8
isymchych 9 years ago
parent
commit
fbcd2d2320
3 changed files with 1713 additions and 1131 deletions
  1. 18
    11
      app.js
  2. 1662
    1081
      lib-jitsi-meet.js
  3. 33
    39
      modules/UI/UI.js

+ 18
- 11
app.js View File

@@ -161,12 +161,10 @@ function initConference(localTracks, connection) {
161 161
         disableAudioLevels: config.disableAudioLevels
162 162
     });
163 163
 
164
-    var users = {};
165
-
166 164
     APP.conference.localId = room.myUserId();
167 165
     Object.defineProperty(APP.conference, "membersCount", {
168 166
         get: function () {
169
-            return Object.keys(users).length; // FIXME maybe +1?
167
+            return room.getParticipants().length; // FIXME maybe +1?
170 168
         }
171 169
     });
172 170
 
@@ -175,9 +173,9 @@ function initConference(localTracks, connection) {
175 173
             return APP.settings.getDisplayName();
176 174
         }
177 175
 
178
-        var user = users[id];
179
-        if (user && user.displayName) {
180
-            return user.displayName;
176
+        var participant = room.getParticipantById(id);
177
+        if (participant && participant.getDisplayName()) {
178
+            return participant.getDisplayName();
181 179
         }
182 180
     }
183 181
 
@@ -191,19 +189,28 @@ function initConference(localTracks, connection) {
191 189
 
192 190
 
193 191
     room.on(ConferenceEvents.USER_JOINED, function (id) {
194
-        users[id] = {
195
-            displayName: undefined,
196
-            tracks: []
197
-        };
198 192
         // FIXME email???
199 193
         APP.UI.addUser(id);
200 194
     });
201 195
     room.on(ConferenceEvents.USER_LEFT, function (id) {
202
-        delete users[id];
203 196
         APP.UI.removeUser(id);
204 197
     });
205 198
 
206 199
 
200
+    room.on(ConferenceEvents.USER_ROLE_CHANGED, function (id, role) {
201
+        if (APP.conference.isLocalId(id)) {
202
+            console.info(`My role changed, new role: ${role}`);
203
+            APP.conference.isModerator = room.isModerator();
204
+            APP.UI.updateLocalRole(room.isModerator());
205
+        } else {
206
+            var user = room.getParticipantById(id);
207
+            if (user) {
208
+                APP.UI.updateUserRole(user);
209
+            }
210
+        }
211
+    });
212
+
213
+
207 214
     room.on(ConferenceEvents.TRACK_MUTE_CHANGED, function (track) {
208 215
         // FIXME handle mute
209 216
     });

+ 1662
- 1081
lib-jitsi-meet.js
File diff suppressed because it is too large
View File


+ 33
- 39
modules/UI/UI.js View File

@@ -308,31 +308,6 @@ function initEtherpad(name) {
308 308
     Etherpad.init(name);
309 309
 }
310 310
 
311
-function onLocalRoleChanged(jid, info, pres, isModerator) {
312
-    console.info("My role changed, new role: " + info.role);
313
-    onModeratorStatusChanged(isModerator);
314
-    VideoLayout.showModeratorIndicator();
315
-    SettingsMenu.onRoleChanged();
316
-
317
-    if (isModerator) {
318
-        Authentication.closeAuthenticationWindow();
319
-        messageHandler.notify(null, "notify.me",
320
-            'connected', "notify.moderator");
321
-
322
-        Toolbar.checkAutoRecord();
323
-    }
324
-}
325
-
326
-function onModeratorStatusChanged(isModerator) {
327
-    Toolbar.showSipCallButton(isModerator);
328
-    Toolbar.showRecordingButton(
329
-        isModerator); //&&
330
-    // FIXME:
331
-    // Recording visible if
332
-    // there are at least 2(+ 1 focus) participants
333
-    //Object.keys(connection.emuc.members).length >= 3);
334
-}
335
-
336 311
 UI.notifyPasswordRequired = function (callback) {
337 312
     // password is required
338 313
     Toolbar.lockLockButton();
@@ -413,24 +388,43 @@ function onPeerVideoTypeChanged(resourceJid, newVideoType) {
413 388
     VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
414 389
 }
415 390
 
416
-function onMucRoleChanged(role, displayName) {
391
+UI.updateLocalRole = function (isModerator) {
417 392
     VideoLayout.showModeratorIndicator();
418 393
 
419
-    if (role === 'moderator') {
420
-        var messageKey, messageOptions = {};
421
-        if (!displayName) {
422
-            messageKey = "notify.grantedToUnknown";
423
-        }
424
-        else {
425
-            messageKey = "notify.grantedTo";
426
-            messageOptions = {to: displayName};
427
-        }
394
+    Toolbar.showSipCallButton(isModerator);
395
+    Toolbar.showRecordingButton(isModerator);
396
+    SettingsMenu.onRoleChanged();
397
+
398
+    if (isModerator) {
399
+        Authentication.closeAuthenticationWindow();
400
+        messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
401
+
402
+        Toolbar.checkAutoRecord();
403
+    }
404
+};
405
+
406
+UI.updateUserRole = function (user) {
407
+    VideoLayout.showModeratorIndicator();
408
+
409
+    if (!user.isModerator()) {
410
+        return;
411
+    }
412
+
413
+    var displayName = user.getDisplayName();
414
+    if (displayName) {
428 415
         messageHandler.notify(
429
-            displayName,'notify.somebody',
430
-            'connected', messageKey,
431
-            messageOptions);
416
+            displayName, 'notify.somebody',
417
+            'connected', 'notify.grantedTo', {
418
+                to: displayName
419
+            }
420
+        );
421
+    } else {
422
+        messageHandler.notify(
423
+            '', 'notify.somebody',
424
+            'connected', 'notify.grantedToUnknown', {}
425
+        );
432 426
     }
433
-}
427
+};
434 428
 
435 429
 UI.notifyAuthRequired = function (intervalCallback) {
436 430
     Authentication.openAuthenticationDialog(

Loading…
Cancel
Save