diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-02-04 13:56:10 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-02-04 13:56:10 +0100 |
commit | 912da8d27756d9f0d55821338f6d8698af2dbd27 (patch) | |
tree | dac95a4673a5d523366b9478c27887d16571f0a4 /core/js/js.js | |
parent | 49f0f9f2f67c3494628f14c7a5c383596879ec12 (diff) | |
download | nextcloud-server-912da8d27756d9f0d55821338f6d8698af2dbd27.tar.gz nextcloud-server-912da8d27756d9f0d55821338f6d8698af2dbd27.zip |
Added session_keepalive setting
When session_keepalive is true (default) the heartbeat will be send as
often as the half of the session timeout value.
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/core/js/js.js b/core/js/js.js index 1c7d89ea055..cd9b8bd3010 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -11,6 +11,8 @@ var oc_webroot; var oc_current_user = document.getElementsByTagName('head')[0].getAttribute('data-user'); var oc_requesttoken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken'); +window.oc_config = window.oc_config || {}; + if (typeof oc_webroot === "undefined") { oc_webroot = location.pathname; var pos = oc_webroot.indexOf('/index.php/'); @@ -742,8 +744,39 @@ function fillWindow(selector) { console.warn("This function is deprecated! Use CSS instead"); } -$(document).ready(function(){ - sessionHeartBeat(); +/** + * Initializes core + */ +function initCore() { + + /** + * Calls the server periodically to ensure that session doesnt + * time out + */ + function initSessionHeartBeat(){ + // interval in seconds + var interval = 900; + if (oc_config.session_lifetime) { + interval = Math.floor(oc_config.session_lifetime / 2); + } + // minimum one minute + if (interval < 60) { + interval = 60; + } + OC.Router.registerLoadedCallback(function(){ + var url = OC.Router.generate('heartbeat'); + setInterval(function(){ + $.post(url); + }, interval * 1000); + }); + } + + // session heartbeat (defalts to enabled) + if (typeof(oc_config.session_keepalive) === 'undefined' || + !!oc_config.session_keepalive) { + + initSessionHeartBeat(); + } if(!SVGSupport()){ //replace all svg images with png images for browser that dont support svg replaceSVG(); @@ -856,7 +889,9 @@ $(document).ready(function(){ $('input[type=text]').focus(function(){ this.select(); }); -}); +} + +$(document).ready(initCore); /** * Filter Jquery selector by attribute value @@ -986,15 +1021,3 @@ jQuery.fn.exists = function(){ return this.length > 0; }; -/** - * Calls the server periodically every 15 mins to ensure that session doesnt - * time out - */ -function sessionHeartBeat(){ - OC.Router.registerLoadedCallback(function(){ - var url = OC.Router.generate('heartbeat'); - setInterval(function(){ - $.post(url); - }, 900000); - }); -} |