简体   繁体   English

如何检测反应 web 应用程序中的空闲时间?

[英]How to detect idle time in react web application?

I am developing a react web app that contains the functionality of idle time detection(small scale project).我正在开发一个反应 web 应用程序,其中包含空闲时间检测功能(小型项目)。 The app should detect the whole system's(OS) idle time.该应用程序应检测整个系统的(操作系统)空闲时间。 If the user closes the browser I mean not the case user idle for the app, but for the whole system/OS: no keyboard input, no mouse operation, no-touch even when no focus on the app or app is minimized.如果用户关闭浏览器,我的意思不是应用程序的用户空闲,而是整个系统/操作系统:没有键盘输入,没有鼠标操作,即使没有对应用程序或应用程序的关注最小化,也没有触摸。 Is there any way to implement this?有什么方法可以实现吗?

Here is an example project of implementing idle-timeout in React.这是一个在 React 中实现空闲超时的示例项目。 You can clone this project and run it on your machine.你可以克隆这个项目并在你的机器上运行它。

// clone the project
git clone https://github.com/bbachi/react-idle-timeout.git
// install dependencies and start the project
npm install
npm start

This is a simple project which has two screens: login screen and dashboard screen.这是一个简单的项目,它有两个屏幕:登录屏幕和仪表板屏幕。

When you log in with any username and password, dashboard displays with some user table.当您使用任何用户名和密码登录时,仪表板会显示一些用户表。 If you are idle for 5 seconds we are going to let the user know with a modal window and if the user is still idle after 5 seconds, the user will be logged out.如果您空闲 5 秒,我们将使用模态 window 让用户知道,如果用户在 5 秒后仍然空闲,则用户将被注销。

For details, this blog post seems to support the idea.有关详细信息, 此博客文章似乎支持该想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM