implement user logout

This commit is contained in:
isymchych 2016-02-25 15:52:15 +02:00
parent b73bddf1c4
commit 3cf478826e
5 changed files with 85 additions and 22 deletions

View File

@ -110,6 +110,33 @@ function muteLocalVideo (muted) {
} }
} }
/**
* Disconnect from the conference and optionally request user feedback.
* @param {boolean} [requestFeedback=false] if user feedback should be requested
*/
function hangup (requestFeedback = false) {
let promise = Promise.resolve();
if (requestFeedback) {
promise = APP.UI.requestFeedback();
}
promise.then(function () {
connection.disconnect();
if (!config.enableWelcomePage) {
return;
}
// redirect to welcome page
setTimeout(() => {
APP.settings.setWelcomePageEnabled(true);
window.location.pathname = "/";
}, 3000);
}, function (err) {
console.error('Failed to hangup the call:', err);
});
}
/** /**
* Create local tracks of specified types. * Create local tracks of specified types.
* @param {string[]} devices required track types ('audio', 'video' etc.) * @param {string[]} devices required track types ('audio', 'video' etc.)
@ -915,25 +942,18 @@ export default {
// call hangup // call hangup
APP.UI.addListener(UIEvents.HANGUP, () => { APP.UI.addListener(UIEvents.HANGUP, () => {
APP.UI.requestFeedback().then(() => { hangup(true);
connection.disconnect();
config.enableWelcomePage && setTimeout(() => {
window.localStorage.welcomePageDisabled = false;
window.location.pathname = "/";
}, 3000);
}, (err) => {console.error(err);});
}); });
// logout // logout
APP.UI.addListener(UIEvents.LOGOUT, () => { APP.UI.addListener(UIEvents.LOGOUT, () => {
// FIXME handle logout AuthHandler.logout(room).then(function (url) {
// APP.xmpp.logout(function (url) { if (url) {
// if (url) { window.location.href = url;
// window.location.href = url; } else {
// } else { hangup(true);
// hangup(); }
// } });
// });
}); });
APP.UI.addListener(UIEvents.SIP_DIAL, (sipNumber) => { APP.UI.addListener(UIEvents.SIP_DIAL, (sipNumber) => {

View File

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

View File

@ -69,6 +69,7 @@ function doXmppAuth (room, lockPassword) {
APP.translation.translateString('connection.GOT_SESSION_ID') APP.translation.translateString('connection.GOT_SESSION_ID')
); );
// authenticate conference on the fly
room.join(lockPassword); room.join(lockPassword);
loginDialog.close(); loginDialog.close();
@ -105,6 +106,26 @@ function authenticate (room, lockPassword) {
} }
} }
/**
* De-authenticate local user.
*
* @param {JitsiConference} room
* @param {string} [lockPassword] password to use if the conference is locked
* @returns {Promise}
*/
function logout (room) {
return new Promise(function (resolve) {
room.room.moderator.logout(resolve);
}).then(function (url) {
// de-authenticate conference on the fly
if (room.isJoined()) {
room.join();
}
return url;
});
}
/** /**
* Notify user that authentication is required to create the conference. * Notify user that authentication is required to create the conference.
* @param {JitsiConference} room * @param {JitsiConference} room
@ -139,5 +160,6 @@ function closeAuth() {
export default { export default {
authenticate, authenticate,
requireAuth, requireAuth,
closeAuth closeAuth,
logout
}; };

View File

@ -1,4 +1,4 @@
/* global $, interfaceConfig */ /* global $, interfaceConfig, APP */
var animateTimeout, updateTimeout; var animateTimeout, updateTimeout;
var RoomnameGenerator = require("../../util/RoomnameGenerator"); var RoomnameGenerator = require("../../util/RoomnameGenerator");
@ -87,8 +87,9 @@ function setupWelcomePage() {
} }
$("#disable_welcome").click(function () { $("#disable_welcome").click(function () {
window.localStorage.welcomePageDisabled = APP.settings.setWelcomePageEnabled(
$("#disable_welcome").is(":checked"); !$("#disable_welcome").is(":checked")
);
}); });
} }

View File

@ -7,6 +7,7 @@ let userId;
let language = null; let language = null;
let cameraDeviceId = ''; let cameraDeviceId = '';
let micDeviceId = ''; let micDeviceId = '';
let welcomePageDisabled = false;
function supportsLocalStorage() { function supportsLocalStorage() {
try { try {
@ -37,6 +38,9 @@ if (supportsLocalStorage()) {
language = window.localStorage.language; language = window.localStorage.language;
cameraDeviceId = window.localStorage.cameraDeviceId || ''; cameraDeviceId = window.localStorage.cameraDeviceId || '';
micDeviceId = window.localStorage.micDeviceId || ''; micDeviceId = window.localStorage.micDeviceId || '';
welcomePageDisabled = JSON.parse(
window.localStorage.welcomePageDisabled || false
);
} else { } else {
console.log("local storage is not supported"); console.log("local storage is not supported");
userId = generateUniqueId(); userId = generateUniqueId();
@ -130,5 +134,22 @@ export default {
setMicDeviceId: function (newId = '') { setMicDeviceId: function (newId = '') {
micDeviceId = newId; micDeviceId = newId;
window.localStorage.micDeviceId = newId; window.localStorage.micDeviceId = newId;
},
/**
* Check if welcome page is enabled or not.
* @returns {boolean}
*/
isWelcomePageEnabled () {
return !welcomePageDisabled;
},
/**
* Enable or disable welcome page.
* @param {boolean} enabled if welcome page should be enabled or not
*/
setWelcomePageEnabled (enabled) {
welcomePageDisabled = !enabled;
window.localStorage.welcomePageDisabled = welcomePageDisabled;
} }
}; };