Alarm Manager
This module enables the web app to add alarms that will remain active even when the app is in the background.
Some web-ui features rely on triggering events at a specified time, e.g. parental control features. The UI app cannot use the standard javascript function setTimeout because the alarms must remain active even when the UI app is released. Therefore this module was added to the Senza platform in order to manage the alarms, i.e wake the UI if necessary by triggering the relevant event.
Modules
Classes
- AlarmManager
AlarmManager is a singleton class that manages the alarms in the application. It fires events whose types are the names of the alarms.
alarmManager ⇒ AlarmManager
AlarmManager
Returns: AlarmManager
- pointer to the AlarmManager singleton
Example
import { alarmManager } from "senza-sdk";
AlarmManager
AlarmManager is a singleton class that manages the alarms in the application. It fires events whose types are the names of the alarms.
Kind: global class
Emits: event:MyAlarm
alarmManager.addAlarm(alarmName, alarmTime, [data])
Set alarm to be fired at the specified time, even when ui is released.
Kind: instance method of AlarmManager
Param | Type | Description |
---|---|---|
alarmName | string | unique name for the alarm |
alarmTime | number | time for the alarm to be fired, represented by the number of milliseconds elapsed since the epoch |
[data] | string | data to be passed back when the alarm is fired |
alarmManager.deleteAlarm(alarmName)
Delete the specified alarm.
Kind: instance method of AlarmManager
Param | Type | Description |
---|---|---|
alarmName | string | name of alarm to be deleted |
alarmManager.deleteAllAlarms()
Delete all alarms.
Kind: instance method of AlarmManager
alarmManager.getActiveAlarms() ⇒ Promise
Promise
Async function that asks for all active alarms.
Kind: instance method of AlarmManager
Returns: Promise
- when resolved, returns an array of objects containing alarmName and alarmTime fields
Throws:
string
error string in case of an error
"MyAlarm"
Fired when time of 'MyAlarm' arrives.
Kind: event emitted by AlarmManager
Example
alarmManager.addEventListener("MyAlarm", (e) => {
console.log("alarm MyAlarm arrived with data", e.detail);
});
alarmManager.addAlarm("MyAlarm", Date.now() + 60*60*1000, "MyData");
Updated 5 months ago