-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_helper.js
43 lines (42 loc) · 1.96 KB
/
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
37
38
39
40
41
42
43
var NodeHelper = require("node_helper");
var fs = require('fs');
const { spawn } = require("child_process");
module.exports = NodeHelper.create({
start: function(){
console.log("Starting node helper: " + this.name);
spawn("pianobar", {detached: true});
},
stop: function(){
fs.appendFile('/home/pi/.config/pianobar/ctl', 'q', function(err){
if(err){
console.log("Error seen: " + err);
}
});
},
socketNotificationReceived: function(notification, payload) {
var self = this;
if(notification === "CMD_PANDORA") {
fs.appendFile('/home/pi/.config/pianobar/ctl', payload.msg, function(err){
if(err){
console.log("Error seen: " + err);
}
});
} else if(notification === "GET_CUR_SONG") {
var song = fs.readFileSync("/home/pi/.config/pianobar/currentSong").toString();
if (song) {
var songArray = song.split(',,,');
var songToSend = "Title: " + songArray[1] + "<br>Album: " + songArray[2] + "<br>Artist: " + songArray[0];
self.sendSocketNotification("SONG", {currentSong: songToSend});
}
} else if(notification === "GET_STATION_LIST") {
var stationList = fs.readFileSync("/home/pi/.config/pianobar/stationList").toString();
self.sendSocketNotification("STATIONS", {allStations: stationList});
} else if(notification === "GET_CUR_STATION_NAME") {
var stationName = fs.readFileSync("/home/pi/.config/pianobar/currentStation").toString();
self.sendSocketNotification("STATION_NAME", {currentStationName: stationName});
} else if(notification === "GET_MAX_STATION") {
var stationCount = fs.readFileSync("/home/pi/.config/pianobar/maxStation").toString();
self.sendSocketNotification("MAX_STATION", {maxStation: stationCount});
}
},
});