How the ping mechanism works
mainThe ping interval allows you to perform periodic actions (like refreshing an authentication token) during the lifecycle between the user becoming idle and the timeout occurring.
Lifecycle Example:
If ping is 2m, idle is 10m, and timeout is 5m:
- User is active.
- At 10m (idle detected), the countdown timer starts.
- Every 2m (ping), an event is emitted.
- At 15m (total time), the timeout fires.
Timeline: |–– 2m (ping)––4m (ping) ––6m (ping)...-– 10m (user idle detected, start timer for 5 min) –- 12m (ping) –– 14m (ping) –– 15m (time is out)|
// Example: Refresh token every 2 minutes using ping
this.userIdle.ping$.subscribe(() => console.log("PING"));