[英]How to detect user inactivity using Angular 2?
我正在嘗試創建一個Angular應用程序,其中包含用戶需要在幾分鍾不活動后注銷的視頻。
如果用戶正常或全屏觀看視頻,則無需注銷。
如果選項卡處於非活動狀態且視頻正在播放,我需要在不活動后將其注銷。
最簡單的方法是使用idlejs 。
它適用於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();
當用戶正在播放視頻時,您可以停止空閑。
play(){
this.idle.stop();
// play movie
}
當用戶點擊暫停/停止時
pause(){
this.idle.restart();
// pause movie
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.