@@ -22,6 +22,7 @@ import api from '@stackstorm/module-api';
2222import Link from '@stackstorm/module-router/link.component' ;
2323
2424import componentStyle from './style.css' ;
25+ const APPLICATION_INACTIVITY_TIME = 7200 ; // 2 hr time here it is in seconds
2526
2627class Icon extends React . Component {
2728 static propTypes = {
@@ -63,17 +64,42 @@ export default class Menu extends React.Component {
6364 style : componentStyle ,
6465 }
6566
66- componentDidMount ( ) {
67+ componentDidMount ( ) {
68+ this . idleLogout ( ) ;
6769 window . addEventListener ( 'storage' , this . storageChange ( ) ) ;
68- }
6970
71+ }
72+
7073 componentWillUnmount ( ) {
7174 window . removeEventListener ( 'storage' , this . storageChange ( ) ) ;
7275 }
7376
7477 docsLink = 'https://docs.stackstorm.com/'
7578 supportLink = 'https://forum.stackstorm.com/'
7679
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+
77103 storageChange ( ) {
78104 window . addEventListener ( 'storage' , ( event ) => {
79105 if ( event . key === 'logged_in' && ( event . oldValue !== event . newValue ) ) {
0 commit comments