1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Slightly more elegant mpd fix.

This commit is contained in:
Dave C-J 2014-01-23 08:41:51 +00:00
parent ea74eebff2
commit 2dbd93d63d

View File

@ -18,7 +18,7 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red");
var util = require("util"); var util = require("util");
var exec = require('child_process').exec; var exec = require('child_process').exec;
var komponist = require('komponist'); var komponist = require('komponist');
var mpc = ""; var mpc = null;
exec("which mpd",function(err,stdout,stderr) { exec("which mpd",function(err,stdout,stderr) {
if (stdout.indexOf('mpd') == -1) { if (stdout.indexOf('mpd') == -1) {
util.log('[69-mpd.js] Error: Cannot find "mpd" command. Please install MPD.'); util.log('[69-mpd.js] Error: Cannot find "mpd" command. Please install MPD.');
@ -35,12 +35,15 @@ exec("netstat -an | grep LISTEN | grep 6600",function(err,stdout,stderr) {
if (err) node.error("MPD: Failed to connect to MPD server"); if (err) node.error("MPD: Failed to connect to MPD server");
mpc = client; mpc = client;
}); });
});
function MPDOut(n) {
function MPDOut(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
node.mpc = mpc; node.mpc = mpc;
if (mpc != null) {
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { if (msg != null) {
console.log(msg); console.log(msg);
@ -58,14 +61,17 @@ exec("netstat -an | grep LISTEN | grep 6600",function(err,stdout,stderr) {
console.log("MPD: Error:",err); console.log("MPD: Error:",err);
}); });
} }
RED.nodes.registerType("mpd out",MPDOut); else { node.warn("MPD not running"); }
}
RED.nodes.registerType("mpd out",MPDOut);
function MPDIn(n) { function MPDIn(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
node.mpc = mpc; node.mpc = mpc;
var oldMsg = ""; var oldMsg = "";
if (mpc != null) {
getSong(); getSong();
function getSong() { function getSong() {
@ -94,6 +100,6 @@ exec("netstat -an | grep LISTEN | grep 6600",function(err,stdout,stderr) {
// node.mpc.command("stop"); // node.mpc.command("stop");
}); });
} }
RED.nodes.registerType("mpd in",MPDIn); else { node.warn("MPD not running"); }
}
}); RED.nodes.registerType("mpd in",MPDIn);