Quellcode durchsuchen

Move XMPP login prompt handling to AuthHandler

master
paweldomas vor 8 Jahren
Ursprung
Commit
38fc1c01d4
2 geänderte Dateien mit 39 neuen und 32 gelöschten Zeilen
  1. 2
    30
      connection.js
  2. 37
    2
      modules/UI/authentication/AuthHandler.js

+ 2
- 30
connection.js Datei anzeigen

@@ -1,6 +1,5 @@
1 1
 /* global APP, JitsiMeetJS, config */
2
-//FIXME:
3
-import LoginDialog from './modules/UI/authentication/LoginDialog';
2
+import AuthHandler from './modules/UI/authentication/AuthHandler';
4 3
 
5 4
 const ConnectionEvents = JitsiMeetJS.events.connection;
6 5
 const ConnectionErrors = JitsiMeetJS.errors.connection;
@@ -92,33 +91,6 @@ function connect(id, password, roomName) {
92 91
     });
93 92
 }
94 93
 
95
-/**
96
- * Show Authentication Dialog and try to connect with new credentials.
97
- * If failed to connect because of PASSWORD_REQUIRED error
98
- * then ask for password again.
99
- * @param {string} [roomName]
100
- * @returns {Promise<JitsiConnection>}
101
- */
102
-function requestAuth(roomName) {
103
-    return new Promise(function (resolve, reject) {
104
-        let authDialog = LoginDialog.showAuthDialog(
105
-            function (id, password) {
106
-                connect(id, password, roomName).then(function (connection) {
107
-                    authDialog.close();
108
-                    resolve(connection);
109
-                }, function (err) {
110
-                    if (err === ConnectionErrors.PASSWORD_REQUIRED) {
111
-                        authDialog.displayError(err);
112
-                    } else {
113
-                        authDialog.close();
114
-                        reject(err);
115
-                    }
116
-                });
117
-            }
118
-        );
119
-    });
120
-}
121
-
122 94
 /**
123 95
  * Open JitsiConnection using provided credentials.
124 96
  * If retry option is true it will show auth dialog on PASSWORD_REQUIRED error.
@@ -157,7 +129,7 @@ export function openConnection({id, password, retry, roomName}) {
157 129
             if (config.token) {
158 130
                 throw err;
159 131
             } else {
160
-                return requestAuth(roomName);
132
+                return AuthHandler.requestAuth(roomName, connect);
161 133
             }
162 134
         } else {
163 135
             throw err;

+ 37
- 2
modules/UI/authentication/AuthHandler.js Datei anzeigen

@@ -1,11 +1,11 @@
1
-/* global JitsiMeetJS, APP */
1
+/* global APP, config, JitsiMeetJS, Promise */
2 2
 
3 3
 import LoginDialog from './LoginDialog';
4
-import UIEvents from '../../../service/UI/UIEvents';
5 4
 import UIUtil from '../util/UIUtil';
6 5
 import {openConnection} from '../../../connection';
7 6
 
8 7
 const ConferenceEvents = JitsiMeetJS.events.conference;
8
+const ConnectionErrors = JitsiMeetJS.errors.connection;
9 9
 
10 10
 let externalAuthWindow;
11 11
 let authRequiredDialog;
@@ -157,10 +157,45 @@ function closeAuth() {
157 157
     }
158 158
 }
159 159
 
160
+function showXmppPasswordPrompt(roomName, connect) {
161
+    return new Promise(function (resolve, reject) {
162
+        let authDialog = LoginDialog.showAuthDialog(
163
+            function (id, password) {
164
+                connect(id, password, roomName).then(function (connection) {
165
+                    authDialog.close();
166
+                    resolve(connection);
167
+                }, function (err) {
168
+                    if (err === ConnectionErrors.PASSWORD_REQUIRED) {
169
+                        authDialog.displayError(err);
170
+                    } else {
171
+                        authDialog.close();
172
+                        reject(err);
173
+                    }
174
+                });
175
+            }
176
+        );
177
+    });
178
+}
179
+
180
+/**
181
+ * Show Authentication Dialog and try to connect with new credentials.
182
+ * If failed to connect because of PASSWORD_REQUIRED error
183
+ * then ask for password again.
184
+ * @param {string} [roomName] name of the conference room
185
+ * @param {function(id, password, roomName)} [connect] function that returns
186
+ * a Promise which resolves with JitsiConnection or fails with one of
187
+ * ConnectionErrors.
188
+ * @returns {Promise<JitsiConnection>}
189
+ */
190
+function requestAuth(roomName, connect) {
191
+    return showXmppPasswordPrompt(roomName, connect);
192
+}
193
+
160 194
 
161 195
 export default {
162 196
     authenticate,
163 197
     requireAuth,
198
+    requestAuth,
164 199
     closeAuth,
165 200
     logout
166 201
 };

Laden…
Abbrechen
Speichern