-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_helper.js
36 lines (32 loc) · 928 Bytes
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Magic Mirror
* Node Helper: MMM-Vrr
*
* By Steven Zemelka <hello@klizzy.com>
* MIT Licensed.
*/
let NodeHelper = require("node_helper");
const request = require("request").defaults({ encoding: null });
module.exports = NodeHelper.create({
start: function () {
console.log("MMM-VRR Node-helper loaded!");
},
socketNotificationReceived: function (notification, imageUrl) {
if (notification === "MMM-VRR-SEND-IMAGE-URL") {
this.getImageAsBase64(imageUrl);
}
},
getImageAsBase64: function (imageUrl) {
let self = this;
request.get(imageUrl, function (error, response, body) {
let data;
if (!error && response.statusCode === 200) {
data =
"data:" +
response.headers["content-type"] +
";base64," +
Buffer.from(body).toString("base64");
self.sendSocketNotification("base64ImageReceived", data);
}
});
}
});