alb3rt-home-security
Version:
41 lines (34 loc) • 1.03 kB
JavaScript
;
const FILE_ID = '[alb3rt-home-security/alert]',
core = require('alb3rt-core'),
player = core.player;
module.exports = new class HomeSecurityAlert {
constructor() {
this.loop = true;
}
play() {
console.log(FILE_ID, 'Playing alert sound!');
player.play('alert', './node_modules/alb3rt-home-security/alert/alert.mp3', () => {
if (this.loop) {
this.play();
} else {
console.log(FILE_ID, 'Stopping alert sound.');
player.stop('alert');
}
});
}
stop() {
console.log(FILE_ID, 'Request to stopping alert sound received...');
this.loop = false;
}
handle(data, response) {
if (data.action && data.action === 'play' || data.action === 'stop') {
this[data.action]();
core.api.responder.send(response, {
status: 200
});
} else {
core.api.responder.reject();
}
}
};