mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
30 lines
775 B
JavaScript
30 lines
775 B
JavaScript
var http = require("http");
|
|
var NodeHelper = require("node_helper");
|
|
|
|
module.exports = NodeHelper.create({
|
|
start: function () {
|
|
},
|
|
|
|
socketNotificationReceived: function (notification, payload) {
|
|
var self = this;
|
|
|
|
if (notification === "AUTO_TIMEZONE") {
|
|
console.log("Loading timezone...");
|
|
http.get("http://ip-api.com/json", function (req) {
|
|
var data = "";
|
|
req.on("data", function (d) {
|
|
data += d;
|
|
});
|
|
req.on("end", function () {
|
|
var body = JSON.parse(data);
|
|
payload.timezone = body.timezone;
|
|
self.sendSocketNotification("UPDATE_TIMEZONE", payload);
|
|
});
|
|
}).on("error", function () {
|
|
payload.error = "Could not figure out the timezone.";
|
|
self.sendSocketNotification("UPDATE_TIMEZONE", payload);
|
|
});
|
|
}
|
|
}
|
|
});
|