### Install Dev Dependencies Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Install development dependencies for the project. ```bash npm install ``` -------------------------------- ### Install ng2-idle Core Package Source: https://github.com/grbsk/ng2-idle/blob/master/README.md Install the core ng2-idle package using npm. This command installs the latest supported version for Angular. ```bash npm install --save @ng-idle/core ``` -------------------------------- ### Standalone Bootstrap with provideNgIdleKeepalive Source: https://context7.com/grbsk/ng2-idle/llms.txt For standalone Angular applications, use the functional provider helpers instead of NgModules. This example includes HTTP client and NgIdleKeepalive. ```typescript import { bootstrapApplication } from '@angular/platform-browser'; import { provideHttpClient } from '@angular/common/http'; import { provideNgIdleKeepalive } from '@ng-idle/keepalive'; import { AppComponent } from './app/app.component'; bootstrapApplication(AppComponent, { providers: [ provideHttpClient(), provideNgIdleKeepalive() // includes provideNgIdle() + Keepalive ] }); // If keepalive is not needed, use core-only: // import { provideNgIdle } from '@ng-idle/core'; // providers: [provideNgIdle()] ``` -------------------------------- ### Install Commitizen CLI Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Install the Commitizen CLI globally to use its interactive commit wizard. This tool helps in adhering to conventional commit message formats. ```bash npm install -g commitizen ``` -------------------------------- ### Configure Idle Service and Subscribe to Lifecycle Events Source: https://context7.com/grbsk/ng2-idle/llms.txt Inject the Idle service and configure its properties such as idle duration, timeout duration, and interrupt sources. Subscribe to lifecycle events to react to user activity changes. Call watch() to start the idle detection. ```typescript import { Component, OnInit } from '@angular/core'; import { Idle, DEFAULT_INTERRUPTSOURCES, AutoResume } from '@ng-idle/core'; import { Keepalive } from '@ng-idle/keepalive'; @Component({ selector: 'app-root', templateUrl: './app.component.html' }) export class AppComponent implements OnInit { idleState = 'Not started'; timedOut = false; lastPing?: Date; constructor(private idle: Idle, private keepalive: Keepalive) {} ngOnInit(): void { // Seconds of inactivity before entering idle state (default: 1200) this.idle.setIdle(600); // 10 minutes // Seconds to count down after idle before firing onTimeout (default: 30) this.idle.setTimeout(30); // Use default interrupt sources: mouse, keyboard, touch, scroll, storage this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); // Resume watch automatically when the user is idle (default) this.idle.setAutoResume(AutoResume.notIdle); // --- Lifecycle event subscriptions --- // Fired when the user transitions from active → idle this.idle.onIdleStart.subscribe(() => { this.idleState = 'You have gone idle!'; console.log('User is now idle'); }); // Fired when the user returns to active from idle (interrupt occurred) this.idle.onIdleEnd.subscribe(() => { this.idleState = 'No longer idle.'; console.log('User is active again'); }); // Fired every second during the timeout countdown; countdown = seconds remaining this.idle.onTimeoutWarning.subscribe((countdown: number) => { this.idleState = `You will time out in ${countdown} seconds!`; }); // Fired when the countdown reaches zero — user has timed out this.idle.onTimeout.subscribe(() => { this.timedOut = true; this.idleState = 'Timed out!'; console.log('Session timed out'); // Typically: log the user out, redirect to login page, etc. }); // Fired on every interrupt event (useful for debugging) this.idle.onInterrupt.subscribe((event: any) => { console.log('Interrupt detected:', event?.type); }); // Start watching this.idle.watch(); } reset(): void { this.timedOut = false; this.idleState = 'Active'; this.idle.watch(); // restart the idle watch } } ``` -------------------------------- ### Custom IdleExpiry Implementation with Cookie Expiry Source: https://context7.com/grbsk/ng2-idle/llms.txt Extend IdleExpiry to create custom expiry stores, such as using cookies. This example demonstrates a CookieExpiry class that manages expiry timestamps via document.cookie. ```typescript import { Injectable } from '@angular/core'; import { IdleExpiry } from '@ng-idle/core'; @Injectable() export class CookieExpiry extends IdleExpiry { last(value?: Date): Date { if (value !== undefined) { if (value) { document.cookie = `idle_expiry=${value.getTime()};path=/`; } else { document.cookie = 'idle_expiry=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/'; } } const match = document.cookie.match(/idle_expiry=(\d+)/); return match ? new Date(parseInt(match[1], 10)) : null; } } // Register in your module: // providers: [CookieExpiry, { provide: IdleExpiry, useExisting: CookieExpiry }] ``` -------------------------------- ### Revert Commit Message Format Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Commits that revert a previous commit should start with 'revert:' followed by the header of the reverted commit. The body must specify the SHA of the reverted commit. ```text revert:
This reverts commit ``` -------------------------------- ### Keepalive Service Configuration and Usage Source: https://context7.com/grbsk/ng2-idle/llms.txt Configure the Keepalive service to ping an HTTP endpoint at intervals while the user is active. It automatically pauses when the user goes idle and resumes upon their return. This example shows basic configuration and event subscription. ```typescript import { Component, OnInit } from '@angular/core'; import { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core'; import { Keepalive } from '@ng-idle/keepalive'; import { HttpRequest } from '@angular/common/http'; @Component({ selector: 'app-root', template: '' }) export class AppComponent implements OnInit { lastPing?: Date; constructor(private idle: Idle, private keepalive: Keepalive) {} ngOnInit(): void { // Configure keepalive this.keepalive.interval(60); // ping every 60 seconds this.keepalive.request('/api/session/ping'); // simple GET // Or use a full HttpRequest for POST with auth header: // this.keepalive.request( // new HttpRequest('POST', '/api/session/ping', null, { // headers: new HttpHeaders({ Authorization: 'Bearer token' }) // }) // ); // React to ping events this.keepalive.onPing.subscribe(() => { console.log('Keepalive ping fired at', new Date()); }); this.keepalive.onPingResponse.subscribe(response => { this.lastPing = new Date(); console.log('Ping response status:', response?.status); }); // Configure idle this.idle.setIdle(600); this.idle.setTimeout(30); this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); // Idle automatically starts/stops keepalive as user goes idle/active this.idle.watch(); } manualPing(): void { this.keepalive.ping(); // fire a single ping immediately } } ``` -------------------------------- ### Manually Control Keepalive Start and Stop Source: https://context7.com/grbsk/ng2-idle/llms.txt Manually start or stop the keepalive service. Check if the keepalive service is currently running. ```typescript // Manually control the interval this.keepalive.start(); console.log(this.keepalive.isRunning()); // true this.keepalive.stop(); console.log(this.keepalive.isRunning()); // false ``` -------------------------------- ### Control Idle Watching State Source: https://context7.com/grbsk/ng2-idle/llms.txt Use `watch()` to start or reset the idle timer. `stop()` halts all timers. `isRunning()` and `isIdling()` check the current state. ```typescript this.idle.watch(); console.log(this.idle.isRunning()); // true console.log(this.idle.isIdling()); // false ``` ```typescript this.idle.watch(true /* skipExpiry */); ``` ```typescript this.idle.stop(); console.log(this.idle.isRunning()); // false ``` -------------------------------- ### Idle.watch() / stop() / isRunning() / isIdling() Source: https://context7.com/grbsk/ng2-idle/llms.txt These methods control the active watching state of the idle timer. `watch()` starts or resets the timer, `stop()` halts all timers, `isRunning()` checks if the timer is active, and `isIdling()` checks if the user is currently considered idle. ```APIDOC ## Idle.watch() / stop() / isRunning() / isIdling() ### Description Controls the active watching state. `watch()` starts (or resets) the idle timer. `stop()` halts all timers and clears the expiry entry from storage. ### Methods - `watch()`: Starts or resets the idle timer. Accepts an optional boolean `skipExpiry` argument (defaults to `false`) to prevent writing a new expiry value. - `stop()`: Halts all timers and clears the expiry entry from storage. - `isRunning()`: Returns `true` if the idle timer is currently running, `false` otherwise. - `isIdling()`: Returns `true` if the user is currently considered idle, `false` otherwise. ### Request Example ```typescript // Start watching — also resets the timer if already running this.idle.watch(); console.log(this.idle.isRunning()); // true console.log(this.idle.isIdling()); // false // Force a watch-reset without writing a new expiry value (used internally on interrupt) this.idle.watch(true /* skipExpiry */); // Stop watching entirely this.idle.stop(); console.log(this.idle.isRunning()); // false ``` ``` -------------------------------- ### Keepalive Service API Source: https://context7.com/grbsk/ng2-idle/llms.txt Control and configure the Keepalive service for periodic server pinging. You can set the request endpoint, adjust the interval between pings, and manually start or stop the keepalive mechanism. ```APIDOC ## Keepalive.request() / interval() / start() / stop() / isRunning() Configuration and control API for the `Keepalive` service when used independently of `Idle`. ```typescript import { Keepalive } from '@ng-idle/keepalive'; // Set endpoint (string shorthand for GET) this.keepalive.request('/api/heartbeat'); console.log(this.keepalive.request()); // HttpRequest { method: 'GET', url: '/api/heartbeat' } // Clear endpoint (ping event still fires, but no HTTP call is made) this.keepalive.request(null); // Set interval in seconds (must be > 0; default: 600) this.keepalive.interval(120); console.log(this.keepalive.interval()); // 120 // Manually control the interval this.keepalive.start(); console.log(this.keepalive.isRunning()); // true this.keepalive.stop(); console.log(this.keepalive.isRunning()); // false ``` ``` -------------------------------- ### Custom Keepalive Service Implementation Source: https://context7.com/grbsk/ng2-idle/llms.txt Implement the `KeepaliveSvc` abstract class from `@ng-idle/core` to create a custom keepalive strategy. This allows `Idle` to control your custom keepalive mechanism without relying on the default `@ng-idle/keepalive` implementation, for example, using WebSockets. ```APIDOC ## KeepaliveSvc (abstract base — custom implementation) Implement `KeepaliveSvc` from `@ng-idle/core` to create a custom keepalive strategy that `Idle` can control without depending on `@ng-idle/keepalive`. ```typescript import { Injectable } from '@angular/core'; import { KeepaliveSvc } from '@ng-idle/core'; import { WebSocketService } from './websocket.service'; // hypothetical @Injectable() export class WsKeepaliveSvc extends KeepaliveSvc { constructor(private ws: WebSocketService) { super(); } start(): void { this.ws.startHeartbeat(30); } stop(): void { this.ws.stopHeartbeat(); } ping(): void { this.ws.sendPing(); } } // Register in module: // providers: [WsKeepaliveSvc, { provide: KeepaliveSvc, useExisting: WsKeepaliveSvc }] ``` ``` -------------------------------- ### Run Release Task Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Execute the release script, which will prompt for NPM OTP to publish core and keepalive packages. ```bash npm run release ``` -------------------------------- ### Run Tests Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Execute the test suite to ensure all tests pass. ```bash npm test ``` -------------------------------- ### Continuously Run Tests for Core Module Source: https://github.com/grbsk/ng2-idle/blob/master/README.md Continuously runs tests for the 'core' module while you make changes. Ensure 'core' is built first if making changes to it. ```bash npm run ng test core ``` -------------------------------- ### Continuously Run Tests for Keepalive Module Source: https://github.com/grbsk/ng2-idle/blob/master/README.md Continuously runs tests for the 'keepalive' module while you make changes. Ensure 'core' is built first as Keepalive depends on it. ```bash npm run ng test keepalive ``` -------------------------------- ### Create a New Branch Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Create a new branch for your changes, based on the master branch. ```bash npm checkout -b my-fix master ``` -------------------------------- ### IdleExpiry (abstract base class) Source: https://context7.com/grbsk/ng2-idle/llms.txt An abstract base class for implementing custom expiry stores, allowing developers to extend `IdleExpiry` for custom persistence mechanisms like cookies or server-side sessions. ```APIDOC ## IdleExpiry (abstract base class) Extend `IdleExpiry` to implement a custom expiry store (e.g., cookies, server-side session). ```typescript import { Injectable } from '@angular/core'; import { IdleExpiry } from '@ng-idle/core'; @Injectable() export class CookieExpiry extends IdleExpiry { last(value?: Date): Date { if (value !== undefined) { if (value) { document.cookie = `idle_expiry=${value.getTime()};path=/`; } else { document.cookie = 'idle_expiry=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/'; } } const match = document.cookie.match(/idle_expiry=(\d+)/); return match ? new Date(parseInt(match[1], 10)) : null; } } // Register in your module: // providers: [CookieExpiry, { provide: IdleExpiry, useExisting: CookieExpiry }] ``` ``` -------------------------------- ### SimpleExpiry Source: https://context7.com/grbsk/ng2-idle/llms.txt An alternative in-memory-only `IdleExpiry` implementation that does not interact with `localStorage`, thus not coordinating activity between browser tabs. ```APIDOC ## SimpleExpiry An alternative in-memory-only `IdleExpiry` implementation. Does not write to `localStorage`, so it does not coordinate activity between browser tabs or windows. ```typescript import { NgModule } from '@angular/core'; import { NgIdleModule, IdleExpiry, SimpleExpiry } from '@ng-idle/core'; @NgModule({ imports: [NgIdleModule.forRoot()], providers: [ SimpleExpiry, { provide: IdleExpiry, useExisting: SimpleExpiry } // override default LocalStorageExpiry ] }) export class AppModule {} ``` ``` -------------------------------- ### DEFAULT_INTERRUPTSOURCES / createDefaultInterruptSources() Source: https://context7.com/grbsk/ng2-idle/llms.txt Provides pre-built configurations for common browser interrupt sources. `DEFAULT_INTERRUPTSOURCES` is a static array, while `createDefaultInterruptSources()` generates a new set with optional throttle and passive listener configurations. ```APIDOC ## DEFAULT_INTERRUPTSOURCES / createDefaultInterruptSources() ### Description A pre-built array of interrupt sources covering the common browser input events. `createDefaultInterruptSources(options?)` creates a fresh set with optional throttle/passive configuration. ### Usage - `DEFAULT_INTERRUPTSOURCES`: A shared static array of default interrupt sources. - `createDefaultInterruptSources(options?)`: Creates a new set of interrupt sources with configurable options. - `options.passive` (boolean): Whether to use passive event listeners (defaults to `false`). - `options.throttleDelay` (number): The delay in milliseconds for throttling events (defaults to `500`). ### Request Example ```typescript import { DEFAULT_INTERRUPTSOURCES, createDefaultInterruptSources } from '@ng-idle/core'; // Reuse the shared static array (default throttle: 500 ms, passive: false) this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); // Create a new set with passive event listeners and a 100 ms throttle const passiveSources = createDefaultInterruptSources({ passive: true, throttleDelay: 100 }); this.idle.setInterrupts(passiveSources); // Events monitored by DocumentInterruptSource: // 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll' // StorageInterruptSource listens to the Window 'storage' event (for cross-tab coordination) ``` ``` -------------------------------- ### Lint and Fix Code Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Run the linter to check for code style issues and automatically fix most warnings. ```bash npm run lint ``` ```bash npm run lint:fix ``` -------------------------------- ### Configure Default Interrupt Sources Source: https://context7.com/grbsk/ng2-idle/llms.txt Use `DEFAULT_INTERRUPTSOURCES` or `createDefaultInterruptSources()` to set up common browser input event listeners. `createDefaultInterruptSources` allows custom throttle/passive options. ```typescript import { DEFAULT_INTERRUPTSOURCES, createDefaultInterruptSources } from '@ng-idle/core'; // Reuse the shared static array (default throttle: 500 ms, passive: false) this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); ``` ```typescript // Create a new set with passive event listeners and a 100 ms throttle const passiveSources = createDefaultInterruptSources({ passive: true, throttleDelay: 100 }); this.idle.setInterrupts(passiveSources); // Events monitored by DocumentInterruptSource: // 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll' // StorageInterruptSource listens to the Window 'storage' event (for cross-tab coordination) ``` -------------------------------- ### Module-based Bootstrap with NgIdleKeepaliveModule Source: https://context7.com/grbsk/ng2-idle/llms.txt Register NgIdleModule (with optional NgIdleKeepaliveModule) once at the root of your application using forRoot(). This includes Idle, Keepalive, and LocalStorageExpiry. ```typescript import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule } from '@angular/common/http'; import { NgIdleKeepaliveModule } from '@ng-idle/keepalive'; // includes @ng-idle/core import { AppComponent } from './app.component'; @NgModule({ declarations: [AppComponent], imports: [ BrowserModule, HttpClientModule, NgIdleKeepaliveModule.forRoot() // registers Idle, Keepalive, LocalStorageExpiry ], bootstrap: [AppComponent] }) export class AppModule {} ``` -------------------------------- ### Idle.setTimeout(seconds | false) Source: https://context7.com/grbsk/ng2-idle/llms.txt Sets the timeout countdown in seconds that begins after the user enters the idle state. Setting this to `false` or `0` disables the timeout feature, meaning the idle state is entered but never times out automatically. ```APIDOC ## Idle.setTimeout(seconds | false) Sets the timeout countdown (in seconds) that begins after the user enters the idle state. Pass `false` or `0` to disable the timeout feature entirely. ### Parameters - **seconds** (number | false) - The number of seconds for the timeout countdown, or `false` to disable. ### Example ```typescript this.idle.setTimeout(60); // Warns for 60 seconds, then fires onTimeout. this.idle.setTimeout(false); // Disables timeout; only idle detection occurs. console.log(this.idle.getTimeout()); // Returns 60 or 0 ``` ``` -------------------------------- ### Idle Service Configuration and Lifecycle Events Source: https://context7.com/grbsk/ng2-idle/llms.txt The Idle service is the central API for managing user inactivity. It allows configuration of idle thresholds and interrupt sources, and provides event emitters for lifecycle events. ```APIDOC ## Idle Service — Configuration & Lifecycle Events The `Idle` service is the central API. Inject it, configure thresholds and interrupt sources, then subscribe to its event emitters before calling `watch()`. ### Lifecycle Event Subscriptions: - **onIdleStart**: Fired when the user transitions from active to idle. - **onIdleEnd**: Fired when the user returns to active from idle (an interrupt occurred). - **onTimeoutWarning**: Fired every second during the timeout countdown. - **onTimeout**: Fired when the countdown reaches zero, indicating the user has timed out. - **onInterrupt**: Fired on every interrupt event (useful for debugging). ### Starting the Watcher: - **watch()**: Starts the idle timer and begins watching for interrupt events. ``` -------------------------------- ### Configure Server-Side Rendering (SSR) Compatibility Source: https://context7.com/grbsk/ng2-idle/llms.txt Ensure `EventTargetInterruptSource` subclasses skip browser-specific initialization when running under Angular Universal using `isPlatformServer`. No extra configuration is required. ```typescript // app.module.server.ts (Universal) import { NgModule } from '@angular/core'; import { ServerModule } from '@angular/platform-server'; import { NgIdleModule } from '@ng-idle/core'; import { AppModule } from './app.module'; import { AppComponent } from './app/app.component'; @NgModule({ imports: [ AppModule, ServerModule, NgIdleModule.forRoot() // safe — interrupt sources skip init on server ], bootstrap: [AppComponent] }) export class AppServerModule {} // In a component running on the server, idle.watch() can be called safely: // - DocumentInterruptSource, WindowInterruptSource, StorageInterruptSource // all check isPlatformServer() and skip addEventListener calls. // - onIdleStart / onTimeout events will never fire server-side. ``` -------------------------------- ### Idle.setIdleName(key) Source: https://context7.com/grbsk/ng2-idle/llms.txt Assigns a unique name to an `Idle` instance, which is used to create a distinct `localStorage` key for storing the idle expiry time. This is crucial when running multiple independent `Idle` instances to prevent key collisions. ```APIDOC ## Idle.setIdleName(key) ### Description When running multiple independent `Idle` instances (e.g., scoped to different components or elements), each must have a unique name to avoid colliding on the same `localStorage` key. ### Parameters - `key` (string): A unique name for this `Idle` instance. ### Request Example ```typescript // In a feature module with its own injector scope: const idleA = injector.get(Idle); idleA.setIdleName('featureA'); // localStorage key: ng2Idle.featureA.expiry const idleB = anotherInjector.get(Idle); idleB.setIdleName('featureB'); // localStorage key: ng2Idle.featureB.expiry idleA.watch(); idleB.watch(); ``` ``` -------------------------------- ### Pull Latest Changes Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Ensure you have the latest changes from the master branch before releasing. ```bash git checkout master && git pull ``` -------------------------------- ### LocalStorageExpiry Source: https://context7.com/grbsk/ng2-idle/llms.txt The default `IdleExpiry` implementation that persists the expiry timestamp and idling status to `localStorage`, enabling cross-tab idle synchronization. ```APIDOC ## LocalStorageExpiry The default `IdleExpiry` implementation. Persists the expiry timestamp and idling flag to `localStorage` (falls back to an in-memory store in private-browsing environments). Enables cross-tab idle synchronization when paired with `StorageInterruptSource`. ```typescript import { Idle } from '@ng-idle/core'; import { LocalStorageExpiry } from '@ng-idle/core'; // LocalStorageExpiry is provided automatically via NgIdleModule / provideNgIdle() // Access the localStorage keys directly (for debugging): // ng2Idle.main.expiry → Unix timestamp (ms) of when the session expires // ng2Idle.main.idling → 'true' | 'false' // With a custom idle name: this.idle.setIdleName('dashboard'); // Keys become: ng2Idle.dashboard.expiry, ng2Idle.dashboard.idling ``` ``` -------------------------------- ### StorageInterruptSource Source: https://context7.com/grbsk/ng2-idle/llms.txt Listens for the `storage` event on `window` to coordinate activity across different tabs or windows of the same application, especially when paired with `LocalStorageExpiry`. ```APIDOC ## StorageInterruptSource Listens for the `storage` event on `window` and passes through only events whose key matches the `ng2Idle.*.expiry` pattern — enabling cross-tab activity coordination with `LocalStorageExpiry`. ```typescript import { StorageInterruptSource } from '@ng-idle/core'; const storageSource = new StorageInterruptSource({ throttleDelay: 500 }); this.idle.setInterrupts([storageSource]); // Activity in any other tab/window of the same app resets the idle timer here too ``` ``` -------------------------------- ### Configure Auto-Resume Behavior Source: https://context7.com/grbsk/ng2-idle/llms.txt Use `setAutoResume()` with the `AutoResume` enum to control if the idle watch restarts automatically when the user is already idle. Requires importing `Idle` and `AutoResume`. ```typescript import { Idle, AutoResume } from '@ng-idle/core'; this.idle.setAutoResume(AutoResume.idle); // (default) resume even if already idle this.idle.setAutoResume(AutoResume.notIdle); // only resume if NOT yet idle this.idle.setAutoResume(AutoResume.disabled); // never auto-resume — must call watch() manually console.log(this.idle.getAutoResume()); // AutoResume.notIdle (1) ``` -------------------------------- ### WindowInterruptSource Source: https://context7.com/grbsk/ng2-idle/llms.txt Listens for events on the global `window` object to detect user activity like focus changes or clicks, which can be used to reset the idle timer. ```APIDOC ## WindowInterruptSource Listens for events on the global `window` object. ```typescript import { WindowInterruptSource } from '@ng-idle/core'; // Detect focus/blur to reset idle on window regain-focus const winSource = new WindowInterruptSource('focus click'); this.idle.setInterrupts([winSource]); ``` ``` -------------------------------- ### Listen for Document Events with Filtering Source: https://context7.com/grbsk/ng2-idle/llms.txt Use `DocumentInterruptSource` to listen for events on `document.documentElement`. It automatically filters zero-movement `mousemove` events. ```typescript import { DocumentInterruptSource } from '@ng-idle/core'; // Custom event set on document const docSource = new DocumentInterruptSource( 'mousemove keydown mousedown touchstart scroll', { throttleDelay: 300 } ); this.idle.setInterrupts([docSource]); ``` -------------------------------- ### Idle.setIdle(seconds) Source: https://context7.com/grbsk/ng2-idle/llms.txt Sets the number of seconds of inactivity that must elapse before the user is considered idle and the `onIdleStart` event fires. This value must be greater than zero. ```APIDOC ## Idle.setIdle(seconds) Sets the number of seconds of inactivity that must elapse before the user is considered idle and `onIdleStart` fires. Must be greater than zero. ### Parameters - **seconds** (number) - The number of seconds of inactivity. ### Example ```typescript this.idle.setIdle(300); // User becomes idle after 5 minutes of inactivity console.log(this.idle.getIdle()); // Returns 300 ``` ``` -------------------------------- ### SimpleExpiry for In-Memory Idle Management Source: https://context7.com/grbsk/ng2-idle/llms.txt SimpleExpiry is an in-memory-only IdleExpiry implementation that does not coordinate activity between browser tabs or windows. It can be used to override the default LocalStorageExpiry. ```typescript import { NgModule } from '@angular/core'; import { NgIdleModule, IdleExpiry, SimpleExpiry } from '@ng-idle/core'; @NgModule({ imports: [NgIdleModule.forRoot()], providers: [ SimpleExpiry, { provide: IdleExpiry, useExisting: SimpleExpiry } // override default LocalStorageExpiry ] }) export class AppModule {} ``` -------------------------------- ### EventTargetInterruptSource Source: https://context7.com/grbsk/ng2-idle/llms.txt The base class for creating custom interrupt sources. It accepts an `EventTarget`, a string of space-separated event names, and optional throttle/passive options. It also supports Server-Side Rendering (SSR) by skipping initialization on the server. ```APIDOC ## EventTargetInterruptSource ### Description The base class for all built-in interrupt sources. Accepts any `EventTarget` (DOM element, window, etc.), a space-separated event string, and optional throttle/passive options. Supports SSR: skips initialization when running on the server. ### Constructor `new EventTargetInterruptSource(eventTarget: EventTarget, events: string, options?: { throttleDelay?: number, passive?: boolean }): EventTargetInterruptSource` ### Methods - `filterEvent(event: Event): boolean`: Protected method to filter events. Return `true` to prevent the event from triggering an interrupt. ### Request Example ```typescript import { EventTargetInterruptSource } from '@ng-idle/core'; // Listen for clicks and keypresses on a specific form element const formEl = document.getElementById('main-form'); const formSource = new EventTargetInterruptSource( formEl, 'click keydown', { throttleDelay: 200, passive: true } ); this.idle.setInterrupts([formSource]); // Custom subclass that filters specific events class CustomInterruptSource extends EventTargetInterruptSource { constructor() { super(() => document.documentElement, 'mousemove keydown'); } protected filterEvent(event: Event): boolean { // Suppress mousemove events from programmatic sources if (event.type === 'mousemove' && !(event as MouseEvent).isTrusted) { return true; // filtered — does NOT trigger an interrupt } return false; } } this.idle.setInterrupts([new CustomInterruptSource()]); ``` ``` -------------------------------- ### Idle.setInterrupts(sources) / clearInterrupts() Source: https://context7.com/grbsk/ng2-idle/llms.txt Registers an array of `InterruptSource` instances that define user actions which reset the idle timer. `clearInterrupts()` removes all registered sources. ```APIDOC ## Idle.setInterrupts(sources) / clearInterrupts() Registers an array of `InterruptSource` instances that define what user actions reset the idle timer. Call `clearInterrupts()` to remove all registered sources. ### Parameters - **sources** (Array) - An array of interrupt source configurations. ### Example ```typescript import { DEFAULT_INTERRUPTSOURCES, createDefaultInterruptSources } from '@ng-idle/core'; // Option 1: Use the pre-built default set (mouse, keyboard, touch, scroll, storage) this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); // Option 2: Default set with passive listeners and custom throttle this.idle.setInterrupts( createDefaultInterruptSources({ passive: true, throttleDelay: 250 }) ); // Option 3: Define custom sources this.idle.setInterrupts([ new DocumentInterruptSource('keydown mousedown touchstart'), new StorageInterruptSource() ]); // Remove all interrupt sources this.idle.clearInterrupts(); ``` ``` -------------------------------- ### Update Outdated Pull Request Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md Rebase and force push changes to update an out-of-date pull request. ```bash git fetch upstream git checkout master git merge upstream/master git checkout my-fix git rebase master -i git push origin my-fix -f ``` -------------------------------- ### Set Idle Duration Source: https://context7.com/grbsk/ng2-idle/llms.txt Configures the number of seconds of inactivity before the user is considered idle and the `onIdleStart` event fires. This value must be greater than zero. ```typescript import { Idle } from '@ng-idle/core'; // In a component or service constructor: constructor(private idle: Idle) { this.idle.setIdle(300); // 5 minutes → user becomes idle console.log(this.idle.getIdle()); // 300 } ``` -------------------------------- ### Conventional Commit Message Format Source: https://github.com/grbsk/ng2-idle/blob/master/CONTRIBUTING.md The standard format for commit messages includes a header (type, scope, subject), an optional body, and an optional footer. Each line should not exceed 100 characters. ```text ():