Browse Source

implement user logout

j8
isymchych 9 years ago
parent
commit
3cf478826e

+ 35
- 15
conference.js View File

@@ -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.)
@@ -915,25 +942,18 @@ export default {
915 942
 
916 943
         // call hangup
917 944
         APP.UI.addListener(UIEvents.HANGUP, () => {
918
-            APP.UI.requestFeedback().then(() => {
919
-                connection.disconnect();
920
-                config.enableWelcomePage && setTimeout(() => {
921
-                        window.localStorage.welcomePageDisabled = false;
922
-                        window.location.pathname = "/";
923
-                    }, 3000);
924
-            }, (err) => {console.error(err);});
945
+            hangup(true);
925 946
         });
926 947
 
927 948
         // logout
928 949
         APP.UI.addListener(UIEvents.LOGOUT, () => {
929
-            // FIXME handle logout
930
-            // APP.xmpp.logout(function (url) {
931
-            //     if (url) {
932
-            //         window.location.href = url;
933
-            //     } else {
934
-            //         hangup();
935
-            //     }
936
-            // });
950
+            AuthHandler.logout(room).then(function (url) {
951
+                if (url) {
952
+                    window.location.href = url;
953
+                } else {
954
+                    hangup(true);
955
+                }
956
+            });
937 957
         });
938 958
 
939 959
         APP.UI.addListener(UIEvents.SIP_DIAL, (sipNumber) => {

+ 1
- 2
modules/UI/UI.js View File

@@ -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");

+ 23
- 1
modules/UI/authentication/AuthHandler.js View File

@@ -69,6 +69,7 @@ function doXmppAuth (room, lockPassword) {
69 69
                     APP.translation.translateString('connection.GOT_SESSION_ID')
70 70
                 );
71 71
 
72
+                // authenticate conference on the fly
72 73
                 room.join(lockPassword);
73 74
 
74 75
                 loginDialog.close();
@@ -105,6 +106,26 @@ function authenticate (room, lockPassword) {
105 106
     }
106 107
 }
107 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
+
108 129
 /**
109 130
  * Notify user that authentication is required to create the conference.
110 131
  * @param {JitsiConference} room
@@ -139,5 +160,6 @@ function closeAuth() {
139 160
 export default {
140 161
     authenticate,
141 162
     requireAuth,
142
-    closeAuth
163
+    closeAuth,
164
+    logout
143 165
 };

+ 5
- 4
modules/UI/welcome_page/WelcomePage.js View File

@@ -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 View File

@@ -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
 };

Loading…
Cancel
Save