[英]How to detect user inactivity using Angular 2?
I am trying to create an Angular App which contains videos where the user needs to be logged out after a few minutes of inactivity. 我正在尝试创建一个Angular应用程序,其中包含用户需要在几分钟不活动后注销的视频。
If the user is watching the videos either normally or in fullscreen, he need not be logged out. 如果用户正常或全屏观看视频,则无需注销。
If the tab is inactive and the videos are playing I need him to be logged out after inactivity. 如果选项卡处于非活动状态且视频正在播放,我需要在不活动后将其注销。
The easiest way will be to use idlejs . 最简单的方法是使用idlejs 。
It works well with Angular and it includes .d.ts bindings for Typescript. 它适用于Angular,它包含了针对Typescript的.d.ts绑定。
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.