moribvndvs / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://moribvndvs.github.io/ng2-idle
Apache License 2.0
315 stars 128 forks source link

Idle time out is triggering when I called HTTP request and It shouldn't be #66

Open bhagath007 opened 6 years ago

bhagath007 commented 6 years ago

Hi,

I am using angular version 4.4.6 and latest ng-idle version.

For instance, I kept idle Timeout = 5sec and idle time = 5sec. So after 10 seconds of inactivity, I am getting logged out. It's working!

But when I called any HTTP request and if it takes more than 10sec to execute I am getting logged out but It shouldn't be.

Please help me out.

My ng-idle Functionality for your ref:-

constructor( private jhiLanguageHelper: JhiLanguageHelper, private loginService: LoginService, private principal: Principal, private router: Router, private idle: Idle, private keepalive: Keepalive, public dialog: MdDialog ) { this.timeOut = 5; this.idletime = 5; idle.setIdle(this.idletime); idle.setTimeout(this.timeOut); idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

    idle.onIdleEnd.subscribe(() => this.dialog.closeAll());
    idle.onTimeout.subscribe(() => this.logout());    
    idle.onTimeoutWarning.subscribe((countdown) => this.idlelogout(countdown));
    this.reset();
    this.isAuthenticated();
}

isAuthenticated() {
    if (this.principal.isAuthenticated()) {
        this.opened = true;
        $("#main_container").addClass('container-fluid maincontainer');
        $("#iceman").addClass('leftPadding');         
    } else {
        this.opened = false;
        $("#main_container").removeClass('container-fluid maincontainer');
        $("#iceman").removeClass('leftPadding');
    }
}

idlelogout(countdown){
       if (this.principal.isAuthenticated()) {         
        let dialogRef = this.dialog.open(DialogOverviewMainDialog, {
            width: '300px',
            data: { name: this.name, count: countdown, timeOutValue: (countdown/this.timeOut)*100}
        });
    }
}

logout() {
    if (this.principal.isAuthenticated()) {
        this.loginService.logout();
        this.router.navigate(['']);
        location.reload();
    } 
}

Thanks Bhagath

egarkavy commented 1 year ago

As I understand you want idle/timeout not to be called if the user idle but the request in progress. Here I recommend to create your own interrupt sources and specify your own interrupt event which will be called for instance each second while there is at least one active http request