0

Please anyone help me to find whats wrong with the below code. checkInSessionTimout constructor being called at code-CreateObject but the variables values are not retaining at code-setInterval.

https://jsfiddle.net/y1f74tz8/2/

var _timer;
    function addIdleCheckInMethod() {
        var sessionTimeout = new checkInSessionTimout(); //**code-CreateObject**
        $(this).mousemove(sessionTimeout.resetTimer);
        $(this).keypress(sessionTimeout.resetTimer);
    
       /* _timer = setInterval(function () { sessionTimeout.checkIdleTime(onSessionExpire) }
                                , 1000);
        */

        _timer = setInterval(sessionTimeout.checkIdleTime //**code-setInterval**
                                , 1000, onSessionExpire);
    }
    function onSessionExpire() {
        clearInterval(_timer);
        var user = new user();
        
        console.log('session expired!');
    }
    
    class checkInSessionTimout {
        constructor(args){
            this.IDLE_TIMEOUT = args != null && args.idleTimout ? args.idleTimout : 30;
            this._idleSecondsCounter = 0;
            console.log('constructor');
        }
        checkIdleTime(callback) {
            this._idleSecondsCounter++;
            console.log( "idle timeout: " + this.IDLE_TIMEOUT + ' counter: ' + this._idleSecondsCounter);
            if (this._idleSecondsCounter >= this.IDLE_TIMEOUT) {
                callback();
            }
        }
        resetTimer() {
            this._idleSecondsCounter = 0;
            console.log('reset:' + this._idleSecondsCounter);
        }
    }

2
  • 1
    Hi! Please put your runnable example here, on-site using Stack Snippets (the [<>] toolbar button), not off-site. Here's how to do one. Three reasons: People shouldn't have to go off-site to help you; some sites are blocked for some users; and links rot, making the question and its answers useless to people in the future. Commented Aug 19, 2021 at 10:16
  • 1
    Please review the help center, in particular How do I ask a good question? I also recommend Jon Skeet's Writing the Perfect Question and Question Checklist. What specifically are you asking about? What variable? What value are you seeing? What value do you expect instead? Commented Aug 19, 2021 at 10:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.