UNPKG

ambilight-provider

Version:

Ambilight-provider is a module, which when running, is generating a RGB integer array, representing the dominant color of the screen. The color is calculated every given Millisecond, based on the value given in the 'interval' parameter, in the start func

38 lines (33 loc) 981 B
var screenshot = require('desktop-screenshot'); var color = require('dominant-color') var fs = require('fs'); var timer var isRunning = false exports.start = (interval, callback) => { isRunning = true timer = setInterval(() => { screenshot("screenshot.png", function (error, complete) { color("screenshot.png", { format: 'rgb' }, (err, color) => { if (err) { console.log("Computer cant keep up with interval. Try increasing by 25ms") return } callback(color) }) }) }, interval) } exports.stop = () => { if (timer != null && isRunning) { clearInterval(timer) isRunning = false try { fs.unlinkSync("screenshot.png") } catch (err) { console.log("Couldn't delete screenshot\n" + err) } } } exports.isRunning = () => { return isRunning }