My goal is to maintain user session activity by implementing a system that locks an interactive session after 15 minutes of user inactivity (defined as no keyboard or mouse activity).
The information system will automatically lock the session if there is no user activity for 15 minutes.
I have come up with a solution using RxJS, but I'm open to suggestions for better or standard strategies.
In the example below, the server will be pinged every 60 seconds if there is any user activity.
const userActivityEvents = [
fromEvent(document, 'click'),
fromEvent(document, 'wheel'),
fromEvent(document, 'scroll'),
fromEvent(document, 'keypress'),
fromEvent(document, 'mousemove'),
fromEvent(document, 'touchmove'),
];
merge(...userActivityEvents).pipe(
throttleTime(60 * 1000),
switchMap(() => this.apiService.get('/api/auth/ping', new HttpParams(), new HttpHeaders({ignoreLoadingBar: ''})),
),
).subscribe({error: () => undefined});