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

onIdleEnd fails to trigger on second (and subsequent) visits to the view #32

Open santanu-biswas opened 7 years ago

santanu-biswas commented 7 years ago

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/HackedByChinese/ng2-idle/blob/master/CONTRIBUTING.md#getting-help

Current behavior I have two routes at app root level - login (LoginComponent) and content (ContentComponent).

Only content component has ng2-idle configured in its constructor.

On first entry/visit to content view everything works fine.

However, if I go to logout (or any other view) and come back to content, the interrupts are not detected by ng2-idle and onIdleStart gets triggered after the timeout period! Even after that no matter how much I click on the screen or scroll etc, the onIdleEnd event is not triggered and onIdleTimeout gets triggered. After that everything again starts works well.

Expected behavior

ng2-idle should work consistently on first visit or subsequent visits to the route

Minimal reproduction of the problem with instructions

Please visit the following Plunk to check the bug: https://plnkr.co/edit/OHhNJHYrmx0oWkIqYq7V?p=preview

What is the motivation / use case for changing the behavior?

Idle timeout is used only for protected content. It is never used for login page.

Please tell us about your environment:

OSx (macOS Sierra) VSCode NPM Node.js

guilhermejcgois commented 7 years ago

We have a similar problem here, some updates about that @santanu-biswas ? Did you solve it? How?

vincent-cm commented 7 years ago

Try following, this worked for me:

this.subscriptionOnIdleStart = this.idle.onIdleStart.subscribe(() => { this.idleState = 'You\'ve gone idle!'; Logger.log('onIdleStart') });

ngOnDestroy(): any { this.subscriptionOnIdleStart.unsubscribe(); }

rgoj commented 6 years ago

Adding this.idle.stop() to ngOnDestroy() worked for me (adding the unsubscribe didn't change anything), here's the original Plunker working fine after the addition of this.idle.stop():

https://plnkr.co/edit/WMHW9HJQq2CzYut0qXKo?p=preview

vd-nagarro commented 6 years ago

Still getting the same error ,, on next screen or route change,, the interrupts events are not working, didn't get any interrupt even if trying to call this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); and this cause idle to start subscribing and showing . Please comment @HackedByChinese @rgoj @vincent-cm

PappuSharma231092 commented 3 years ago

I had also faced the same issue when I was implementing it on my project, to resolve it, I removed "this.idle.watch();" from reset() function and place it below idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); inside constructor.