{"id":19608593,"url":"https://github.com/teamwork/node-afk","last_synced_at":"2025-04-27T20:32:57.592Z","repository":{"id":14348945,"uuid":"17058532","full_name":"Teamwork/node-afk","owner":"Teamwork","description":"Away from keyboard!","archived":false,"fork":false,"pushed_at":"2018-09-06T17:48:08.000Z","size":1121,"stargazers_count":33,"open_issues_count":0,"forks_count":10,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-04-21T02:45:27.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.org/package/afk","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Teamwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-21T14:26:57.000Z","updated_at":"2025-04-20T22:47:59.000Z","dependencies_parsed_at":"2022-09-03T08:52:31.735Z","dependency_job_id":null,"html_url":"https://github.com/Teamwork/node-afk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teamwork%2Fnode-afk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teamwork%2Fnode-afk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teamwork%2Fnode-afk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teamwork%2Fnode-afk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Teamwork","download_url":"https://codeload.github.com/Teamwork/node-afk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251204680,"owners_count":21552266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T10:15:51.888Z","updated_at":"2025-04-27T20:32:57.311Z","avatar_url":"https://github.com/Teamwork.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-afk\n\nTrigger an action when the activity status of the user changes.\n\n## Prerequisites\n\n- Node.js \u003e= 8.0.0\n\n## Installation\n\n```sh\nnpm install afk\n```\n\nThis module uses a native module that needs to be built using `node-gyp`.\n\nOn linux you will need to install `libxss-dev` and `pkg-config` to ensure that the native module dependency can be built.\n\n## Usage\n\n```js\nconst NodeAFK = require('afk');\n\nconst inactivityDuration = 1000 * 10; // the user will be considered `idle` after 10 seconds\n\nconst afk = new NodeAFK(inactivityDuration);\n\nafk.init();\n\nafk.on('status:idle', () =\u003e {\n  // the status of the user changed from `active` to `idle`\n});\n\nafk.on('status:active', () =\u003e {\n  // the status of the user changed from `idle` to `active`\n})\n```\n\n`node-afk` is an event emitter and emits the following events:\n\n- `status:idle` - the status of the user changed from `active` to `idle`\n- `status:active` - the status of the user changed from `idle` to `active`\n- `status-changed` - the status of the user changed. An object is passed to the listener for this event containing details of the previous and current status.\n- `error` - an error occured\n\n```js\nafk.on('status-changed', ({ previousStatus, currentStatus }) =\u003e {\n  // `previousStatus` is the status of the user before their status changed\n  // `currentStatus` is the status of the user after their status changed\n})\n```\n\nYou can unregister a listener from an event using the `off` method of the event emitter:\n\n```js\nafk.off('status:idle', idleListener);\n```\n\nYou can also setup a listener that is executed when the status of the user has been their current status for a certain duration:\n\n```js\nafk.on('idle:5000', () =\u003e {\n  // the user has been `idle` for 5 seconds\n});\n\nafk.on('active:15000', () =\u003e {\n  // the user has been `active` for 15 seconds\n});\n```\n\nThese events will be emitted each time the status of the user is changed.\n\nIf an error occurs whilst trying to retrieve the idle time from the system an `error` event will be emitted:\n\n```js\nafk.on('error', (err) =\u003e {\n  // an error occurred\n});\n```\n\n## API\n\n### constructor(inactivityDuration, [pollInterval])\n\nCreate a new instance of `node-afk`\n\n- `inactivityDuration` - How long (in `ms`) until the user can be inactive until they are considered as `idle`\n- `pollInterval` - How often (in `ms`) should `node-afk`  query the system to get the the amount of time that the user has been away for (`1000ms` by default)\n\n### on(eventName, listener)\n\nRegister a listener on an event\n\n- `eventName` - `status:active`, `status:idle`, `status-changed`, `\u003cstatus\u003e:\u003ctime\u003e`, `error`\n- `listener` - Function to be executed when the event is emitted\n\n### off(eventName, listener)\n\nUnregister a listener from an event\n\n- `eventName` - The name of the event\n- `listener` - The listener associated with the event\n\n### init()\n\nInitalise the `node-afk` instance.\n\n**This is required to be called so that the poll interval is setup.**\n\n### destroy()\n\nStops the poll interval and removes all event listeners.\n\n## Contributing\n\nContributions are always welcome. Make sure you write tests for anything you add or change. We also enforce AirBNB ESLint rules.\n\n## License\n\n`MIT`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamwork%2Fnode-afk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteamwork%2Fnode-afk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamwork%2Fnode-afk/lists"}