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

Check mpd really is listening on port 6600 before allowing nodes to exist.

Otherwise komponist fails badly.
This commit is contained in:
Dave C-J 2014-01-23 00:19:40 +00:00
parent 03484169e3
commit ea74eebff2

View File

@ -15,8 +15,10 @@
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var util = require("util");
var exec = require('child_process').exec;
var komponist = require('komponist');
var mpc = "";
exec("which mpd",function(err,stdout,stderr) {
if (stdout.indexOf('mpd') == -1) {
util.log('[69-mpd.js] Error: Cannot find "mpd" command. Please install MPD.');
@ -24,13 +26,17 @@ exec("which mpd",function(err,stdout,stderr) {
}
});
var mpc = "";
komponist.createConnection(6600, 'localhost', function(err, client) {
exec("netstat -an | grep LISTEN | grep 6600",function(err,stdout,stderr) {
if (stdout.indexOf('6600') == -1) {
util.log('[69-mpd.js] Error: MPD daemon not listening on port 6600. Please start MPD.');
return;
}
komponist.createConnection(6600, 'localhost', function(err, client) {
if (err) node.error("MPD: Failed to connect to MPD server");
mpc = client;
});
});
function MPDOut(n) {
function MPDOut(n) {
RED.nodes.createNode(this,n);
var node = this;
node.mpc = mpc;
@ -51,10 +57,10 @@ function MPDOut(n) {
node.mpc.on('error', function(err) {
console.log("MPD: Error:",err);
});
}
RED.nodes.registerType("mpd out",MPDOut);
}
RED.nodes.registerType("mpd out",MPDOut);
function MPDIn(n) {
function MPDIn(n) {
RED.nodes.createNode(this,n);
var node = this;
node.mpc = mpc;
@ -87,5 +93,7 @@ function MPDIn(n) {
this.on("close", function() {
// node.mpc.command("stop");
});
}
RED.nodes.registerType("mpd in",MPDIn);
}
RED.nodes.registerType("mpd in",MPDIn);
});