Browse Source

better error handling while establishing connection

j8
isymchych 9 years ago
parent
commit
3a00837107

+ 4
- 2
app.js View File

17
 import RoomnameGenerator from './modules/util/RoomnameGenerator';
17
 import RoomnameGenerator from './modules/util/RoomnameGenerator';
18
 import CQEvents from './service/connectionquality/CQEvents';
18
 import CQEvents from './service/connectionquality/CQEvents';
19
 import UIEvents from './service/UI/UIEvents';
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
 import {openConnection} from './modules/connection';
21
 import {openConnection} from './modules/connection';
24
 import AuthHandler from './modules/AuthHandler';
22
 import AuthHandler from './modules/AuthHandler';
149
             room.addTrack(track);
147
             room.addTrack(track);
150
             APP.UI.addLocalStream(track);
148
             APP.UI.addLocalStream(track);
151
         });
149
         });
150
+
151
+        APP.UI.updateAuthInfo(room.isAuthEnabled(), room.getAuthLogin());
152
     });
152
     });
153
 
153
 
154
 
154
 
534
         APP.statistics.start();
534
         APP.statistics.start();
535
         APP.connectionquality.init();
535
         APP.connectionquality.init();
536
         APP.keyboardshortcut.init();
536
         APP.keyboardshortcut.init();
537
+    }).catch(function (err) {
538
+        console.error(err);
537
     });
539
     });
538
 }
540
 }
539
 
541
 

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

34
     this.connection = this.options.connection;
34
     this.connection = this.options.connection;
35
     this.xmpp = this.connection.xmpp;
35
     this.xmpp = this.connection.xmpp;
36
     this.eventEmitter = new EventEmitter();
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
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
38
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
39
     this.rtc = new RTC(this.room, options);
39
     this.rtc = new RTC(this.room, options);
40
     if(!RTC.options.disableAudioLevels)
40
     if(!RTC.options.disableAudioLevels)
44
     this.lastActiveSpeaker = null;
44
     this.lastActiveSpeaker = null;
45
     this.dtmfManager = null;
45
     this.dtmfManager = null;
46
     this.somebodySupportsDTMF = false;
46
     this.somebodySupportsDTMF = false;
47
+    this.authEnabled = false;
48
+    this.authIdentity;
47
 }
49
 }
48
 
50
 
49
 /**
51
 /**
78
     return this.options.name;
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
  * Check if external authentication is enabled for this conference.
105
  * Check if external authentication is enabled for this conference.
83
  */
106
  */
385
 
408
 
386
 JitsiConference.prototype.onMemberLeft = function (jid) {
409
 JitsiConference.prototype.onMemberLeft = function (jid) {
387
     var id = Strophe.getResourceFromJid(jid);
410
     var id = Strophe.getResourceFromJid(jid);
411
+    if (id === 'focus') {
412
+       return;
413
+    }
388
     var participant = this.participants[id];
414
     var participant = this.participants[id];
389
     delete this.participants[id];
415
     delete this.participants[id];
390
     this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
416
     this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
564
     });
590
     });
565
 
591
 
566
     conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
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
     conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
597
     conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
11522
     return this._connect(jid, password);
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
     var roomjid = roomName  + '@' + this.options.hosts.muc;
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
         } else {
11558
         } else {
11532
             roomjid += '/' + Strophe.getNodeFromJid(this.connection.jid);
11559
             roomjid += '/' + Strophe.getNodeFromJid(this.connection.jid);
11533
         }
11560
         }

+ 11
- 4
modules/UI/UI.js View File

612
     VideoLayout.updateConnectionStats(jid, percent, stats);
612
     VideoLayout.updateConnectionStats(jid, percent, stats);
613
 };
613
 };
614
 
614
 
615
-UI.showAuthenticateButton = function (show) {
616
-    Toolbar.showAuthenticateButton(show);
617
-};
618
-
619
 UI.markVideoInterrupted = function (interrupted) {
615
 UI.markVideoInterrupted = function (interrupted) {
620
     if (interrupted) {
616
     if (interrupted) {
621
         VideoLayout.onVideoInterrupted();
617
         VideoLayout.onVideoInterrupted();
740
     messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
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
 module.exports = UI;
750
 module.exports = UI;

+ 43
- 18
modules/UI/authentication/LoginDialog.js View File

13
         <h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
13
         <h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
14
         <input name="username" type="text" placeholder=${placeholder} autofocus>
14
         <input name="username" type="text" placeholder=${placeholder} autofocus>
15
         <input name="password" type="password"
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
 function Dialog(successCallback, cancelCallback) {
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
     const states = {
59
     const states = {
23
         login: {
60
         login: {
24
             html: getPasswordInputHtml(),
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
             focus: ':input:first',
63
             focus: ':input:first',
33
             submit: function (e, v, m, f) {
64
             submit: function (e, v, m, f) {
34
                 e.preventDefault();
65
                 e.preventDefault();
37
                     let password = f.password;
68
                     let password = f.password;
38
                     if (jid && password) {
69
                     if (jid && password) {
39
                         connDialog.goToState('connecting');
70
                         connDialog.goToState('connecting');
40
-                        successCallback(jid, password);
71
+                        successCallback(toJid(jid), password);
41
                     }
72
                     }
42
                 } else {
73
                 } else {
43
                     // User cancelled
74
                     // User cancelled
54
         finished: {
85
         finished: {
55
             title: APP.translation.translateString('dialog.error'),
86
             title: APP.translation.translateString('dialog.error'),
56
             html:   '<div id="errorMessage"></div>',
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
             defaultButton: 0,
89
             defaultButton: 0,
65
             submit: function (e, v, m, f) {
90
             submit: function (e, v, m, f) {
66
                 e.preventDefault();
91
                 e.preventDefault();

+ 37
- 34
modules/connection.js View File

5
 const ConnectionEvents = JitsiMeetJS.events.connection;
5
 const ConnectionEvents = JitsiMeetJS.events.connection;
6
 const ConnectionErrors = JitsiMeetJS.errors.connection;
6
 const ConnectionErrors = JitsiMeetJS.errors.connection;
7
 
7
 
8
-export function openConnection({retry, id, password}) {
8
+function connect(id, password) {
9
     let connection = new JitsiMeetJS.JitsiConnection(null, null, {
9
     let connection = new JitsiMeetJS.JitsiConnection(null, null, {
10
         hosts: config.hosts,
10
         hosts: config.hosts,
11
         bosh: config.bosh,
11
         bosh: config.bosh,
17
             ConnectionEvents.CONNECTION_ESTABLISHED, handleConnectionEstablished
17
             ConnectionEvents.CONNECTION_ESTABLISHED, handleConnectionEstablished
18
         );
18
         );
19
         connection.addEventListener(
19
         connection.addEventListener(
20
-            ConnectionEvents.CONNECTION_FAILED, onConnectionFailed
20
+            ConnectionEvents.CONNECTION_FAILED, handleConnectionFailed
21
         );
21
         );
22
-        let authDialog;
23
 
22
 
24
         function unsubscribe() {
23
         function unsubscribe() {
25
             connection.removeEventListener(
24
             connection.removeEventListener(
27
                 handleConnectionEstablished
26
                 handleConnectionEstablished
28
             );
27
             );
29
             connection.removeEventListener(
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
         function handleConnectionEstablished() {
34
         function handleConnectionEstablished() {
41
 
38
 
42
         function handleConnectionFailed(err) {
39
         function handleConnectionFailed(err) {
43
             unsubscribe();
40
             unsubscribe();
41
+            console.error("CONNECTION FAILED:", err);
44
             reject(err);
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
             // do not retry if token is not valid
76
             // do not retry if token is not valid
62
             if (config.token) {
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 View File

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

+ 1
- 0
modules/statistics/statistics.js View File

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

Loading…
Cancel
Save