0

I am developing an application and looking for an event/method which gets called everytime irrespective of the user interaction or not with the application so that I can write my logic to render the timeout dialog. Can someone suggest me how this could be achieved in the app.component.ts.

anonymous function(){

//listen to any state of the application, be it user clicks, mouse move, ideal, keyboards events so that my function can be invoked.

PS:- idle package just works for ideal state with a timeout.

With the idle package you can just determine the idle state of the application but I am looking for something which can be executed irrespective of it.

DJ-
  • 119
  • 1
  • 4
  • 12
  • Try this https://www.npmjs.com/package/@ng-idle/core – Saurabh Agrawal Mar 01 '19 at 05:54
  • Possible duplicate of [How to give session idle timeout in angular 6?](https://stackoverflow.com/questions/54925361/how-to-give-session-idle-timeout-in-angular-6) – Nithya Rajan Mar 01 '19 at 05:58
  • possible duplicate of https://stackoverflow.com/questions/54925361/how-to-give-session-idle-timeout-in-angular-6/54925477#54925477. – Nithya Rajan Mar 01 '19 at 05:58
  • No , please read that I would like to execute my logic irrespective of whether user is ideal or not. I have already implemented the idle flow but it doesn't suffice my objective. – DJ- Mar 01 '19 at 05:59
  • @DJ-, Provide working example in stackblitz with the code that you have used.. – Maniraj Murugan Mar 01 '19 at 06:02
  • I am still trying to figure out a way that's what my question is how can i achieve it. Once I have it, i shall be able to provide it. – DJ- Mar 01 '19 at 06:05

1 Answers1

0

One approach can be like this, consider you have a variable appState in a service called appService. Create a directive and apply it on <app-component activeDirective></app-component>. This directive will listen for mouse movements, user click, keyboard click etc. If any of such things happen, change the appState to active.

In the same appService create a timer function. Let's say your idle time is 10s. See this answer. So every five second check the state of appState variable. If it's active make it idle. If it's idle perform your idle function flow.

emkay
  • 777
  • 8
  • 19
  • ok, thanks for your response, how do i listen to a mouse movements, user clicks keyboard etck, Appreciate if you can tell me the package or example to look through. – DJ- Mar 03 '19 at 09:30
  • Does anyone have any thoughts? – DJ- Mar 04 '19 at 06:02
  • 1
    Have you used HostListener before? If not you can see that for identifying button clicks, mouse movements. See this asnwer for example https://stackoverflow.com/questions/37362488/how-can-i-listen-for-keypress-event-on-the-whole-page/37363257 If you are stuck anywhere tell me. – emkay Mar 04 '19 at 15:22
  • Thanks, I think this helps in capturing me all the clicks on the application to track down which is good. However, just wondering if I had to determine the session idle should i go with Idle package. – DJ- Mar 12 '19 at 03:43