orangehill / bootstrap-session-timeout

Session timeout and keep-alive control with a nice Bootstrap warning dialog.
MIT License
159 stars 110 forks source link

Keep Alive Not Running #27

Open yuginng opened 9 years ago

yuginng commented 9 years ago

Hi, Thanks for the excellent plugin. Keep alive does not seem to run even though these options were set: keepAlive: true, keepAliveInterval: 10000,

Adding a call to keepAlive() in the timeout function solved the problem:

function keepAlive() {
            if (!keepAlivePinged) {
                // Ping keepalive URL using (if provided) data and type from options
                $.ajax({
                    type: opt.ajaxType,
                    url: opt.keepAliveUrl,
                    data: opt.ajaxData
                });
                keepAlivePinged = true;
                setTimeout(function() {
                    keepAlivePinged = false;
            keepAlive(); // <-- added this line
                }, opt.keepAliveInterval);
            }
        }
toddca commented 8 years ago

I found the same issue when ignoreUserActivity === true it seems the keep alives only fire then when the user is active. Also. not sure of the point of the ignoreUserActivity === as whenever I attempt to do something with the dialog that is being displayed my activity dismisses it. Kind of pointless to offer up a couple of buttons for a user to take action if you dismiss the dialog before they can.

elSpanielo commented 8 years ago

If you want to keep the modal up on mouse move just remove these lines (starts at line 110ish):

// If they moved the mouse not only reset the counter
// but remove the modal too!
if ($('#session-timeout-dialog').length > 0 &&
    $('#session-timeout-dialog').data('bs.modal') &&
    $('#session-timeout-dialog').data('bs.modal').isShown) {
    // http://stackoverflow.com/questions/11519660/twitter-bootstrap-modal-backdrop-doesnt-disappear
    $('#session-timeout-dialog').modal('hide');
    $('body').removeClass('modal-open');
    $('div.modal-backdrop').remove();
}
steveandsten commented 8 years ago

Actually if you add the following code above this block (and prior to startSessionTimer();

if(e.type === 'mousemove' && $('div.modal-backdrop').length > 0) { return; }

This will ensure that mouse movements will not remove the existing modal window.