Kaynağa Gözat

refactor authentication module

j8
isymchych 9 yıl önce
ebeveyn
işleme
ec2be349df

+ 4
- 1
app.js Dosyayı Görüntüle

@@ -460,6 +460,10 @@ function initConference(localTracks, connection) {
460 460
         // APP.xmpp.eject(self.id);
461 461
     });
462 462
 
463
+    APP.UI.addListener(UIEvents.AUTH_CLICKED, function () {
464
+        // FIXME handle
465
+    });
466
+
463 467
     APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, function (id) {
464 468
         room.selectParticipant(id);
465 469
     });
@@ -484,7 +488,6 @@ function initConference(localTracks, connection) {
484 488
 
485 489
         // FIXME handle errors here
486 490
 
487
-        APP.UI.closeAuthenticationDialog();
488 491
         room.join();
489 492
     }).catch(function (err) {
490 493
         // FIXME notify that we cannot conenct to the room

+ 0
- 15
modules/UI/UI.js Dosyayı Görüntüle

@@ -22,7 +22,6 @@ var EventEmitter = require("events");
22 22
 var Settings = require("./../settings/Settings");
23 23
 UI.messageHandler = require("./util/MessageHandler");
24 24
 var messageHandler = UI.messageHandler;
25
-var Authentication  = require("./authentication/Authentication");
26 25
 var JitsiPopover = require("./util/JitsiPopover");
27 26
 var CQEvents = require("../../service/connectionquality/CQEvents");
28 27
 var DesktopSharingEventTypes
@@ -208,10 +207,6 @@ function registerListeners() {
208 207
 
209 208
     UI.addListener(UIEvents.FULLSCREEN_TOGGLE, toggleFullScreen);
210 209
 
211
-    UI.addListener(UIEvents.AUTH_CLICKED, function () {
212
-        Authentication.authenticate();
213
-    });
214
-
215 210
     UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
216 211
 
217 212
     UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
@@ -407,7 +402,6 @@ UI.updateLocalRole = function (isModerator) {
407 402
     SettingsMenu.onRoleChanged();
408 403
 
409 404
     if (isModerator) {
410
-        Authentication.closeAuthenticationWindow();
411 405
         messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
412 406
 
413 407
         Toolbar.checkAutoRecord();
@@ -437,10 +431,6 @@ UI.updateUserRole = function (user) {
437 431
     }
438 432
 };
439 433
 
440
-UI.notifyAuthRequired = function (intervalCallback) {
441
-    Authentication.openAuthenticationDialog(APP.conference.roomName, intervalCallback);
442
-};
443
-
444 434
 
445 435
 UI.toggleSmileys = function () {
446 436
     Chat.toggleSmileys();
@@ -506,11 +496,6 @@ UI.showLoginPopup = function(callback) {
506 496
     );
507 497
 };
508 498
 
509
-UI.closeAuthenticationDialog = function () {
510
-    Authentication.closeAuthenticationDialog();
511
-    Authentication.stopInterval();
512
-};
513
-
514 499
 UI.askForNickname = function () {
515 500
     return window.prompt('Your nickname (optional)');
516 501
 };

+ 0
- 156
modules/UI/authentication/Authentication.js Dosyayı Görüntüle

@@ -1,156 +0,0 @@
1
-/* global $, APP*/
2
-/* jshint -W101 */
3
-
4
-import messageHandler from '../util/MessageHandler';
5
-
6
-var LoginDialog = require('./LoginDialog');
7
-var Moderator = require('../../xmpp/moderator');
8
-
9
-/* Initial "authentication required" dialog */
10
-var authDialog = null;
11
-/* Loop retry ID that wits for other user to create the room */
12
-var authRetryId = null;
13
-var authenticationWindow = null;
14
-
15
-var Authentication = {
16
-    authenticate () {
17
-        Authentication.focusAuthenticationWindow();
18
-        if (!APP.xmpp.isExternalAuthEnabled()) {
19
-            Authentication.xmppAuthenticate();
20
-            return;
21
-        }
22
-        // Get authentication URL
23
-        if (!APP.xmpp.isMUCJoined()) {
24
-            APP.xmpp.getLoginUrl(APP.conference.roomName, function (url) {
25
-                // If conference has not been started yet - redirect to login page
26
-                window.location.href = url;
27
-            });
28
-        } else {
29
-            APP.xmpp.getPopupLoginUrl(APP.conference.roomName, function (url) {
30
-                // Otherwise - open popup with authentication URL
31
-                var authenticationWindow = Authentication.createAuthenticationWindow(
32
-                    function () {
33
-                        // On popup closed - retry room allocation
34
-                        APP.xmpp.allocateConferenceFocus(
35
-                            APP.conference.roomName,
36
-                            function () { console.info("AUTH DONE"); }
37
-                        );
38
-                    }, url);
39
-                if (!authenticationWindow) {
40
-                    messageHandler.openMessageDialog(null, "dialog.popupError");
41
-                }
42
-            });
43
-        }
44
-    },
45
-
46
-    openAuthenticationDialog (roomName, intervalCallback) {
47
-        // This is the loop that will wait for the room to be created by
48
-        // someone else. 'auth_required.moderator' will bring us back here.
49
-        authRetryId = window.setTimeout(intervalCallback, 5000);
50
-        // Show prompt only if it's not open
51
-        if (authDialog !== null) {
52
-            return;
53
-        }
54
-        // extract room name from 'room@muc.server.net'
55
-        var room = roomName.substr(0, roomName.indexOf('@'));
56
-
57
-        var title
58
-            = APP.translation.generateTranslationHTML("dialog.WaitingForHost");
59
-        var msg
60
-            = APP.translation.generateTranslationHTML(
61
-                    "dialog.WaitForHostMsg", {room: room});
62
-
63
-        var buttonTxt
64
-            = APP.translation.generateTranslationHTML("dialog.IamHost");
65
-        var buttons = [];
66
-        buttons.push({title: buttonTxt, value: "authNow"});
67
-
68
-        authDialog = messageHandler.openDialog(
69
-            title,
70
-            msg,
71
-            true,
72
-            buttons,
73
-            function (onSubmitEvent, submitValue) {
74
-
75
-                // Do not close the dialog yet
76
-                onSubmitEvent.preventDefault();
77
-
78
-                // Open login popup
79
-                if (submitValue === 'authNow') {
80
-                    Authentication.authenticate();
81
-                }
82
-            }
83
-        );
84
-    },
85
-    closeAuthenticationWindow () {
86
-        if (authenticationWindow) {
87
-            authenticationWindow.close();
88
-            authenticationWindow = null;
89
-        }
90
-    },
91
-    xmppAuthenticate () {
92
-        var loginDialog = LoginDialog.show(
93
-            function (connection, state) {
94
-                if (!state) {
95
-                    // User cancelled
96
-                    loginDialog.close();
97
-                    return;
98
-                } else if (state == APP.xmpp.Status.CONNECTED) {
99
-
100
-                    loginDialog.close();
101
-
102
-                    Authentication.stopInterval();
103
-                    Authentication.closeAuthenticationDialog();
104
-
105
-                    // Close the connection as anonymous one will be used
106
-                    // to create the conference. Session-id will authorize
107
-                    // the request.
108
-                    connection.disconnect();
109
-
110
-                    var roomName = APP.conference.roomName;
111
-                    Moderator.allocateConferenceFocus(roomName, function () {
112
-                        // If it's not "on the fly" authentication now join
113
-                        // the conference room
114
-                        if (!APP.xmpp.isMUCJoined()) {
115
-                            APP.UI.checkForNicknameAndJoin();
116
-                        }
117
-                    });
118
-                }
119
-            }, true);
120
-    },
121
-    focusAuthenticationWindow () {
122
-        // If auth window exists just bring it to the front
123
-        if (authenticationWindow) {
124
-            authenticationWindow.focus();
125
-            return;
126
-        }
127
-    },
128
-    closeAuthenticationDialog () {
129
-        // Close authentication dialog if opened
130
-        if (authDialog) {
131
-            authDialog.close();
132
-            authDialog = null;
133
-        }
134
-    },
135
-    createAuthenticationWindow (callback, url) {
136
-        authenticationWindow = messageHandler.openCenteredPopup(
137
-            url, 910, 660,
138
-            // On closed
139
-            function () {
140
-                // Close authentication dialog if opened
141
-                Authentication.closeAuthenticationDialog();
142
-                callback();
143
-                authenticationWindow = null;
144
-            });
145
-        return authenticationWindow;
146
-    },
147
-    stopInterval () {
148
-        // Clear retry interval, so that we don't call 'doJoinAfterFocus' twice
149
-        if (authRetryId) {
150
-            window.clearTimeout(authRetryId);
151
-            authRetryId = null;
152
-        }
153
-    }
154
-};
155
-
156
-module.exports = Authentication;

+ 29
- 127
modules/UI/authentication/LoginDialog.js Dosyayı Görüntüle

@@ -1,35 +1,19 @@
1 1
 /* global $, APP, config*/
2 2
 
3
-var XMPP = require('../../xmpp/xmpp');
4
-var Moderator = require('../../xmpp/moderator');
3
+var messageHandler = require('../util/MessageHandler');
5 4
 
6 5
 //FIXME: use LoginDialog to add retries to XMPP.connect method used when
7 6
 // anonymous domain is not enabled
8 7
 
9
-/**
10
- * Creates new <tt>Dialog</tt> instance.
11
- * @param callback <tt>function(Strophe.Connection, Strophe.Status)</tt> called
12
- *        when we either fail to connect or succeed(check Strophe.Status).
13
- * @param obtainSession <tt>true</tt> if we want to send ConferenceIQ to Jicofo
14
- *        in order to create session-id after the connection is established.
15
- * @constructor
16
- */
17
-function Dialog(callback, obtainSession) {
18
-
19
-    var self = this;
20
-
21
-    var stop = false;
22
-
23
-    var connection = APP.xmpp.createConnection();
24
-
8
+function Dialog(successCallback, cancelCallback) {
25 9
     var message = '<h2 data-i18n="dialog.passwordRequired">';
26 10
     message += APP.translation.translateString("dialog.passwordRequired");
27 11
     message += '</h2>' +
28 12
         '<input name="username" type="text" ';
29 13
     if (config.hosts.authdomain) {
30
-      message += 'placeholder="user identity" autofocus>';
14
+        message += 'placeholder="user identity" autofocus>';
31 15
     } else {
32
-      message += 'placeholder="user@domain.net" autofocus>';
16
+        message += 'placeholder="user@domain.net" autofocus>';
33 17
     }
34 18
     message += '<input name="password" ' +
35 19
         'type="password" data-i18n="[placeholder]dialog.userPassword"' +
@@ -53,23 +37,12 @@ function Dialog(callback, obtainSession) {
53 37
                     var jid = f.username;
54 38
                     var password = f.password;
55 39
                     if (jid && password) {
56
-                        stop = false;
57
-                        if (jid.indexOf("@") < 0) {
58
-                          jid = jid.concat('@');
59
-                          if (config.hosts.authdomain) {
60
-                            jid += config.hosts.authdomain;
61
-                          } else {
62
-                            jid += config.hosts.domain;
63
-                          }
64
-                        }
65
-                        connection.reset();
66 40
                         connDialog.goToState('connecting');
67
-                        connection.connect(jid, password, stateHandler);
41
+                        successCallback(jid, password);
68 42
                     }
69 43
                 } else {
70 44
                     // User cancelled
71
-                    stop = true;
72
-                    callback();
45
+                    cancelCallback();
73 46
                 }
74 47
             }
75 48
         },
@@ -95,102 +68,18 @@ function Dialog(callback, obtainSession) {
95 68
             defaultButton: 0,
96 69
             submit: function (e, v, m, f) {
97 70
                 e.preventDefault();
98
-                if (v === 'retry')
71
+                if (v === 'retry') {
99 72
                     connDialog.goToState('login');
100
-                else
101
-                    callback();
73
+                } else {
74
+                    cancelCallback();
75
+                }
102 76
             }
103 77
         }
104 78
     };
105 79
 
106
-    var connDialog
107
-        = APP.UI.messageHandler.openDialogWithStates(states,
108
-                { persistent: true, closeText: '' }, null);
109
-
110
-    var stateHandler = function (status, message) {
111
-        if (stop) {
112
-            return;
113
-        }
114
-
115
-        var translateKey = "connection." + XMPP.getStatusString(status);
116
-        var statusStr = APP.translation.translateString(translateKey);
117
-
118
-        // Display current state
119
-        var connectionStatus =
120
-            connDialog.getState('connecting').find('#connectionStatus');
121
-
122
-        connectionStatus.text(statusStr);
123
-
124
-        switch (status) {
125
-            case XMPP.Status.CONNECTED:
126
-
127
-                stop = true;
128
-                if (!obtainSession) {
129
-                    callback(connection, status);
130
-                    return;
131
-                }
132
-                // Obtaining session-id status
133
-                connectionStatus.text(
134
-                    APP.translation.translateString(
135
-                        'connection.FETCH_SESSION_ID'));
136
-
137
-                // Authenticate with Jicofo and obtain session-id
138
-                var roomName = APP.conference.roomName;
139
-
140
-                // Jicofo will return new session-id when connected
141
-                // from authenticated domain
142
-                connection.sendIQ(
143
-                    Moderator.createConferenceIq(roomName),
144
-                    function (result) {
145
-
146
-                        connectionStatus.text(
147
-                            APP.translation.translateString(
148
-                                'connection.GOT_SESSION_ID'));
149
-
150
-                        stop = true;
151
-
152
-                        // Parse session-id
153
-                        Moderator.parseSessionId(result);
154
-
155
-                        callback(connection, status);
156
-                    },
157
-                    function (error) {
158
-                        console.error("Auth on the fly failed", error);
159
-
160
-                        stop = true;
161
-
162
-                        var errorMsg =
163
-                            APP.translation.translateString(
164
-                                'connection.GET_SESSION_ID_ERROR') +
165
-                                $(error).find('>error').attr('code');
166
-
167
-                        self.displayError(errorMsg);
168
-
169
-                        connection.disconnect();
170
-                    });
171
-
172
-                break;
173
-            case XMPP.Status.AUTHFAIL:
174
-            case XMPP.Status.CONNFAIL:
175
-            case XMPP.Status.DISCONNECTED:
176
-
177
-                stop = true;
178
-
179
-                callback(connection, status);
180
-
181
-                var errorMessage = statusStr;
182
-
183
-                if (message)
184
-                {
185
-                    errorMessage += ': ' + message;
186
-                }
187
-                self.displayError(errorMessage);
188
-
189
-                break;
190
-            default:
191
-                break;
192
-        }
193
-    };
80
+    var connDialog = messageHandler.openDialogWithStates(
81
+        states, { persistent: true, closeText: '' }, null
82
+    );
194 83
 
195 84
     /**
196 85
      * Displays error message in 'finished' state which allows either to cancel
@@ -211,7 +100,6 @@ function Dialog(callback, obtainSession) {
211 100
      * Closes LoginDialog.
212 101
      */
213 102
     this.close = function () {
214
-        stop = true;
215 103
         connDialog.close();
216 104
     };
217 105
 }
@@ -232,8 +120,22 @@ var LoginDialog = {
232 120
      *        established.
233 121
      * @returns {Dialog}
234 122
      */
235
-    show: function (callback, obtainSession) {
236
-        return new Dialog(callback, obtainSession);
123
+    show: function (successCallback, cancelCallback) {
124
+        return new Dialog(successCallback, cancelCallback);
125
+    },
126
+
127
+    showExternalAuthDialog: function (url, callback) {
128
+        var dialog = messageHandler.openCenteredPopup(
129
+            url, 910, 660,
130
+            // On closed
131
+            callback
132
+        );
133
+
134
+        if (!dialog) {
135
+            messageHandler.openMessageDialog(null, "dialog.popupError");
136
+        }
137
+
138
+        return dialog;
237 139
     }
238 140
 };
239 141
 

+ 0
- 1
modules/UI/videolayout/SmallVideo.js Dosyayı Görüntüle

@@ -5,7 +5,6 @@ import UIUtil from "../util/UIUtil";
5 5
 import LargeVideo from "./LargeVideo";
6 6
 
7 7
 var RTCBrowserType = require("../../RTC/RTCBrowserType");
8
-var MediaStreamType = require("../../../service/RTC/MediaStreamTypes");
9 8
 
10 9
 function SmallVideo() {
11 10
     this.isMuted = false;

Loading…
İptal
Kaydet