UNPKG

@lightninglabs/lnc-web

Version:

Lightning Node Connect npm module for web

77 lines 2.56 kB
import type SessionManager from './sessionManager'; type SessionManagerDependency = Pick<SessionManager, 'config' | 'sessionTimeRemaining' | 'refreshSession'>; /** * Monitors user activity and automatically extends sessions that are about to * expire. Activity events (clicks, key presses, mouse moves, etc.) are * throttled to avoid excessive updates, and the refresh timer is paused when * the page is hidden to conserve resources. */ export default class SessionRefreshManager { private sessionManager; private lastActivity; private refreshTimer?; private activityListeners; private activityThrottleTimer?; private isRunning; private config; private visibilityHandler?; private hasVisibilityListener; private consecutiveErrors; private isRefreshing; private refreshTriggerMs; constructor(sessionManager: SessionManagerDependency); /** * Start monitoring activity and schedule the refresh timer. */ start(): void; /** * Stop monitoring and clean up all listeners and timers. */ stop(): void; /** * Register DOM event listeners for user activity signals. */ private setupActivityMonitoring; /** * Create a throttled callback that updates the last-activity timestamp at * most once per {@link ACTIVITY_THROTTLE_MS} milliseconds. */ private createThrottledActivityUpdater; /** * Schedule the next refresh-condition check. */ private resumeRefreshTimer; /** * Pause the periodic refresh timer. */ private pauseRefreshTimer; /** * Evaluate whether the session should be refreshed based on recent user * activity and the time remaining until expiry. */ private checkAndRefreshSession; /** * Pause the timer when the page becomes hidden and resume when visible. */ private handleVisibilityChange; /** * Remove all timers and DOM event listeners. */ private cleanupTimersAndListeners; /** * Return the timestamp of the most recent user activity. */ getLastActivity(): number; /** * Return whether the refresh manager is currently running. */ isActive(): boolean; /** * Force an immediate refresh-condition check. Returns true if the manager is * still running after the check, or false if the manager was not running or * stopped itself due to repeated failures. */ forceRefreshCheck(): Promise<boolean>; } export {}; //# sourceMappingURL=sessionRefreshManager.d.ts.map