Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
Trigger an action when the activity status of the user changes.
npm install afk
This module uses a native module that needs to be built using node-gyp
.
On linux you will need to install libxss-dev
and pkg-config
to ensure that the native module dependency can be built.
const NodeAFK = require('node-afk');
const inactivityDuration = 1000 * 10; // the user will be considered `idle` after 10 seconds
const afk = new NodeAFK(inactivityDuration);
afk.init();
afk.on('status:idle', () => {
// the status of the user changed from `active` to `idle`
});
afk.on('status:active', () => {
// the status of the user changed from `idle` to `active`
})
node-afk
is an event emitter and emits the following events:
status:idle
- the status of the user changed from active
to idle
status:active
- the status of the user changed from idle
to active
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.error
- an error occuredafk.on('status-changed', ({ previousStatus, currentStatus }) => {
// `previousStatus` is the status of the user before their status changed
// `currentStatus` is the status of the user after their status changed
})
You can unregister a listener from an event using the off
method of the event emitter:
afk.off('status:idle', idleListener);
You can also setup a listener that is executed when the status of the user has been their current status for a certain duration:
afk.on('idle:5000', () => {
// the user has been `idle` for 5 seconds
});
afk.on('active:15000', () => {
// the user has been `active` for 15 seconds
});
These events will be emitted each time the status of the user is changed.
If an error occurs whilst trying to retrieve the idle time from the system an error
event will be emitted:
afk.on('error', (err) => {
// an error occurred
});
Create a new instance of node-afk
inactivityDuration
- How long (in ms
) until the user can be inactive until they are considered as idle
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)Register a listener on an event
eventName
- status:active
, status:idle
, status-changed
, <status>:<time>
, error
listener
- Function to be executed when the event is emittedUnregister a listener from an event
eventName
- The name of the eventlistener
- The listener associated with the eventInitalise the node-afk
instance.
This is required to be called so that the poll interval is setup.
Stops the poll interval and removes all event listeners.
Contributions are always welcome. Make sure you write tests for anything you add or change. We also enforce AirBNB ESLint rules.
MIT
FAQs
Trigger an action when the activity status of the user changes
The npm package afk receives a total of 13 weekly downloads. As such, afk popularity was classified as not popular.
We found that afk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.