浏览代码

Separates display name and presence status. Triggers separate event for presence status.

master
paweldomas 11 年前
父节点
当前提交
325af308f5
共有 3 个文件被更改,包括 49 次插入26 次删除
  1. 8
    1
      app.js
  2. 6
    0
      muc.js
  3. 35
    25
      videolayout.js

+ 8
- 1
app.js 查看文件

@@ -824,7 +824,7 @@ $(document).bind('presence.muc', function (event, jid, info, pres) {
824 824
         VideoLayout.ensurePeerContainerExists(jid);
825 825
         VideoLayout.setDisplayName(
826 826
                 'participant_' + Strophe.getResourceFromJid(jid),
827
-                info.displayName, info.status);
827
+                info.displayName);
828 828
     }
829 829
 
830 830
     if (focus !== null && info.displayName !== null) {
@@ -832,6 +832,13 @@ $(document).bind('presence.muc', function (event, jid, info, pres) {
832 832
     }
833 833
 });
834 834
 
835
+$(document).bind('presence.status.muc', function (event, jid, info, pres) {
836
+
837
+    VideoLayout.setPresenceStatus(
838
+        'participant_' + Strophe.getResourceFromJid(jid), info.status);
839
+
840
+});
841
+
835 842
 $(document).bind('passwordrequired.muc', function (event, jid) {
836 843
     console.log('on password required', jid);
837 844
 

+ 6
- 0
muc.js 查看文件

@@ -131,6 +131,12 @@ Strophe.addConnectionPlugin('emuc', {
131 131
         // Always trigger presence to update bindings
132 132
         console.log('presence change from', from);
133 133
         $(document).trigger('presence.muc', [from, member, pres]);
134
+
135
+        // Trigger status message update
136
+        if (member.status) {
137
+            $(document).trigger('presence.status.muc', [from, member, pres]);
138
+        }
139
+
134 140
         return true;
135 141
     },
136 142
     onPresenceUnavailable: function (pres) {

+ 35
- 25
videolayout.js 查看文件

@@ -323,35 +323,11 @@ var VideoLayout = (function (my) {
323 323
     /**
324 324
      * Shows the display name for the given video.
325 325
      */
326
-    my.setDisplayName = function(videoSpanId, displayName, statusMsg) {
326
+    my.setDisplayName = function(videoSpanId, displayName) {
327 327
         var nameSpan = $('#' + videoSpanId + '>span.displayname');
328 328
         var defaultLocalDisplayName = "Me";
329 329
         var defaultRemoteDisplayName = "Speaker";
330 330
 
331
-        var statusSpan = $('#' + videoSpanId + '>span.status');
332
-        if (!statusSpan.length)
333
-        {
334
-            //Add status span
335
-            statusSpan = document.createElement('span');
336
-            statusSpan.className = 'status';
337
-            statusSpan.id = videoSpanId + '_status';
338
-            $('#' + videoSpanId)[0].appendChild(statusSpan);
339
-
340
-            statusSpan = $('#' + videoSpanId + '>span.status');
341
-        }
342
-
343
-        // Display status
344
-        if (statusMsg && statusMsg.length)
345
-        {
346
-            $('#' + videoSpanId + '_status').text(statusMsg);
347
-            statusSpan.get(0).setAttribute("style", "display:inline-block;");
348
-        }
349
-        else
350
-        {
351
-            // Hide
352
-            statusSpan.get(0).setAttribute("style", "display:none;");
353
-        }
354
-
355 331
         // If we already have a display name for this video.
356 332
         if (nameSpan.length > 0) {
357 333
             var nameSpanElement = nameSpan.get(0);
@@ -473,6 +449,40 @@ var VideoLayout = (function (my) {
473 449
         }
474 450
     };
475 451
 
452
+    /**
453
+     * Shows the presence status message for the given video.
454
+     */
455
+    my.setPresenceStatus = function (videoSpanId, statusMsg) {
456
+
457
+        if (!$('#' + videoSpanId).length) {
458
+            // No container
459
+            return;
460
+        }
461
+
462
+        var nameSpan = $('#' + videoSpanId + '>span.displayname');
463
+
464
+        var statusSpan = $('#' + videoSpanId + '>span.status');
465
+        if (!statusSpan.length) {
466
+            //Add status span
467
+            statusSpan = document.createElement('span');
468
+            statusSpan.className = 'status';
469
+            statusSpan.id = videoSpanId + '_status';
470
+            $('#' + videoSpanId)[0].appendChild(statusSpan);
471
+
472
+            statusSpan = $('#' + videoSpanId + '>span.status');
473
+        }
474
+
475
+        // Display status
476
+        if (statusMsg && statusMsg.length) {
477
+            $('#' + videoSpanId + '_status').text(statusMsg);
478
+            statusSpan.get(0).setAttribute("style", "display:inline-block;");
479
+        }
480
+        else {
481
+            // Hide
482
+            statusSpan.get(0).setAttribute("style", "display:none;");
483
+        }
484
+    };
485
+
476 486
     /**
477 487
      * Shows a visual indicator for the focus of the conference.
478 488
      * Currently if we're not the owner of the conference we obtain the focus

正在加载...
取消
保存