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

idleEnd is not called if user becomes idle while focus is in another window #53

Open arloduff opened 7 years ago

arloduff 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

Currently, if I allow the idle period to start while my focus is in another window (such as another application besides my browser), the idle period will not end when I return to the browser, click around with the mouse, type keys, etc. It works as expected only if the user becomes idle while focus is inside the window, which is not desired, since most users will become idle while in other windows.

Expected behavior

The idle period should end regardless of where the focus was when it began.

Minimal reproduction of the problem with instructions

Take appropriate steps to activate ng2idle in your application (such as logging in). Move the mouse to another window besides the browser and shift the focus there by clicking. Wait for your application to become idle. Move the mouse back into the application and click to move the focus back. Click or type keys to end the idle status. The application will not become active un-idle.

I'm using the following initialization: init () { let interruptSource: WindowInterruptSource = new WindowInterruptSource('mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll'); // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document this.idle.setInterrupts([interruptSource, new StorageInterruptSource()]);

// Subscribe to idle events. Add your logic on how the application should respond, such as displaying
this.keepalive.onPing.subscribe(() => {
  this.ngZone.run(() => {
      console.log("In keepalive ping");
  });
});
this.idle.onTimeout.subscribe(() => {
  this.ngZone.run(() => {
     console.log("The user would be logout now");
  });
});

// a warning dialog onIdleStart, or redirecting to logout page onTImeout, etc.
this.idle.onIdleStart.subscribe(() => {
  this.ngZone.run(() => {
    console.log('IdleStart');
  });
});
  this.idle.onTimeoutWarning.subscribe((countdown) => {
  this.ngZone.run(() => {
    console.log("Countdown", countdown);
  });
 });
this.idle.onIdleEnd.subscribe(() => {
  this.ngZone.run(() => {
     console.log("Idle ended");
 });
});

// start watching for idleness right away.
this.start();
}

start () {
this.ngZone.runOutsideAngular(() => {
  this.idle.watch();
});

}

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

Please tell us about your environment:

I'm using a Mac with Chrome, but have seen the same results on Browserstack emulating the Windows environment with both Chrome and Firefox.

EDIT: Seems related to https://github.com/HackedByChinese/ng2-idle/issues/40 - when not running this.idle.watch outside of ngZone, it seems to behave correctly - but then Protractor tests fail.

rajasekarsphcl commented 3 years ago

Facing same issue. Anyone looking into this issue ?