Browse Source

added helper methods to check if auth enabled

master
isymchych 10 years ago
parent
commit
26f102a470
3 changed files with 182 additions and 116 deletions
  1. 140
    106
      JitsiConference.js
  2. 38
    6
      lib-jitsi-meet.js
  3. 4
    4
      modules/xmpp/xmpp.js

+ 140
- 106
JitsiConference.js View File

@@ -1,11 +1,13 @@
1
-/* global Strophe, $ */
1
+/* global Strophe, $, Promise */
2 2
 /* jshint -W101 */
3 3
 var logger = require("jitsi-meet-logger").getLogger(__filename);
4 4
 var RTC = require("./modules/RTC/RTC");
5 5
 var XMPPEvents = require("./service/xmpp/XMPPEvents");
6
+var AuthenticationEvents = require("./service/authentication/AuthenticationEvents");
6 7
 var RTCEvents = require("./service/RTC/RTCEvents");
7 8
 var EventEmitter = require("events");
8 9
 var JitsiConferenceEvents = require("./JitsiConferenceEvents");
10
+var JitsiConferenceErrors = require("./JitsiConferenceErrors");
9 11
 var JitsiParticipant = require("./JitsiParticipant");
10 12
 var Statistics = require("./modules/statistics/statistics");
11 13
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
@@ -30,7 +32,7 @@ function JitsiConference(options) {
30 32
     this.connection = this.options.connection;
31 33
     this.xmpp = this.connection.xmpp;
32 34
     this.eventEmitter = new EventEmitter();
33
-    this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config);
35
+    this.room = this.xmpp.createRoom(this.options.name, this.options.config);
34 36
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
35 37
     this.rtc = new RTC(this.room, options);
36 38
     if(!RTC.options.disableAudioLevels)
@@ -40,6 +42,8 @@ function JitsiConference(options) {
40 42
     this.lastActiveSpeaker = null;
41 43
     this.dtmfManager = null;
42 44
     this.somebodySupportsDTMF = false;
45
+    this.authEnabled = false;
46
+    this.authIdentity;
43 47
 }
44 48
 
45 49
 /**
@@ -51,6 +55,13 @@ JitsiConference.prototype.join = function (password) {
51 55
         this.room.join(password, this.connection.tokenPassword);
52 56
 };
53 57
 
58
+/**
59
+ * Check if joined to the conference.
60
+ */
61
+JitsiConference.prototype.isJoined = function () {
62
+    return this.room && this.room.joined;
63
+};
64
+
54 65
 /**
55 66
  * Leaves the conference.
56 67
  */
@@ -60,6 +71,61 @@ JitsiConference.prototype.leave = function () {
60 71
     this.room = null;
61 72
 };
62 73
 
74
+/**
75
+ * Returns name of this conference.
76
+ */
77
+JitsiConference.prototype.getName = function () {
78
+    return this.options.name;
79
+};
80
+
81
+/**
82
+ * Check if authentication is enabled for this conference.
83
+ */
84
+JitsiConference.prototype.isAuthEnabled = function () {
85
+    return this.authEnabled;
86
+};
87
+
88
+/**
89
+ * Check if user is logged in.
90
+ */
91
+JitsiConference.prototype.isLoggedIn = function () {
92
+    return !!this.authIdentity;
93
+};
94
+
95
+/**
96
+ * Get authorized login.
97
+ */
98
+JitsiConference.prototype.getAuthLogin = function () {
99
+    return this.authIdentity;
100
+};
101
+
102
+/**
103
+ * Check if external authentication is enabled for this conference.
104
+ */
105
+JitsiConference.prototype.isExternalAuthEnabled = function () {
106
+    return this.room && this.room.moderator.isExternalAuthEnabled();
107
+};
108
+
109
+/**
110
+ * Get url for external authentication.
111
+ * @param {boolean} [urlForPopup] if true then return url for login popup,
112
+ *                                else url of login page.
113
+ * @returns {Promise}
114
+ */
115
+JitsiConference.prototype.getExternalAuthUrl = function (urlForPopup) {
116
+    return new Promise(function (resolve, reject) {
117
+        if (!this.isExternalAuthEnabled()) {
118
+            reject();
119
+            return;
120
+        }
121
+        if (urlForPopup) {
122
+            this.room.moderator.getPopupLoginUrl(resolve, reject);
123
+        } else {
124
+            this.room.moderator.getLoginUrl(resolve, reject);
125
+        }
126
+    }.bind(this));
127
+};
128
+
63 129
 /**
64 130
  * Returns the local tracks.
65 131
  */
@@ -225,6 +291,11 @@ JitsiConference.prototype._fireMuteChangeEvent = function (track) {
225 291
  * @param track the JitsiLocalTrack object.
226 292
  */
227 293
 JitsiConference.prototype.removeTrack = function (track) {
294
+    if(!this.room){
295
+        if(this.rtc)
296
+            this.rtc.removeLocalStream(track);
297
+        return;
298
+    }
228 299
     this.room.removeStream(track.getOriginalStream(), function(){
229 300
         this.rtc.removeLocalStream(track);
230 301
         this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
@@ -247,6 +318,36 @@ JitsiConference.prototype.isModerator = function () {
247 318
     return this.room.isModerator();
248 319
 };
249 320
 
321
+/**
322
+ * Set password for the room.
323
+ * @param {string} password new password for the room.
324
+ * @returns {Promise}
325
+ */
326
+JitsiConference.prototype.lock = function (password) {
327
+  if (!this.isModerator()) {
328
+    return Promise.reject();
329
+  }
330
+
331
+  var conference = this;
332
+  return new Promise(function (resolve, reject) {
333
+    conference.xmpp.lockRoom(password, function () {
334
+      resolve();
335
+    }, function (err) {
336
+      reject(err);
337
+    }, function () {
338
+      reject(JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED);
339
+    });
340
+  });
341
+};
342
+
343
+/**
344
+ * Remove password from the room.
345
+ * @returns {Promise}
346
+ */
347
+JitsiConference.prototype.unlock = function () {
348
+  return this.lock(undefined);
349
+};
350
+
250 351
 /**
251 352
  * Elects the participant with the given id to be the selected participant or the speaker.
252 353
  * @param id the identifier of the participant
@@ -288,10 +389,13 @@ JitsiConference.prototype.getParticipantById = function(id) {
288 389
 
289 390
 JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
290 391
     var id = Strophe.getResourceFromJid(jid);
392
+    if (id === 'focus') {
393
+       return;
394
+    }
291 395
     var participant = new JitsiParticipant(id, this, nick);
292
-    this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id);
293 396
     this.participants[id] = participant;
294
-    this.connection.xmpp.connection.disco.info(
397
+    this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
398
+    this.xmpp.connection.disco.info(
295 399
         jid, "node", function(iq) {
296 400
             participant._supportsDTMF = $(iq).find(
297 401
                 '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
@@ -302,8 +406,12 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
302 406
 
303 407
 JitsiConference.prototype.onMemberLeft = function (jid) {
304 408
     var id = Strophe.getResourceFromJid(jid);
409
+    if (id === 'focus') {
410
+       return;
411
+    }
412
+    var participant = this.participants[id];
305 413
     delete this.participants[id];
306
-    this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id);
414
+    this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
307 415
 };
308 416
 
309 417
 JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
@@ -399,7 +507,7 @@ JitsiConference.prototype.myUserId = function () {
399 507
 
400 508
 JitsiConference.prototype.sendTones = function (tones, duration, pause) {
401 509
     if (!this.dtmfManager) {
402
-        var connection = this.connection.xmpp.connection.jingle.activecall.peerconnection;
510
+        var connection = this.xmpp.connection.jingle.activecall.peerconnection;
403 511
         if (!connection) {
404 512
             logger.warn("cannot sendTones: no conneciton");
405 513
             return;
@@ -418,94 +526,6 @@ JitsiConference.prototype.sendTones = function (tones, duration, pause) {
418 526
     this.dtmfManager.sendTones(tones, duration, pause);
419 527
 };
420 528
 
421
-/**
422
- * Returns true if the recording is supproted and false if not.
423
- */
424
-JitsiConference.prototype.isRecordingSupported = function () {
425
-    if(this.room)
426
-        return this.room.isRecordingSupported();
427
-    return false;
428
-};
429
-
430
-/**
431
- * Returns null if the recording is not supported, "on" if the recording started
432
- * and "off" if the recording is not started.
433
- */
434
-JitsiConference.prototype.getRecordingState = function () {
435
-    if(this.room)
436
-        return this.room.getRecordingState();
437
-    return "off";
438
-}
439
-
440
-/**
441
- * Returns the url of the recorded video.
442
- */
443
-JitsiConference.prototype.getRecordingURL = function () {
444
-    if(this.room)
445
-        return this.room.getRecordingURL();
446
-    return null;
447
-}
448
-
449
-/**
450
- * Starts/stops the recording
451
- * @param token a token for authentication.
452
- */
453
-JitsiConference.prototype.toggleRecording = function (token, followEntity) {
454
-    if(this.room)
455
-        return this.room.toggleRecording(token, followEntity);
456
-    return new Promise(function(resolve, reject){
457
-        reject(new Error("The conference is not created yet!"))});
458
-}
459
-
460
-/**
461
- * Dials a number.
462
- * @param number the number
463
- */
464
-JitsiConference.prototype.dial = function (number) {
465
-    if(this.room)
466
-        return this.room.dial(number);
467
-    return new Promise(function(resolve, reject){
468
-        reject(new Error("The conference is not created yet!"))});
469
-}
470
-
471
-/**
472
- * Hangup an existing call
473
- */
474
-JitsiConference.prototype.hangup = function () {
475
-    if(this.room)
476
-        return this.room.hangup();
477
-    return new Promise(function(resolve, reject){
478
-        reject(new Error("The conference is not created yet!"))});
479
-}
480
-
481
-/**
482
- * Returns the phone number for joining the conference.
483
- */
484
-JitsiConference.prototype.getPhoneNumber = function () {
485
-    if(this.room)
486
-        return this.room.getPhoneNumber();
487
-    return null;
488
-}
489
-
490
-/**
491
- * Returns the pin for joining the conference with phone.
492
- */
493
-JitsiConference.prototype.getPhonePin = function () {
494
-    if(this.room)
495
-        return this.room.getPhonePin();
496
-    return null;
497
-}
498
-
499
-/**
500
- * Returns the connection state for the current room. Its ice connection state
501
- * for its session.
502
- */
503
-JitsiConference.prototype.getConnectionState = function () {
504
-    if(this.room)
505
-        return this.room.getConnectionState();
506
-    return null;
507
-}
508
-
509 529
 /**
510 530
  * Setups the listeners needed for the conference.
511 531
  * @param conference the conference
@@ -529,6 +549,18 @@ function setupListeners(conference) {
529 549
     conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
530 550
         conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
531 551
     });
552
+    conference.room.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) {
553
+        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONNECTION_ERROR, pres);
554
+    });
555
+    conference.room.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
556
+        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONNECTION_ERROR, pres);
557
+    });
558
+    conference.room.addListener(XMPPEvents.PASSWORD_REQUIRED, function (pres) {
559
+        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.PASSWORD_REQUIRED, pres);
560
+    });
561
+    conference.room.addListener(XMPPEvents.AUTHENTICATION_REQUIRED, function () {
562
+        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
563
+    });
532 564
 //    FIXME
533 565
 //    conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
534 566
 //        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
@@ -548,22 +580,21 @@ function setupListeners(conference) {
548 580
         conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
549 581
     });
550 582
 
551
-    conference.room.addListener(XMPPEvents.RECORDING_STATE_CHANGED,
552
-        function () {
553
-            conference.eventEmitter.emit(
554
-                JitsiConferenceEvents.RECORDING_STATE_CHANGED);
555
-        });
556
-
557
-    conference.room.addListener(XMPPEvents.PHONE_NUMBER_CHANGED, function () {
558
-        conference.eventEmitter.emit(
559
-            JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
560
-    });
561
-
562 583
     conference.room.addListener(XMPPEvents.CONNECTION_RESTORED, function () {
563 584
         conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_RESTORED);
564 585
     });
565 586
     conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
566
-        conference.eventEmitter.emit(JitsiConferenceEvents.SETUP_FAILED);
587
+        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.SETUP_FAILED);
588
+    });
589
+
590
+    conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
591
+        conference.authEnabled = authEnabled;
592
+        conference.authIdentity = authIdentity;
593
+    });
594
+
595
+    conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
596
+        var id = Strophe.getResourceFromJid(jid);
597
+        conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
567 598
     });
568 599
 
569 600
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
@@ -582,6 +613,9 @@ function setupListeners(conference) {
582 613
             conference.eventEmitter.emit(JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
583 614
                 lastNEndpoints, endpointsEnteringLastN);
584 615
         });
616
+    conference.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, function () {
617
+        conference.eventEmitter.emit(JitsiConferenceErrors.PASSWORD_REQUIRED);
618
+    });
585 619
 
586 620
     if(conference.statistics) {
587 621
         //FIXME: Maybe remove event should not be associated with the conference.

+ 38
- 6
lib-jitsi-meet.js View File

@@ -5,6 +5,7 @@
5 5
 var logger = require("jitsi-meet-logger").getLogger(__filename);
6 6
 var RTC = require("./modules/RTC/RTC");
7 7
 var XMPPEvents = require("./service/xmpp/XMPPEvents");
8
+var AuthenticationEvents = require("./service/authentication/AuthenticationEvents");
8 9
 var RTCEvents = require("./service/RTC/RTCEvents");
9 10
 var EventEmitter = require("events");
10 11
 var JitsiConferenceEvents = require("./JitsiConferenceEvents");
@@ -33,7 +34,7 @@ function JitsiConference(options) {
33 34
     this.connection = this.options.connection;
34 35
     this.xmpp = this.connection.xmpp;
35 36
     this.eventEmitter = new EventEmitter();
36
-    this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config);
37
+    this.room = this.xmpp.createRoom(this.options.name, this.options.config);
37 38
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
38 39
     this.rtc = new RTC(this.room, options);
39 40
     if(!RTC.options.disableAudioLevels)
@@ -43,6 +44,8 @@ function JitsiConference(options) {
43 44
     this.lastActiveSpeaker = null;
44 45
     this.dtmfManager = null;
45 46
     this.somebodySupportsDTMF = false;
47
+    this.authEnabled = false;
48
+    this.authIdentity;
46 49
 }
47 50
 
48 51
 /**
@@ -77,6 +80,27 @@ JitsiConference.prototype.getName = function () {
77 80
     return this.options.name;
78 81
 };
79 82
 
83
+/**
84
+ * Check if authentication is enabled for this conference.
85
+ */
86
+JitsiConference.prototype.isAuthEnabled = function () {
87
+    return this.authEnabled;
88
+};
89
+
90
+/**
91
+ * Check if user is logged in.
92
+ */
93
+JitsiConference.prototype.isLoggedIn = function () {
94
+    return !!this.authIdentity;
95
+};
96
+
97
+/**
98
+ * Get authorized login.
99
+ */
100
+JitsiConference.prototype.getAuthLogin = function () {
101
+    return this.authIdentity;
102
+};
103
+
80 104
 /**
81 105
  * Check if external authentication is enabled for this conference.
82 106
  */
@@ -384,6 +408,9 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
384 408
 
385 409
 JitsiConference.prototype.onMemberLeft = function (jid) {
386 410
     var id = Strophe.getResourceFromJid(jid);
411
+    if (id === 'focus') {
412
+       return;
413
+    }
387 414
     var participant = this.participants[id];
388 415
     delete this.participants[id];
389 416
     this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
@@ -562,6 +589,11 @@ function setupListeners(conference) {
562 589
         conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.SETUP_FAILED);
563 590
     });
564 591
 
592
+    conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
593
+        conference.authEnabled = authEnabled;
594
+        conference.authIdentity = authIdentity;
595
+    });
596
+
565 597
     conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
566 598
         var id = Strophe.getResourceFromJid(jid);
567 599
         conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
@@ -612,7 +644,7 @@ function setupListeners(conference) {
612 644
 module.exports = JitsiConference;
613 645
 
614 646
 }).call(this,"/JitsiConference.js")
615
-},{"./JitsiConferenceErrors":2,"./JitsiConferenceEvents":3,"./JitsiParticipant":8,"./JitsiTrackEvents":10,"./modules/DTMF/JitsiDTMFManager":11,"./modules/RTC/RTC":16,"./modules/statistics/statistics":24,"./service/RTC/RTCEvents":79,"./service/xmpp/XMPPEvents":85,"events":43,"jitsi-meet-logger":47}],2:[function(require,module,exports){
647
+},{"./JitsiConferenceErrors":2,"./JitsiConferenceEvents":3,"./JitsiParticipant":8,"./JitsiTrackEvents":10,"./modules/DTMF/JitsiDTMFManager":11,"./modules/RTC/RTC":16,"./modules/statistics/statistics":24,"./service/RTC/RTCEvents":79,"./service/authentication/AuthenticationEvents":81,"./service/xmpp/XMPPEvents":85,"events":43,"jitsi-meet-logger":47}],2:[function(require,module,exports){
616 648
 /**
617 649
  * Enumeration with the errors for the conference.
618 650
  * @type {{string: string}}
@@ -11517,12 +11549,12 @@ XMPP.prototype.connect = function (jid, password) {
11517 11549
     return this._connect(jid, password);
11518 11550
 };
11519 11551
 
11520
-XMPP.prototype.createRoom = function (roomName, options, useNicks, nick) {
11552
+XMPP.prototype.createRoom = function (roomName, options) {
11521 11553
     var roomjid = roomName  + '@' + this.options.hosts.muc;
11522 11554
 
11523
-    if (useNicks) {
11524
-        if (nick) {
11525
-            roomjid += '/' + nick;
11555
+    if (options.useNicks) {
11556
+        if (options.nick) {
11557
+            roomjid += '/' + options.nick;
11526 11558
         } else {
11527 11559
             roomjid += '/' + Strophe.getNodeFromJid(this.connection.jid);
11528 11560
         }

+ 4
- 4
modules/xmpp/xmpp.js View File

@@ -180,12 +180,12 @@ XMPP.prototype.connect = function (jid, password) {
180 180
     return this._connect(jid, password);
181 181
 };
182 182
 
183
-XMPP.prototype.createRoom = function (roomName, options, useNicks, nick) {
183
+XMPP.prototype.createRoom = function (roomName, options) {
184 184
     var roomjid = roomName  + '@' + this.options.hosts.muc;
185 185
 
186
-    if (useNicks) {
187
-        if (nick) {
188
-            roomjid += '/' + nick;
186
+    if (options.useNicks) {
187
+        if (options.nick) {
188
+            roomjid += '/' + options.nick;
189 189
         } else {
190 190
             roomjid += '/' + Strophe.getNodeFromJid(this.connection.jid);
191 191
         }

Loading…
Cancel
Save