Explorar el Código

add info about user role to JitsiConference

dev1
isymchych hace 9 años
padre
commit
02a95fd662
Se han modificado 6 ficheros con 116 adiciones y 42 borrados
  1. 31
    0
      JitsiConference.js
  2. 5
    1
      JitsiConferenceEvents.js
  3. 3
    3
      JitsiParticipant.js
  4. 6
    0
      doc/API.md
  5. 67
    32
      lib-jitsi-meet.js
  6. 4
    6
      modules/xmpp/ChatRoom.js

+ 31
- 0
JitsiConference.js Ver fichero

@@ -195,6 +195,22 @@ JitsiConference.prototype.removeTrack = function (track) {
195 195
     this.rtc.removeLocalStream(track);
196 196
 };
197 197
 
198
+/**
199
+ * Get role of the local user.
200
+ * @returns {string} user role: 'moderator' or 'none'
201
+ */
202
+JitsiConference.prototype.getRole = function () {
203
+    return this.room.role;
204
+};
205
+
206
+/**
207
+ * Check if local user is moderator.
208
+ * @returns {boolean} true if local user is moderator, false otherwise.
209
+ */
210
+JitsiConference.prototype.isModerator = function () {
211
+    return this.room.isModerator();
212
+};
213
+
198 214
 /**
199 215
  * Elects the participant with the given id to be the selected participant or the speaker.
200 216
  * @param id the identifier of the participant
@@ -253,6 +269,16 @@ JitsiConference.prototype.onMemberLeft = function (jid) {
253 269
     this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id);
254 270
 };
255 271
 
272
+JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
273
+    var id = Strophe.getResourceFromJid(jid);
274
+    var participant = this.getParticipantById(id);
275
+    if (!participant) {
276
+        return;
277
+    }
278
+    participant._role = role;
279
+    this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
280
+};
281
+
256 282
 JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
257 283
     var id = Strophe.getResourceFromJid(jid);
258 284
     var participant = this.getParticipantById(id);
@@ -362,6 +388,11 @@ function setupListeners(conference) {
362 388
 
363 389
     conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
364 390
 
391
+    conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
392
+        conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
393
+    });
394
+    conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
395
+
365 396
     conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
366 397
         conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
367 398
     });

+ 5
- 1
JitsiConferenceEvents.js Ver fichero

@@ -23,6 +23,10 @@ var JitsiConferenceEvents = {
23 23
      * A user has left the conference.
24 24
      */
25 25
     USER_LEFT: "conference.userLeft",
26
+    /**
27
+     * User role changed.
28
+     */
29
+    USER_ROLE_CHANGED: "conference.roleChanged",
26 30
     /**
27 31
      * New text message was received.
28 32
      */
@@ -79,7 +83,7 @@ var JitsiConferenceEvents = {
79 83
     /**
80 84
      * Indicates that DTMF support changed.
81 85
      */
82
-    DTMF_SUPPORT_CHANGED: "conference.dtmf_support_changed"
86
+    DTMF_SUPPORT_CHANGED: "conference.dtmfSupportChanged"
83 87
 };
84 88
 
85 89
 module.exports = JitsiConferenceEvents;

+ 3
- 3
JitsiParticipant.js Ver fichero

@@ -7,7 +7,7 @@ function JitsiParticipant(id, conference, displayName){
7 7
     this._displayName = displayName;
8 8
     this._supportsDTMF = false;
9 9
     this._tracks = [];
10
-    this._isModerator = false;
10
+    this._role = 'none';
11 11
 }
12 12
 
13 13
 /**
@@ -42,7 +42,7 @@ JitsiParticipant.prototype.getDisplayName = function() {
42 42
  * @returns {Boolean} Whether this participant is a moderator or not.
43 43
  */
44 44
 JitsiParticipant.prototype.isModerator = function() {
45
-    return this._isModerator;
45
+    return this._role === 'moderator';
46 46
 };
47 47
 
48 48
 // Gets a link to an etherpad instance advertised by the participant?
@@ -81,7 +81,7 @@ JitsiParticipant.prototype.getLatestStats = function() {
81 81
  * @returns {String} The role of this participant.
82 82
  */
83 83
 JitsiParticipant.prototype.getRole = function() {
84
-
84
+    return this._role;
85 85
 };
86 86
 
87 87
 /*

+ 6
- 0
doc/API.md Ver fichero

@@ -78,6 +78,7 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
78 78
         - CONFERENCE_JOINED - notifies the local user that he joined the conference successfully. (no parameters)
79 79
         - CONFERENCE_LEFT - notifies the local user that he left the conference successfully. (no parameters)
80 80
         - DTMF_SUPPORT_CHANGED - notifies if at least one user supports DTMF. (parameters - supports(boolean))
81
+        - USER_ROLE_CHANGED - notifies that role of some user changed. (parameters - id(string), role(string))
81 82
 
82 83
     2. connection
83 84
         - CONNECTION_FAILED - indicates that the server connection failed.
@@ -220,6 +221,11 @@ The object represents a conference. We have the following methods to control the
220 221
 
221 222
 19. isDTMFSupported() - Check if at least one user supports DTMF.
222 223
 
224
+20. getRole() - returns string with the local user role ("moderator" or "none")
225
+
226
+21. isModerator() - checks if local user has "moderator" role
227
+
228
+
223 229
 JitsiTrack
224 230
 ======
225 231
 The object represents single track - video or audio. They can be remote tracks ( from the other participants in the call) or local tracks (from the devices of the local participant).

+ 67
- 32
lib-jitsi-meet.js Ver fichero

@@ -197,6 +197,22 @@ JitsiConference.prototype.removeTrack = function (track) {
197 197
     this.rtc.removeLocalStream(track);
198 198
 };
199 199
 
200
+/**
201
+ * Get role of the local user.
202
+ * @returns {string} user role: 'moderator' or 'none'
203
+ */
204
+JitsiConference.prototype.getRole = function () {
205
+    return this.room.role;
206
+};
207
+
208
+/**
209
+ * Check if local user is moderator.
210
+ * @returns {boolean} true if local user is moderator, false otherwise.
211
+ */
212
+JitsiConference.prototype.isModerator = function () {
213
+    return this.room.isModerator();
214
+};
215
+
200 216
 /**
201 217
  * Elects the participant with the given id to be the selected participant or the speaker.
202 218
  * @param id the identifier of the participant
@@ -255,6 +271,16 @@ JitsiConference.prototype.onMemberLeft = function (jid) {
255 271
     this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id);
256 272
 };
257 273
 
274
+JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
275
+    var id = Strophe.getResourceFromJid(jid);
276
+    var participant = this.getParticipantById(id);
277
+    if (!participant) {
278
+        return;
279
+    }
280
+    participant._role = role;
281
+    this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
282
+};
283
+
258 284
 JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
259 285
     var id = Strophe.getResourceFromJid(jid);
260 286
     var participant = this.getParticipantById(id);
@@ -364,6 +390,11 @@ function setupListeners(conference) {
364 390
 
365 391
     conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
366 392
 
393
+    conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
394
+        conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
395
+    });
396
+    conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
397
+
367 398
     conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
368 399
         conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
369 400
     });
@@ -496,6 +527,10 @@ var JitsiConferenceEvents = {
496 527
      * A user has left the conference.
497 528
      */
498 529
     USER_LEFT: "conference.userLeft",
530
+    /**
531
+     * User role changed.
532
+     */
533
+    USER_ROLE_CHANGED: "conference.roleChanged",
499 534
     /**
500 535
      * New text message was received.
501 536
      */
@@ -552,7 +587,7 @@ var JitsiConferenceEvents = {
552 587
     /**
553 588
      * Indicates that DTMF support changed.
554 589
      */
555
-    DTMF_SUPPORT_CHANGED: "conference.dtmf_support_changed"
590
+    DTMF_SUPPORT_CHANGED: "conference.dtmfSupportChanged"
556 591
 };
557 592
 
558 593
 module.exports = JitsiConferenceEvents;
@@ -783,7 +818,7 @@ function JitsiParticipant(id, conference, displayName){
783 818
     this._displayName = displayName;
784 819
     this._supportsDTMF = false;
785 820
     this._tracks = [];
786
-    this._isModerator = false;
821
+    this._role = 'none';
787 822
 }
788 823
 
789 824
 /**
@@ -818,7 +853,7 @@ JitsiParticipant.prototype.getDisplayName = function() {
818 853
  * @returns {Boolean} Whether this participant is a moderator or not.
819 854
  */
820 855
 JitsiParticipant.prototype.isModerator = function() {
821
-    return this._isModerator;
856
+    return this._role === 'moderator';
822 857
 };
823 858
 
824 859
 // Gets a link to an etherpad instance advertised by the participant?
@@ -857,7 +892,7 @@ JitsiParticipant.prototype.getLatestStats = function() {
857 892
  * @returns {String} The role of this participant.
858 893
  */
859 894
 JitsiParticipant.prototype.getRole = function() {
860
-
895
+    return this._role;
861 896
 };
862 897
 
863 898
 /*
@@ -5565,7 +5600,8 @@ module.exports = RandomUtil;
5565 5600
 
5566 5601
 },{}],26:[function(require,module,exports){
5567 5602
 (function (__filename){
5568
-
5603
+/* global Strophe, $, $pres, $iq, $msg */
5604
+/* jshint -W101,-W069 */
5569 5605
 var logger = require("jitsi-meet-logger").getLogger(__filename);
5570 5606
 var XMPPEvents = require("../../service/xmpp/XMPPEvents");
5571 5607
 var Moderator = require("./moderator");
@@ -5576,23 +5612,24 @@ var parser = {
5576 5612
         var self = this;
5577 5613
         $(packet).children().each(function (index) {
5578 5614
             var tagName = $(this).prop("tagName");
5579
-            var node = {}
5580
-            node["tagName"] = tagName;
5615
+            var node = {
5616
+                tagName: tagName
5617
+            };
5581 5618
             node.attributes = {};
5582 5619
             $($(this)[0].attributes).each(function( index, attr ) {
5583 5620
                 node.attributes[ attr.name ] = attr.value;
5584
-            } );
5621
+            });
5585 5622
             var text = Strophe.getText($(this)[0]);
5586
-            if(text)
5623
+            if (text) {
5587 5624
                 node.value = text;
5625
+            }
5588 5626
             node.children = [];
5589 5627
             nodes.push(node);
5590 5628
             self.packet2JSON($(this), node.children);
5591
-        })
5629
+        });
5592 5630
     },
5593 5631
     JSON2packet: function (nodes, packet) {
5594
-        for(var i = 0; i < nodes.length; i++)
5595
-        {
5632
+        for(var i = 0; i < nodes.length; i++) {
5596 5633
             var node = nodes[i];
5597 5634
             if(!node || node === null){
5598 5635
                 continue;
@@ -5634,7 +5671,7 @@ function ChatRoom(connection, jid, password, XMPP, options) {
5634 5671
     this.presMap = {};
5635 5672
     this.presHandlers = {};
5636 5673
     this.joined = false;
5637
-    this.role = null;
5674
+    this.role = 'none';
5638 5675
     this.focusMucJid = null;
5639 5676
     this.bridgeIsDown = false;
5640 5677
     this.options = options || {};
@@ -5671,7 +5708,7 @@ ChatRoom.prototype.updateDeviceAvailability = function (devices) {
5671 5708
             }
5672 5709
         ]
5673 5710
     });
5674
-}
5711
+};
5675 5712
 
5676 5713
 ChatRoom.prototype.join = function (password, tokenPassword) {
5677 5714
     if(password)
@@ -5773,7 +5810,7 @@ ChatRoom.prototype.onPresence = function (pres) {
5773 5810
     member.jid = tmp.attr('jid');
5774 5811
     member.isFocus = false;
5775 5812
     if (member.jid
5776
-        && member.jid.indexOf(this.moderator.getFocusUserJid() + "/") == 0) {
5813
+        && member.jid.indexOf(this.moderator.getFocusUserJid() + "/") === 0) {
5777 5814
         member.isFocus = true;
5778 5815
     }
5779 5816
 
@@ -5822,8 +5859,7 @@ ChatRoom.prototype.onPresence = function (pres) {
5822 5859
             if (this.role !== member.role) {
5823 5860
                 this.role = member.role;
5824 5861
 
5825
-                this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED,
5826
-                    member, this.isModerator());
5862
+                this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED, this.role);
5827 5863
             }
5828 5864
         if (!this.joined) {
5829 5865
             this.joined = true;
@@ -5846,8 +5882,7 @@ ChatRoom.prototype.onPresence = function (pres) {
5846 5882
         // Watch role change:
5847 5883
         if (this.members[from].role != member.role) {
5848 5884
             this.members[from].role = member.role;
5849
-            this.eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED,
5850
-                member.role, member.nick);
5885
+            this.eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED, from, member.role);
5851 5886
         }
5852 5887
 
5853 5888
         // store the new display name
@@ -5912,7 +5947,7 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
5912 5947
 
5913 5948
         this.xmpp.disposeConference(false);
5914 5949
         this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
5915
-        delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(jid)];
5950
+        delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
5916 5951
         return true;
5917 5952
     }
5918 5953
 
@@ -5955,7 +5990,7 @@ ChatRoom.prototype.onMessage = function (msg, from) {
5955 5990
     var subject = $(msg).find('>subject');
5956 5991
     if (subject.length) {
5957 5992
         var subjectText = subject.text();
5958
-        if (subjectText || subjectText == "") {
5993
+        if (subjectText || subjectText === "") {
5959 5994
             this.eventEmitter.emit(XMPPEvents.SUBJECT_CHANGED, subjectText);
5960 5995
             logger.log("Subject is changed to " + subjectText);
5961 5996
         }
@@ -5980,7 +6015,7 @@ ChatRoom.prototype.onMessage = function (msg, from) {
5980 6015
         this.eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
5981 6016
             from, nick, txt, this.myroomjid, stamp);
5982 6017
     }
5983
-}
6018
+};
5984 6019
 
5985 6020
 ChatRoom.prototype.onPresenceError = function (pres, from) {
5986 6021
     if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
@@ -6059,13 +6094,13 @@ ChatRoom.prototype.removeFromPresence = function (key) {
6059 6094
 
6060 6095
 ChatRoom.prototype.addPresenceListener = function (name, handler) {
6061 6096
     this.presHandlers[name] = handler;
6062
-}
6097
+};
6063 6098
 
6064 6099
 ChatRoom.prototype.removePresenceListener = function (name) {
6065 6100
     delete this.presHandlers[name];
6066
-}
6101
+};
6067 6102
 
6068
-ChatRoom.prototype.isModerator = function (jid) {
6103
+ChatRoom.prototype.isModerator = function () {
6069 6104
     return this.role === 'moderator';
6070 6105
 };
6071 6106
 
@@ -6085,8 +6120,8 @@ ChatRoom.prototype.setJingleSession = function(session){
6085 6120
 ChatRoom.prototype.removeStream = function (stream) {
6086 6121
     if(!this.session)
6087 6122
         return;
6088
-    this.session.peerconnection.removeStream(stream)
6089
-}
6123
+    this.session.peerconnection.removeStream(stream);
6124
+};
6090 6125
 
6091 6126
 ChatRoom.prototype.switchStreams = function (stream, oldStream, callback, isAudio) {
6092 6127
     if(this.session) {
@@ -6108,14 +6143,14 @@ ChatRoom.prototype.addStream = function (stream, callback) {
6108 6143
         logger.warn("No conference handler or conference not started yet");
6109 6144
         callback();
6110 6145
     }
6111
-}
6146
+};
6112 6147
 
6113 6148
 ChatRoom.prototype.setVideoMute = function (mute, callback, options) {
6114 6149
     var self = this;
6115 6150
     var localCallback = function (mute) {
6116 6151
         self.sendVideoInfoPresence(mute);
6117 6152
         if(callback)
6118
-            callback(mute)
6153
+            callback(mute);
6119 6154
     };
6120 6155
 
6121 6156
     if(this.session)
@@ -6148,7 +6183,7 @@ ChatRoom.prototype.addAudioInfoToPresence = function (mute) {
6148 6183
         {attributes:
6149 6184
         {"audions": "http://jitsi.org/jitmeet/audio"},
6150 6185
             value: mute.toString()});
6151
-}
6186
+};
6152 6187
 
6153 6188
 ChatRoom.prototype.sendAudioInfoPresence = function(mute, callback) {
6154 6189
     this.addAudioInfoToPresence(mute);
@@ -6165,7 +6200,7 @@ ChatRoom.prototype.addVideoInfoToPresence = function (mute) {
6165 6200
         {attributes:
6166 6201
         {"videons": "http://jitsi.org/jitmeet/video"},
6167 6202
             value: mute.toString()});
6168
-}
6203
+};
6169 6204
 
6170 6205
 
6171 6206
 ChatRoom.prototype.sendVideoInfoPresence = function (mute) {
@@ -6198,7 +6233,7 @@ ChatRoom.prototype.remoteStreamAdded = function(data, sid, thessrc) {
6198 6233
     }
6199 6234
 
6200 6235
     this.eventEmitter.emit(XMPPEvents.REMOTE_STREAM_RECEIVED, data, sid, thessrc);
6201
-}
6236
+};
6202 6237
 
6203 6238
 ChatRoom.prototype.getJidBySSRC = function (ssrc) {
6204 6239
     if (!this.session)

+ 4
- 6
modules/xmpp/ChatRoom.js Ver fichero

@@ -69,7 +69,7 @@ function ChatRoom(connection, jid, password, XMPP, options) {
69 69
     this.presMap = {};
70 70
     this.presHandlers = {};
71 71
     this.joined = false;
72
-    this.role = null;
72
+    this.role = 'none';
73 73
     this.focusMucJid = null;
74 74
     this.bridgeIsDown = false;
75 75
     this.options = options || {};
@@ -257,8 +257,7 @@ ChatRoom.prototype.onPresence = function (pres) {
257 257
             if (this.role !== member.role) {
258 258
                 this.role = member.role;
259 259
 
260
-                this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED,
261
-                    member, this.isModerator());
260
+                this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED, this.role);
262 261
             }
263 262
         if (!this.joined) {
264 263
             this.joined = true;
@@ -281,8 +280,7 @@ ChatRoom.prototype.onPresence = function (pres) {
281 280
         // Watch role change:
282 281
         if (this.members[from].role != member.role) {
283 282
             this.members[from].role = member.role;
284
-            this.eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED,
285
-                member.role, member.nick);
283
+            this.eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED, from, member.role);
286 284
         }
287 285
 
288 286
         // store the new display name
@@ -500,7 +498,7 @@ ChatRoom.prototype.removePresenceListener = function (name) {
500 498
     delete this.presHandlers[name];
501 499
 };
502 500
 
503
-ChatRoom.prototype.isModerator = function (jid) {
501
+ChatRoom.prototype.isModerator = function () {
504 502
     return this.role === 'moderator';
505 503
 };
506 504
 

Loading…
Cancelar
Guardar