Преглед изворни кода

better error handling while establishing connection

master
isymchych пре 9 година
родитељ
комит
3a00837107

+ 4
- 2
app.js Прегледај датотеку

@@ -17,8 +17,6 @@ import URLProcessor from "./modules/config/URLProcessor";
17 17
 import RoomnameGenerator from './modules/util/RoomnameGenerator';
18 18
 import CQEvents from './service/connectionquality/CQEvents';
19 19
 import UIEvents from './service/UI/UIEvents';
20
-import LoginDialog from './modules/UI/authentication/LoginDialog';
21
-import UIUtil from './modules/UI/util/UIUtil';
22 20
 
23 21
 import {openConnection} from './modules/connection';
24 22
 import AuthHandler from './modules/AuthHandler';
@@ -149,6 +147,8 @@ function initConference(localTracks, connection) {
149 147
             room.addTrack(track);
150 148
             APP.UI.addLocalStream(track);
151 149
         });
150
+
151
+        APP.UI.updateAuthInfo(room.isAuthEnabled(), room.getAuthLogin());
152 152
     });
153 153
 
154 154
 
@@ -534,6 +534,8 @@ function init() {
534 534
         APP.statistics.start();
535 535
         APP.connectionquality.init();
536 536
         APP.keyboardshortcut.init();
537
+    }).catch(function (err) {
538
+        console.error(err);
537 539
     });
538 540
 }
539 541
 

+ 33
- 6
lib-jitsi-meet.js Прегледај датотеку

@@ -34,7 +34,7 @@ function JitsiConference(options) {
34 34
     this.connection = this.options.connection;
35 35
     this.xmpp = this.connection.xmpp;
36 36
     this.eventEmitter = new EventEmitter();
37
-    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);
38 38
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
39 39
     this.rtc = new RTC(this.room, options);
40 40
     if(!RTC.options.disableAudioLevels)
@@ -44,6 +44,8 @@ function JitsiConference(options) {
44 44
     this.lastActiveSpeaker = null;
45 45
     this.dtmfManager = null;
46 46
     this.somebodySupportsDTMF = false;
47
+    this.authEnabled = false;
48
+    this.authIdentity;
47 49
 }
48 50
 
49 51
 /**
@@ -78,6 +80,27 @@ JitsiConference.prototype.getName = function () {
78 80
     return this.options.name;
79 81
 };
80 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
+
81 104
 /**
82 105
  * Check if external authentication is enabled for this conference.
83 106
  */
@@ -385,6 +408,9 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
385 408
 
386 409
 JitsiConference.prototype.onMemberLeft = function (jid) {
387 410
     var id = Strophe.getResourceFromJid(jid);
411
+    if (id === 'focus') {
412
+       return;
413
+    }
388 414
     var participant = this.participants[id];
389 415
     delete this.participants[id];
390 416
     this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
@@ -564,7 +590,8 @@ function setupListeners(conference) {
564 590
     });
565 591
 
566 592
     conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
567
-        console.error(authEnabled, authIdentity);
593
+        conference.authEnabled = authEnabled;
594
+        conference.authIdentity = authIdentity;
568 595
     });
569 596
 
570 597
     conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
@@ -11522,12 +11549,12 @@ XMPP.prototype.connect = function (jid, password) {
11522 11549
     return this._connect(jid, password);
11523 11550
 };
11524 11551
 
11525
-XMPP.prototype.createRoom = function (roomName, options, useNicks, nick) {
11552
+XMPP.prototype.createRoom = function (roomName, options) {
11526 11553
     var roomjid = roomName  + '@' + this.options.hosts.muc;
11527 11554
 
11528
-    if (useNicks) {
11529
-        if (nick) {
11530
-            roomjid += '/' + nick;
11555
+    if (options.useNicks) {
11556
+        if (options.nick) {
11557
+            roomjid += '/' + options.nick;
11531 11558
         } else {
11532 11559
             roomjid += '/' + Strophe.getNodeFromJid(this.connection.jid);
11533 11560
         }

+ 11
- 4
modules/UI/UI.js Прегледај датотеку

@@ -612,10 +612,6 @@ UI.updateRemoteStats = function (jid, percent, stats) {
612 612
     VideoLayout.updateConnectionStats(jid, percent, stats);
613 613
 };
614 614
 
615
-UI.showAuthenticateButton = function (show) {
616
-    Toolbar.showAuthenticateButton(show);
617
-};
618
-
619 615
 UI.markVideoInterrupted = function (interrupted) {
620 616
     if (interrupted) {
621 617
         VideoLayout.onVideoInterrupted();
@@ -740,4 +736,15 @@ UI.notifyTokenAuthFailed = function () {
740 736
     messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
741 737
 };
742 738
 
739
+UI.updateAuthInfo = function (isAuthEnabled, login) {
740
+    let loggedIn = !!login;
741
+
742
+    if (isAuthEnabled) {
743
+        Toolbar.setAuthenticatedIdentity(login);
744
+
745
+        Toolbar.showLoginButton(!loggedIn);
746
+        Toolbar.showLogoutButton(loggedIn);
747
+    }
748
+};
749
+
743 750
 module.exports = UI;

+ 43
- 18
modules/UI/authentication/LoginDialog.js Прегледај датотеку

@@ -13,22 +13,53 @@ function getPasswordInputHtml() {
13 13
         <h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
14 14
         <input name="username" type="text" placeholder=${placeholder} autofocus>
15 15
         <input name="password" type="password"
16
-               data-i18n="[placeholder]dialog.userPassword"
17
-               placeholder="user password">
18
-    `;
16
+    data-i18n="[placeholder]dialog.userPassword"
17
+    placeholder="user password">
18
+        `;
19
+}
20
+
21
+function toJid(id) {
22
+    if (id.indexOf("@") >= 0) {
23
+        return id;
24
+    }
25
+
26
+    let jid = id.concat('@');
27
+    if (config.hosts.authdomain) {
28
+        jid += config.hosts.authdomain;
29
+    } else {
30
+        jid += config.hosts.domain;
31
+    }
32
+
33
+    return jid;
34
+}
35
+
36
+function cancelButton() {
37
+    return {
38
+        title: APP.translation.generateTranslationHTML("dialog.Cancel"),
39
+        value: false
40
+    };
19 41
 }
20 42
 
21 43
 function Dialog(successCallback, cancelCallback) {
44
+    let loginButtons = [{
45
+        title: APP.translation.generateTranslationHTML("dialog.Ok"),
46
+        value: true
47
+    }];
48
+    let finishedButtons = [{
49
+        title: APP.translation.translateString('dialog.retry'),
50
+        value: 'retry'
51
+    }];
52
+
53
+    // show "cancel" button only if cancelCallback provided
54
+    if (cancelCallback) {
55
+        loginButtons.push(cancelButton());
56
+        finishedButtons.push(cancelButton());
57
+    }
58
+
22 59
     const states = {
23 60
         login: {
24 61
             html: getPasswordInputHtml(),
25
-            buttons: [{
26
-                title: APP.translation.generateTranslationHTML("dialog.Ok"),
27
-                value: true
28
-            }, {
29
-                title: APP.translation.generateTranslationHTML("dialog.Cancel"),
30
-                value: false
31
-            }],
62
+            buttons: loginButtons,
32 63
             focus: ':input:first',
33 64
             submit: function (e, v, m, f) {
34 65
                 e.preventDefault();
@@ -37,7 +68,7 @@ function Dialog(successCallback, cancelCallback) {
37 68
                     let password = f.password;
38 69
                     if (jid && password) {
39 70
                         connDialog.goToState('connecting');
40
-                        successCallback(jid, password);
71
+                        successCallback(toJid(jid), password);
41 72
                     }
42 73
                 } else {
43 74
                     // User cancelled
@@ -54,13 +85,7 @@ function Dialog(successCallback, cancelCallback) {
54 85
         finished: {
55 86
             title: APP.translation.translateString('dialog.error'),
56 87
             html:   '<div id="errorMessage"></div>',
57
-            buttons: [{
58
-                title: APP.translation.translateString('dialog.retry'),
59
-                value: 'retry'
60
-            }, {
61
-                title: APP.translation.generateTranslationHTML("dialog.Cancel"),
62
-                value: false
63
-            }],
88
+            buttons: finishedButtons,
64 89
             defaultButton: 0,
65 90
             submit: function (e, v, m, f) {
66 91
                 e.preventDefault();

+ 37
- 34
modules/connection.js Прегледај датотеку

@@ -5,7 +5,7 @@ import LoginDialog from './UI/authentication/LoginDialog';
5 5
 const ConnectionEvents = JitsiMeetJS.events.connection;
6 6
 const ConnectionErrors = JitsiMeetJS.errors.connection;
7 7
 
8
-export function openConnection({retry, id, password}) {
8
+function connect(id, password) {
9 9
     let connection = new JitsiMeetJS.JitsiConnection(null, null, {
10 10
         hosts: config.hosts,
11 11
         bosh: config.bosh,
@@ -17,9 +17,8 @@ export function openConnection({retry, id, password}) {
17 17
             ConnectionEvents.CONNECTION_ESTABLISHED, handleConnectionEstablished
18 18
         );
19 19
         connection.addEventListener(
20
-            ConnectionEvents.CONNECTION_FAILED, onConnectionFailed
20
+            ConnectionEvents.CONNECTION_FAILED, handleConnectionFailed
21 21
         );
22
-        let authDialog;
23 22
 
24 23
         function unsubscribe() {
25 24
             connection.removeEventListener(
@@ -27,11 +26,9 @@ export function openConnection({retry, id, password}) {
27 26
                 handleConnectionEstablished
28 27
             );
29 28
             connection.removeEventListener(
30
-                ConnectionEvents.CONNECTION_FAILED, onConnectionFailed
29
+                ConnectionEvents.CONNECTION_FAILED,
30
+                handleConnectionFailed
31 31
             );
32
-            if (authDialog) {
33
-                authDialog.close();
34
-            }
35 32
         }
36 33
 
37 34
         function handleConnectionEstablished() {
@@ -41,43 +38,49 @@ export function openConnection({retry, id, password}) {
41 38
 
42 39
         function handleConnectionFailed(err) {
43 40
             unsubscribe();
41
+            console.error("CONNECTION FAILED:", err);
44 42
             reject(err);
45 43
         }
46 44
 
47
-        function onConnectionFailed (err) {
48
-            console.error("CONNECTION FAILED:", err);
45
+        connection.connect({id, password});
46
+    });
47
+}
49 48
 
50
-            if (!retry) {
51
-                handleConnectionFailed(err);
52
-                return;
49
+function requestAuth() {
50
+    return new Promise(function (resolve, reject) {
51
+        let authDialog = LoginDialog.showAuthDialog(
52
+            function (id, password) {
53
+                connect(id, password).then(function (connection) {
54
+                    authDialog.close();
55
+                    resolve(connection);
56
+                }, function (err) {
57
+                    if (err === ConnectionErrors.PASSWORD_REQUIRED) {
58
+                        authDialog.displayError(err);
59
+                    } else {
60
+                        authDialog.close();
61
+                        reject(err);
62
+                    }
63
+                });
53 64
             }
65
+        );
66
+    });
67
+}
54 68
 
55
-            // retry only if auth failed
56
-            if (err !== ConnectionErrors.PASSWORD_REQUIRED) {
57
-                handleConnectionFailed(err);
58
-                return;
59
-            }
69
+export function openConnection({id, password, retry}) {
70
+    return connect(id, password).catch(function (err) {
71
+        if (!retry) {
72
+            throw err;
73
+        }
60 74
 
75
+        if (err === ConnectionErrors.PASSWORD_REQUIRED) {
61 76
             // do not retry if token is not valid
62 77
             if (config.token) {
63
-                handleConnectionFailed(err);
64
-                return;
65
-            }
66
-
67
-            // ask for password and try again
68
-
69
-            if (authDialog) {
70
-                authDialog.displayError(err);
71
-                return;
78
+                throw err;
79
+            } else {
80
+                return requestAuth();
72 81
             }
73
-
74
-            authDialog = LoginDialog.showAuthDialog(
75
-                function (id, password) {
76
-                    connection.connect({id, password});
77
-                }
78
-            );
82
+        } else {
83
+            throw err;
79 84
         }
80
-
81
-        connection.connect(id, password);
82 85
     });
83 86
 }

+ 1
- 0
modules/desktopsharing/desktopsharing.js Прегледај датотеку

@@ -73,6 +73,7 @@ module.exports = {
73 73
     
74 74
     init: function () {
75 75
         // Called when RTC finishes initialization
76
+        return;
76 77
         APP.RTC.addListener(RTCEvents.RTC_READY,
77 78
             function() {
78 79
                 screenObtainer.init(eventEmitter);

+ 1
- 0
modules/statistics/statistics.js Прегледај датотеку

@@ -86,6 +86,7 @@ var statistics = {
86 86
         stopRemote();
87 87
     },
88 88
     start: function () {
89
+        return;
89 90
         APP.RTC.addStreamListener(onStreamCreated,
90 91
             StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
91 92
         APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,

Loading…
Откажи
Сачувај