Просмотр исходного кода

Merge pull request #518 from isymchych/really-fix-auth

Fix login/logout
master
Paweł Domas 10 лет назад
Родитель
Сommit
259fae331f

+ 42
- 16
conference.js Просмотреть файл

@@ -110,6 +110,33 @@ function muteLocalVideo (muted) {
110 110
     }
111 111
 }
112 112
 
113
+/**
114
+ * Disconnect from the conference and optionally request user feedback.
115
+ * @param {boolean} [requestFeedback=false] if user feedback should be requested
116
+ */
117
+function hangup (requestFeedback = false) {
118
+    let promise = Promise.resolve();
119
+
120
+    if (requestFeedback) {
121
+        promise = APP.UI.requestFeedback();
122
+    }
123
+
124
+    promise.then(function () {
125
+        connection.disconnect();
126
+
127
+        if (!config.enableWelcomePage) {
128
+            return;
129
+        }
130
+        // redirect to welcome page
131
+        setTimeout(() => {
132
+            APP.settings.setWelcomePageEnabled(true);
133
+            window.location.pathname = "/";
134
+        }, 3000);
135
+    }, function (err) {
136
+        console.error('Failed to hangup the call:', err);
137
+    });
138
+}
139
+
113 140
 /**
114 141
  * Create local tracks of specified types.
115 142
  * @param {string[]} devices required track types ('audio', 'video' etc.)
@@ -624,10 +651,16 @@ export default {
624 651
     _setupListeners () {
625 652
         // add local streams when joined to the conference
626 653
         room.on(ConferenceEvents.CONFERENCE_JOINED, () => {
627
-            APP.UI.updateAuthInfo(room.isAuthEnabled(), room.getAuthLogin());
628 654
             APP.UI.mucJoined();
629 655
         });
630 656
 
657
+        room.on(
658
+            ConferenceEvents.AUTH_STATUS_CHANGED,
659
+            function (authEnabled, authLogin) {
660
+                APP.UI.updateAuthInfo(authEnabled, authLogin);
661
+            }
662
+        );
663
+
631 664
 
632 665
         room.on(ConferenceEvents.USER_JOINED, (id, user) => {
633 666
             console.log('USER %s connnected', id, user);
@@ -909,25 +942,18 @@ export default {
909 942
 
910 943
         // call hangup
911 944
         APP.UI.addListener(UIEvents.HANGUP, () => {
912
-            APP.UI.requestFeedback().then(() => {
913
-                connection.disconnect();
914
-                config.enableWelcomePage && setTimeout(() => {
915
-                        window.localStorage.welcomePageDisabled = false;
916
-                        window.location.pathname = "/";
917
-                    }, 3000);
918
-            }, (err) => {console.error(err);});
945
+            hangup(true);
919 946
         });
920 947
 
921 948
         // logout
922 949
         APP.UI.addListener(UIEvents.LOGOUT, () => {
923
-            // FIXME handle logout
924
-            // APP.xmpp.logout(function (url) {
925
-            //     if (url) {
926
-            //         window.location.href = url;
927
-            //     } else {
928
-            //         hangup();
929
-            //     }
930
-            // });
950
+            AuthHandler.logout(room).then(function (url) {
951
+                if (url) {
952
+                    window.location.href = url;
953
+                } else {
954
+                    hangup(true);
955
+                }
956
+            });
931 957
         });
932 958
 
933 959
         APP.UI.addListener(UIEvents.SIP_DIAL, (sipNumber) => {

+ 1
- 2
modules/UI/UI.js Просмотреть файл

@@ -315,8 +315,7 @@ UI.start = function () {
315 315
     document.title = interfaceConfig.APP_NAME;
316 316
     var setupWelcomePage = null;
317 317
     if(config.enableWelcomePage && window.location.pathname == "/" &&
318
-        (!window.localStorage.welcomePageDisabled ||
319
-            window.localStorage.welcomePageDisabled == "false")) {
318
+       Settings.isWelcomePageEnabled()) {
320 319
         $("#videoconference_page").hide();
321 320
         if (!setupWelcomePage)
322 321
             setupWelcomePage = require("./welcome_page/WelcomePage");

+ 24
- 8
modules/UI/authentication/AuthHandler.js Просмотреть файл

@@ -69,13 +69,8 @@ function doXmppAuth (room, lockPassword) {
69 69
                     APP.translation.translateString('connection.GOT_SESSION_ID')
70 70
                 );
71 71
 
72
-                if (room.isJoined()) {
73
-                    // just reallocate focus if already joined
74
-                    room.room.moderator.allocateConferenceFocus();
75
-                } else {
76
-                    // or join
77
-                    room.join(lockPassword);
78
-                }
72
+                // authenticate conference on the fly
73
+                room.join(lockPassword);
79 74
 
80 75
                 loginDialog.close();
81 76
             }).catch(function (error, code) {
@@ -111,6 +106,26 @@ function authenticate (room, lockPassword) {
111 106
     }
112 107
 }
113 108
 
109
+/**
110
+ * De-authenticate local user.
111
+ *
112
+ * @param {JitsiConference} room
113
+ * @param {string} [lockPassword] password to use if the conference is locked
114
+ * @returns {Promise}
115
+ */
116
+function logout (room) {
117
+    return new Promise(function (resolve) {
118
+        room.room.moderator.logout(resolve);
119
+    }).then(function (url) {
120
+        // de-authenticate conference on the fly
121
+        if (room.isJoined()) {
122
+            room.join();
123
+        }
124
+
125
+        return url;
126
+    });
127
+}
128
+
114 129
 /**
115 130
  * Notify user that authentication is required to create the conference.
116 131
  * @param {JitsiConference} room
@@ -145,5 +160,6 @@ function closeAuth() {
145 160
 export default {
146 161
     authenticate,
147 162
     requireAuth,
148
-    closeAuth
163
+    closeAuth,
164
+    logout
149 165
 };

+ 5
- 4
modules/UI/welcome_page/WelcomePage.js Просмотреть файл

@@ -1,4 +1,4 @@
1
-/* global $, interfaceConfig */
1
+/* global $, interfaceConfig, APP */
2 2
 var animateTimeout, updateTimeout;
3 3
 
4 4
 var RoomnameGenerator = require("../../util/RoomnameGenerator");
@@ -87,10 +87,11 @@ function setupWelcomePage() {
87 87
     }
88 88
 
89 89
     $("#disable_welcome").click(function () {
90
-        window.localStorage.welcomePageDisabled =
91
-            $("#disable_welcome").is(":checked");
90
+        APP.settings.setWelcomePageEnabled(
91
+            !$("#disable_welcome").is(":checked")
92
+        );
92 93
     });
93 94
 
94 95
 }
95 96
 
96
-module.exports = setupWelcomePage;
97
+module.exports = setupWelcomePage;

+ 21
- 0
modules/settings/Settings.js Просмотреть файл

@@ -7,6 +7,7 @@ let userId;
7 7
 let language = null;
8 8
 let cameraDeviceId = '';
9 9
 let micDeviceId = '';
10
+let welcomePageDisabled = false;
10 11
 
11 12
 function supportsLocalStorage() {
12 13
     try {
@@ -37,6 +38,9 @@ if (supportsLocalStorage()) {
37 38
     language = window.localStorage.language;
38 39
     cameraDeviceId = window.localStorage.cameraDeviceId || '';
39 40
     micDeviceId = window.localStorage.micDeviceId || '';
41
+    welcomePageDisabled = JSON.parse(
42
+        window.localStorage.welcomePageDisabled || false
43
+    );
40 44
 } else {
41 45
     console.log("local storage is not supported");
42 46
     userId = generateUniqueId();
@@ -130,5 +134,22 @@ export default {
130 134
     setMicDeviceId: function (newId = '') {
131 135
         micDeviceId = newId;
132 136
         window.localStorage.micDeviceId = newId;
137
+    },
138
+
139
+    /**
140
+     * Check if welcome page is enabled or not.
141
+     * @returns {boolean}
142
+     */
143
+    isWelcomePageEnabled () {
144
+        return !welcomePageDisabled;
145
+    },
146
+
147
+    /**
148
+     * Enable or disable welcome page.
149
+     * @param {boolean} enabled if welcome page should be enabled or not
150
+     */
151
+    setWelcomePageEnabled (enabled) {
152
+        welcomePageDisabled = !enabled;
153
+        window.localStorage.welcomePageDisabled = welcomePageDisabled;
133 154
     }
134 155
 };

Загрузка…
Отмена
Сохранить