Git Product home page Git Product logo

Comments (7)

JillElaine avatar JillElaine commented on July 2, 2024 1

Ah, yes, in the checkIdleTimeout function, you could reset the idleTimerLastActivity storage variable to the current time if there are active connections. Does that work as desired?

 //----------- IDLE TIMER FUNCTIONS --------------//
    checkIdleTimeout = function () {

if ($.active > 0) { // start of $.active check
  console.log('ACTIVE connection! NO TIMEOUT YET!');
  // reset 'idleTimerLastActivity' storage variable to current time
  store.set('idleTimerLastActivity', $.now());
} else {
  console.log('NO active connections. Proceed to check other timeout conditions.');

      var timeIdleTimeout = (store.get('idleTimerLastActivity') + (currentConfig.idleTimeLimit * 1000));

      if ($.now() > timeIdleTimeout) {
        console.log('inactivity has exceeded the idleTimeLimit');

        if (!currentConfig.enableDialog) { // warning dialog is disabled
          console.log('warning dialog disabled - log out user without warning');
          logoutUser(); // immediately log out user when user is idle for idleTimeLimit
        } else if (currentConfig.enableDialog && isDialogOpen() !== true) {
          console.log('warning dialog is not open & will be opened');
          openWarningDialog();
          startDialogTimer(); // start timing the warning dialog
        }
      } else if (store.get('idleTimerLoggedOut') === true) { //a 'manual' user logout?
        console.log('user has manually logged out? Log out all windows & tabs now.');
        logoutUser();
      } else {
        console.log('inactivity has not yet exceeded the idleTimeLimit');

        if (currentConfig.enableDialog && isDialogOpen() === true) {
          console.log('warning dialog is open & will be closed');
          destroyWarningDialog();
          stopDialogTimer();
        }
      }
} // end of $.active check
};

from jquery-idletimeout.

rhetherington avatar rhetherington commented on July 2, 2024 1

from jquery-idletimeout.

JillElaine avatar JillElaine commented on July 2, 2024 1

Thanks for the feedback, feldenla. Glad it's working. And thanks for the suggestions & great code, rhetherington. For some time (years now), I wished I had the focus to fix up my plugin. I too want to combine the debugging & iframe scripts into one main, unminimized scripts. There are also a couple of bug fixes that need to be included. I am not able to do this work now, but perhaps in the future.

from jquery-idletimeout.

JillElaine avatar JillElaine commented on July 2, 2024

You will need to modify the code to check if there is an active AJAX request. Load the jquery-idleTimeout-for-testing.js script, https://github.com/JillElaine/jquery-idleTimeout/blob/master/jquery-idleTimeout-for-testing.js, on your page and watch the console (eg: use Firefox Developer Tools https://developer.mozilla.org/en-US/docs/Tools/Web_Console/Opening_the_Web_Console ) to see the output. This is very useful for debugging & understanding how the script works.

Next, modify the checkIdleTimeout function to include a test for active AJAX connections. The checkIdleTimeout function polls every idleCheckHeartbeat seconds. It opens the warning dialog when certain conditions are met. Set a 'condition' that there must be no active connections before the dialog opens. See untested, modified code below.

You'll probably want to 'comment out' many of the extra 'console.log' outputs to focus only on the outputs you care about.

 //----------- IDLE TIMER FUNCTIONS --------------//
    checkIdleTimeout = function () {

if ($.active > 0) { // start of $.active check
  console.log('ACTIVE connection! NO TIMEOUT YET!');
} else {
  console.log('NO active connections. Proceed to check other timeout conditions.');

      var timeIdleTimeout = (store.get('idleTimerLastActivity') + (currentConfig.idleTimeLimit * 1000));

      if ($.now() > timeIdleTimeout) {
        console.log('inactivity has exceeded the idleTimeLimit');

        if (!currentConfig.enableDialog) { // warning dialog is disabled
          console.log('warning dialog disabled - log out user without warning');
          logoutUser(); // immediately log out user when user is idle for idleTimeLimit
        } else if (currentConfig.enableDialog && isDialogOpen() !== true) {
          console.log('warning dialog is not open & will be opened');
          openWarningDialog();
          startDialogTimer(); // start timing the warning dialog
        }
      } else if (store.get('idleTimerLoggedOut') === true) { //a 'manual' user logout?
        console.log('user has manually logged out? Log out all windows & tabs now.');
        logoutUser();
      } else {
        console.log('inactivity has not yet exceeded the idleTimeLimit');

        if (currentConfig.enableDialog && isDialogOpen() === true) {
          console.log('warning dialog is open & will be closed');
          destroyWarningDialog();
          stopDialogTimer();
        }
      }
} // end of $.active check
};

Please report back. Thank you.

from jquery-idletimeout.

feldenla avatar feldenla commented on July 2, 2024

Great work and thanks a lot for your timely reply.

It is working somehow as expected, that is, it keeps on waiting while there is an active AJAX connection.
So the user is active until the AJAX request is complete, however the user is logged out immediately the AJAX connection is closed and logs the message 'inactivity has exceeded the idleTimeLimit'.

It is obvious here that;

if ($.now() > timeIdleTimeout) { // would always be true }

Can we therefore reset store.get('idleTimerLastActivity') to the current time if $.active > 0 and also stop pinging the server again to keep the session alive since there is an already active connection.

Your help would be greatly appreciated.
Thank you.

from jquery-idletimeout.

feldenla avatar feldenla commented on July 2, 2024

Thanks very much for your assistance.

It is now working to expectation.

from jquery-idletimeout.

rhetherington avatar rhetherington commented on July 2, 2024

from jquery-idletimeout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.