I've implemented a feature in my Angular app that redirects users to a screensaver page after 30 seconds of inactivity, using code I found here. The functionality works well, but I'm facing an issue where I don't want the redirection to occur on certain pages. Even when navigating away from a redirection-enabled page to one without redirection, the timer continues running. How can I disable it upon each navigation?
Here is a snippet of my code:
timeout;
...
resetTimer(endTime: number = this.endTime) {
const interval = 1000;
const duration = endTime * 60;
this.timerSubscription = timer(0, interval)
.pipe(take(duration))
.subscribe(
value => this.render((duration - +value) * interval),
err => {},
() => {
this.timeout = setTimeout(() => {
this.navCtrl.navigateRoot(URL_CONSTANT.SCREENSAVER, {
animated: false
}, 100);
});
}
);
}
...
ngOnDestroy() {
this.unsubscribe$.next();
this.unsubscribe$.complete();
clearTimeout(this.timeout);
}