How to detect user inactivity using Angular 2? How to detect user inactivity using Angular 2? angular angular

How to detect user inactivity using Angular 2?


The easiest way will be to use idlejs.

It works well with Angular and it includes .d.ts bindings for Typescript.

import { Idle } from 'idlejs/dist';// with predefined events on `document`const idle = new Idle()  .whenNotInteractive()  .within(60)  .do(() => console.log('Logout user with a function'))  .start();

When a user is playing a video you can stop the idle.

play(){    this.idle.stop();    // play movie}

And when the user clicks pause / stop

pause(){    this.idle.restart();    // pause movie}