Просмотр исходного кода

Merge pull request #141 from bgrozev/raise-hand2

Raise hand2
dev1
yanas 9 лет назад
Родитель
Сommit
9d5caca9de
4 измененных файлов: 75 добавлений и 11 удалений
  1. 17
    0
      JitsiConference.js
  2. 6
    1
      JitsiConferenceEvents.js
  3. 29
    0
      JitsiParticipant.js
  4. 23
    10
      modules/xmpp/ChatRoom.js

+ 17
- 0
JitsiConference.js Просмотреть файл

@@ -892,6 +892,13 @@ JitsiConference.prototype.getConnectionTimes = function () {
892 892
     return this.room.connectionTimes;
893 893
 };
894 894
 
895
+/**
896
+ * Sets a property for the local participant.
897
+ */
898
+JitsiConference.prototype.setLocalParticipantProperty = function(name, value) {
899
+    this.sendCommand("jitsi_participant_" + name, {value: value});
900
+};
901
+
895 902
 /**
896 903
  * Sends the given feedback through CallStats if enabled.
897 904
  *
@@ -1055,6 +1062,16 @@ function setupListeners(conference) {
1055 1062
     conference.room.addListener(XMPPEvents.FOCUS_LEFT, function () {
1056 1063
         conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.FOCUS_LEFT);
1057 1064
     });
1065
+    conference.room.setParticipantPropertyListener(function (node, from) {
1066
+        var participant = conference.getParticipantById(from);
1067
+        if (!participant) {
1068
+            return;
1069
+        }
1070
+
1071
+        participant.setProperty(
1072
+            node.tagName.substring("jitsi_participant_".length),
1073
+            node.value);
1074
+    });
1058 1075
 //    FIXME
1059 1076
 //    conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
1060 1077
 //        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);

+ 6
- 1
JitsiConferenceEvents.js Просмотреть файл

@@ -130,7 +130,12 @@ var JitsiConferenceEvents = {
130 130
     /**
131 131
      * Indicates that authentication status changed.
132 132
      */
133
-    AUTH_STATUS_CHANGED: "conference.auth_status_changed"
133
+    AUTH_STATUS_CHANGED: "conference.auth_status_changed",
134
+    /**
135
+     * Indicates that a the value of a specific property of a specific
136
+     * participant has changed.
137
+     */
138
+    PARTICIPANT_PROPERTY_CHANGED: "conference.participant_property_changed"
134 139
 };
135 140
 
136 141
 module.exports = JitsiConferenceEvents;

+ 29
- 0
JitsiParticipant.js Просмотреть файл

@@ -1,4 +1,5 @@
1 1
 /* global Strophe */
2
+var JitsiConferenceEvents = require('./JitsiConferenceEvents');
2 3
 
3 4
 /**
4 5
  * Represents a participant in (a member of) a conference.
@@ -21,6 +22,7 @@ function JitsiParticipant(jid, conference, displayName, isHidden){
21 22
         video: undefined
22 23
     };
23 24
     this._isHidden = isHidden;
25
+    this._properties = {};
24 26
 }
25 27
 
26 28
 /**
@@ -30,6 +32,33 @@ JitsiParticipant.prototype.getConference = function() {
30 32
     return this._conference;
31 33
 };
32 34
 
35
+/**
36
+ * Gets the value of a property of this participant.
37
+ */
38
+JitsiParticipant.prototype.getProperty = function(name) {
39
+    return this._properties[name];
40
+};
41
+
42
+/**
43
+ * Sets the value of a property of this participant, and fires an event if the
44
+ * value has changed.
45
+ * @name the name of the property.
46
+ * @value the value to set.
47
+ */
48
+JitsiParticipant.prototype.setProperty = function(name, value) {
49
+    var oldValue = this._properties[name];
50
+    this._properties[name] = value;
51
+
52
+    if (value !== oldValue) {
53
+        this._conference.eventEmitter.emit(
54
+            JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
55
+            this,
56
+            name,
57
+            oldValue,
58
+            value);
59
+    }
60
+};
61
+
33 62
 /**
34 63
  * @returns {Array.<JitsiTrack>} The list of media tracks for this participant.
35 64
  */

+ 23
- 10
modules/xmpp/ChatRoom.js Просмотреть файл

@@ -87,6 +87,7 @@ function ChatRoom(connection, jid, password, XMPP, options, settings) {
87 87
     this.phoneNumber = null;
88 88
     this.phonePin = null;
89 89
     this.connectionTimes = {};
90
+    this.participantPropertyListener = null;
90 91
 }
91 92
 
92 93
 ChatRoom.prototype.initPresenceMap = function () {
@@ -325,8 +326,8 @@ ChatRoom.prototype.onPresence = function (pres) {
325 326
         {
326 327
             case "nick":
327 328
                 if(!member.isFocus) {
328
-                    var displayName = !this.xmpp.options.displayJids
329
-                        ? member.nick : Strophe.getResourceFromJid(from);
329
+                    var displayName = this.xmpp.options.displayJids
330
+                        ? Strophe.getResourceFromJid(from) : member.nick;
330 331
 
331 332
                     if (displayName && displayName.length > 0) {
332 333
                         this.eventEmitter.emit(
@@ -351,7 +352,7 @@ ChatRoom.prototype.onPresence = function (pres) {
351 352
                 this.phonePin = att.pin || null;
352 353
                 this.eventEmitter.emit(XMPPEvents.PHONE_NUMBER_CHANGED);
353 354
                 break;
354
-            default :
355
+            default:
355 356
                 this.processNode(node, from);
356 357
         }
357 358
     }
@@ -369,13 +370,26 @@ ChatRoom.prototype.onPresence = function (pres) {
369 370
     }
370 371
 };
371 372
 
373
+/**
374
+ * Sets the special listener to be used for "command"s whose name starts with
375
+ * "jitsi_participant_".
376
+ */
377
+ChatRoom.prototype.setParticipantPropertyListener = function (listener) {
378
+    this.participantPropertyListener = listener;
379
+};
380
+
372 381
 ChatRoom.prototype.processNode = function (node, from) {
373 382
     // make sure we catch all errors coming from any handler
374 383
     // otherwise we can remove the presence handler from strophe
375 384
     try {
376 385
         var tagHandler = this.presHandlers[node.tagName];
377
-        if(tagHandler)
386
+        if (node.tagName.startsWith("jitsi_participant_")) {
387
+            tagHandler = this.participantPropertyListener;
388
+        }
389
+
390
+        if(tagHandler) {
378 391
             tagHandler(node, Strophe.getResourceFromJid(from), from);
392
+        }
379 393
     } catch (e) {
380 394
         GlobalOnErrorHandler.callErrorHandler(e);
381 395
         logger.error('Error processing:' + node.tagName + ' node.', e);
@@ -560,15 +574,14 @@ ChatRoom.prototype.lockRoom = function (key, onSuccess, onError, onNotSupported)
560 574
 
561 575
 ChatRoom.prototype.addToPresence = function (key, values) {
562 576
     values.tagName = key;
563
-    this.presMap["nodes"].push(values);
577
+    this.removeFromPresence(key);
578
+    this.presMap.nodes.push(values);
564 579
 };
565 580
 
566 581
 ChatRoom.prototype.removeFromPresence = function (key) {
567
-    for(var i = 0; i < this.presMap.nodes.length; i++)
568
-    {
569
-        if(key === this.presMap.nodes[i].tagName)
570
-            this.presMap.nodes.splice(i, 1);
571
-    }
582
+    var nodes = this.presMap.nodes.filter(function(node) {
583
+        return key !== node.tagName;});
584
+    this.presMap.nodes = nodes;
572 585
 };
573 586
 
574 587
 ChatRoom.prototype.addPresenceListener = function (name, handler) {

Загрузка…
Отмена
Сохранить