Browse Source

Move XMPP login prompt handling to AuthHandler

master
paweldomas 8 years ago
parent
commit
38fc1c01d4
2 changed files with 39 additions and 32 deletions
  1. 2
    30
      connection.js
  2. 37
    2
      modules/UI/authentication/AuthHandler.js

+ 2
- 30
connection.js View File

1
 /* global APP, JitsiMeetJS, config */
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
 const ConnectionEvents = JitsiMeetJS.events.connection;
4
 const ConnectionEvents = JitsiMeetJS.events.connection;
6
 const ConnectionErrors = JitsiMeetJS.errors.connection;
5
 const ConnectionErrors = JitsiMeetJS.errors.connection;
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
  * Open JitsiConnection using provided credentials.
95
  * Open JitsiConnection using provided credentials.
124
  * If retry option is true it will show auth dialog on PASSWORD_REQUIRED error.
96
  * If retry option is true it will show auth dialog on PASSWORD_REQUIRED error.
157
             if (config.token) {
129
             if (config.token) {
158
                 throw err;
130
                 throw err;
159
             } else {
131
             } else {
160
-                return requestAuth(roomName);
132
+                return AuthHandler.requestAuth(roomName, connect);
161
             }
133
             }
162
         } else {
134
         } else {
163
             throw err;
135
             throw err;

+ 37
- 2
modules/UI/authentication/AuthHandler.js View File

1
-/* global JitsiMeetJS, APP */
1
+/* global APP, config, JitsiMeetJS, Promise */
2
 
2
 
3
 import LoginDialog from './LoginDialog';
3
 import LoginDialog from './LoginDialog';
4
-import UIEvents from '../../../service/UI/UIEvents';
5
 import UIUtil from '../util/UIUtil';
4
 import UIUtil from '../util/UIUtil';
6
 import {openConnection} from '../../../connection';
5
 import {openConnection} from '../../../connection';
7
 
6
 
8
 const ConferenceEvents = JitsiMeetJS.events.conference;
7
 const ConferenceEvents = JitsiMeetJS.events.conference;
8
+const ConnectionErrors = JitsiMeetJS.errors.connection;
9
 
9
 
10
 let externalAuthWindow;
10
 let externalAuthWindow;
11
 let authRequiredDialog;
11
 let authRequiredDialog;
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
 export default {
195
 export default {
162
     authenticate,
196
     authenticate,
163
     requireAuth,
197
     requireAuth,
198
+    requestAuth,
164
     closeAuth,
199
     closeAuth,
165
     logout
200
     logout
166
 };
201
 };

Loading…
Cancel
Save