@@ -22,6 +22,7 @@ import api from '@stackstorm/module-api';
22
22
import Link from '@stackstorm/module-router/link.component' ;
23
23
24
24
import componentStyle from './style.css' ;
25
+ const APPLICATION_INACTIVITY_TIME = 7200 ; // 2 hr time here it is in seconds
25
26
26
27
class Icon extends React . Component {
27
28
static propTypes = {
@@ -63,17 +64,42 @@ export default class Menu extends React.Component {
63
64
style : componentStyle ,
64
65
}
65
66
66
- componentDidMount ( ) {
67
+ componentDidMount ( ) {
68
+ this . idleLogout ( ) ;
67
69
window . addEventListener ( 'storage' , this . storageChange ( ) ) ;
68
- }
69
70
71
+ }
72
+
70
73
componentWillUnmount ( ) {
71
74
window . removeEventListener ( 'storage' , this . storageChange ( ) ) ;
72
75
}
73
76
74
77
docsLink = 'https://docs.stackstorm.com/'
75
78
supportLink = 'https://forum.stackstorm.com/'
76
79
80
+ idleLogout ( ) {
81
+ let t ;
82
+ window . onload = resetTimer ;
83
+ window . onmousemove = resetTimer ;
84
+ window . onmousedown = resetTimer ; // catches touchscreen presses as well
85
+ window . ontouchstart = resetTimer ; // catches touchscreen swipes as well
86
+ window . onclick = resetTimer ; // catches touchpad clicks as well
87
+ window . onkeydown = resetTimer ;
88
+ window . addEventListener ( 'scroll' , resetTimer , true ) ;
89
+
90
+ function logoutFunction ( ) {
91
+ // your logout code for too long inactivity goes here
92
+ api . disconnect ( ) ;
93
+ window . location . reload ( ) ;
94
+ }
95
+
96
+ function resetTimer ( ) {
97
+ window . clearTimeout ( t ) ;
98
+ const millisecondTime = window . st2constants . st2Config . application_inactivity_time * 1000 || APPLICATION_INACTIVITY_TIME * 1000 ;
99
+ t = window . setTimeout ( logoutFunction , millisecondTime ) ; // time is in milliseconds,application will logout after 2 hr. We can set whatever time we want.
100
+ }
101
+ }
102
+
77
103
storageChange ( ) {
78
104
window . addEventListener ( 'storage' , ( event ) => {
79
105
if ( event . key === 'logged_in' && ( event . oldValue !== event . newValue ) ) {
0 commit comments