A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
Read the statement by Michael Teeuw here.
include npm module like firebase module into our own MM module
-
cd ~/MagicMirror/modules/MMM-hellotsuhan npm install --save-dev electron-rebuild ./node_modules/.bin/electron-rebuild
This could be the solution. or not. :D
-
Thanks bro!:smiling_face_with_open_mouth_smiling_eyes: this work for me!! after did below code then success to run the code already.
cd ~/MagicMirror/modules/MMM-hellotsuhan npm install --save-dev electron-rebuild ./node_modules/.bin/electron-rebuild
Now my node_helper.js is :
const firebase = require ('firebase') var NodeHelper = require("node_helper") let countdown; var ref; var config = { apiKey: "AIzaSyAxi_kFKM3lxMZ9gnBMhwoPa7pxKX_e1BI", authDomain: "customerservice-ee487.firebaseapp.com", databaseURL: "https://customerservice-ee487.firebaseio.com", projectId: "customerservice-ee487", storageBucket: "customerservice-ee487.appspot.com", messagingSenderId: "466622230094" }; if (!firebase.apps.length) { firebase.initializeApp(config); } module.exports = NodeHelper.create({ start: function() { ref = firebase.app().database().ref().child('countdown'); r ef.once('value').then(function (snap) { console.log('snap.val()', snap.val()); countdown=snap.val(); }); }, socketNotificationReceived: function(notification, payload) { switch(notification) { case "DO_YOUR_JOB": ref.once('value').then(function (snap) { console.log('snap.val()', snap.val()); countdown=snap.val(); }); this.sendSocketNotification("I_DID", countdown - payload); break } }, })
My MMM-hellotsuhan.js
Module.register("MMM-hellotsuhan",{ start: function (){ this.count = 0 }, getDom: function() { var element = document.createElement("div") element.className = "myContent" element.innerHTML = "Hello, World! " + this.config.foo var subElement = document.createElement("p") subElement.id = "COUNT" element.appendChild(subElement) return element }, notificationReceived: function(notification, payload, sender) { switch(notification) { case "DOM_OBJECTS_CREATED": var timer = setInterval(()=>{ this.sendSocketNotification("DO_YOUR_JOB", this.count) this.count++ }, 1000) break } }, socketNotificationReceived: function(notification, payload) { switch(notification) { case "I_DID": var elem = document.getElementById("COUNT") elem.innerHTML = "Count:" + payload break } }, });
-
btw Thanks for the great tutorial for developing module from @Sean !!
Head first developing MM module for extreme beginners -
@kevung
I think you’d better define config in module js instead node_helper.js to be able to be redefined by user in config.js. You can move config values with sendSocketNotification. -
@sean ok will try it out later =)