Methods
onIdle(callback) → {function}
Register a callback to be invoked when the device is detected as being idle.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
The function to call when the device is
detected as being idle |
Example
import Agent from '@meldcx/agent'
// or
const Agent = require('@meldcx/agent');
const agent = new Agent();
// using standard Promises
agent.onReadyAsync().then(() => {
agent.Idle.setIdlePeriod(30)
.then(() => {
const unsubscribe = agent.Idle.onIdle(isIdle => {
console.log(`The device ${
isIdle
? 'is'
: 'isn\'t'
} idle.`);
unsubscribe();
});
});
});
// using async/await
const listForIdle = async() => {
await agent.onReadyAsync();
await agent.Idle.setIdleTimeout(30);
const unsubscribe = agent.Idle.onIdle(isIdle => {
console.log(`The device ${
isIdle
? 'is'
: 'isn\'t'
} idle.`);
unsubscribe();
});
};
listForIdle();
(async) queryState(timeout) → {Boolean}
Query if the device has been idle for n number of seconds
Parameters:
Name | Type | Description |
---|---|---|
timeout |
Number |
The minimum of seconds the device must have been idle |
Example
import Agent from '@meldcx/agent'
// or
const Agent = require('@meldcx/agent');
const agent = new Agent();
// Has the device been idle for 30 seconds?
agent.queryState(30).then(isIdle => {
console.log(isIdle
? 'Whoah, yeah it has.'
: 'Nope, you are wiggling the mouse');
});
(async) setIdlePeriod(timeout)
Parameters:
Name | Type | Description |
---|---|---|
timeout |
Number |
The amount of time in seconds to wait before
regarding device as being idle |