浏览代码

Adds a set of properties to JitsiParticipant, which can be updated

via presence (via special items with a tag name beginning with
"jitsi_participant_). An events is fired when the value of a property changes.
dev1
Boris Grozev 8 年前
父节点
当前提交
985f79da37
共有 4 个文件被更改,包括 67 次插入2 次删除
  1. 17
    0
      JitsiConference.js
  2. 6
    1
      JitsiConferenceEvents.js
  3. 29
    0
      JitsiParticipant.js
  4. 15
    1
      modules/xmpp/ChatRoom.js

+ 17
- 0
JitsiConference.js 查看文件

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

+ 15
- 1
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 () {
@@ -370,13 +371,26 @@ ChatRoom.prototype.onPresence = function (pres) {
370 371
     }
371 372
 };
372 373
 
374
+/**
375
+ * Sets the special listener to be used for "command"s whose name starts with
376
+ * "jitsi_participant_".
377
+ */
378
+ChatRoom.prototype.setParticipantPropertyListener = function (listener) {
379
+    this.participantPropertyListener = listener;
380
+};
381
+
373 382
 ChatRoom.prototype.processNode = function (node, from) {
374 383
     // make sure we catch all errors coming from any handler
375 384
     // otherwise we can remove the presence handler from strophe
376 385
     try {
377 386
         var tagHandler = this.presHandlers[node.tagName];
378
-        if(tagHandler)
387
+        if (node.tagName.startsWith("jitsi_participant_")) {
388
+            tagHandler = this.participantPropertyListener;
389
+        }
390
+
391
+        if(tagHandler) {
379 392
             tagHandler(node, Strophe.getResourceFromJid(from), from);
393
+        }
380 394
     } catch (e) {
381 395
         GlobalOnErrorHandler.callErrorHandler(e);
382 396
         logger.error('Error processing:' + node.tagName + ' node.', e);

正在加载...
取消
保存