-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
36 lines (33 loc) · 937 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
var NodeHelper = require('node_helper');
const firebase = require('firebase/app');
require('firebase/database');
module.exports = NodeHelper.create({
listenToChanges: function() {
firebase
.database()
.ref(this.config.firebaseDatabaseRootRef)
.on('value', snapshot => {
const sensorEvents = snapshot.val();
this.sendSocketNotification('SENSORS_CHANGED', sensorEvents);
});
},
stop: function() {
firebase
.database()
.ref(this.config.firebaseDatabaseRootRef)
.off();
},
socketNotificationReceived: function(notification, payload) {
console.log(
`[${this.name}] socketNotificationReceived notification: ${notification}`,
payload,
);
if (notification === 'SEND_CONFIG') {
this.config = payload;
firebase.initializeApp(payload.firebaseConfig);
this.listenToChanges();
return true;
}
return false;
},
});