@mathquis/node-assistant-protocol
Version:
Assistant protocol decorator for Hermes protocol
19 lines • 552 B
JavaScript
module.exports = (hermes, logger) => {
return (topic, object) => {
return {
...object,
offsetVolume: async (siteId, offset) => {
offset = parseInt(offset)
if ( isNaN(offset) ) throw new Error('Invalid offset "' + offset + '"')
offset = Math.max(-100, Math.min(100, offset))
logger.debug('Offseting %s volume on site "%s" of %d', object.name, siteId, offset)
await hermes.publish(topic, hermes.serialize({
siteId, offset
}))
},
onOffsetVolume: (handler) => {
return hermes.on(topic, handler)
}
}
}
}