# idle.ts **Repository Path**: mirrors_dropbox/idle.ts ## Basic Information - **Project Name**: idle.ts - **Description**: A TypeScript library used to detect idle/active users. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-24 - **Last Updated**: 2026-02-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # idle.ts :running: -> :sleeping: -> :running: -> :running: -> :sleeping: idle.ts is a small typescript / javascript lib that helps you indicate whether a user is active or idle. You can use this to get events about the user activitness, and create your own actions - log activity, sign idle users out, show warning modal, etc. The library also offers smart batching with optimal balance between accuracy and effiency. ## Install `npm install idle.ts` Or copy idle.ts (for typescript) or idle.js (for javascript) to your location ## Testing Use attached Jasmine file for testing. ## Usage Start listening to user activity by calling `let idle = Idle(...)` ### Provide the following parameters to Idle(...) constructor: - `activityReportInSec?: number;` The number of seconds interval a report about user activity is sent. - `activityReportMode?: ReportMode` see [Smart Batching](https://github.com/dropbox/idle.ts/#smart-batching) - `detectFramesInSec?: number;` Frames can be added dynamicaly after the page was already created. If the page you inpect creates frames after loaded set the interval time, in which the dicovery frames code may run. By default, it only runs once the page is loaded - `onActivity?: ()=>void;` a event called when a user is starting to be active after being idle - `onEnterFrame?: ()=>void;` a event called when a user enters a frame and listener can't listen to any page event - `onReportUserIsActive?: ()=>void;` a periodic report states that the user was being active on the last interval checked. - `onReportUserIsIdle?: ()=>void;` a periodic report states that the user was being idle on the last interval checked. ## Smart Batching ### Batch Events in order to reduce load In order to reduce load on the server we don’t want to call the refresh cookie url, upon every event that we catch. We should check if the user made an activity over X minutes, and call the endpoint if he was active. So how do we set this X interval to the optimal time? - If we make it to long - we can lose events. A user can be active and close the browser / disconnect from the internet, before activity report was sent - If we make it too short we can overload the server ### Basic triggering - log every X minutes #### Outline send report every 5 minutes if user was active #### How? upon user activity - raise flag every 5 minutes - if flag is raised, call endpoint to refresh cookie. drop flag.