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:
parent
03484169e3
commit
ea74eebff2
@ -15,8 +15,10 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||||
|
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 = "";
|
||||||
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.');
|
||||||
@ -24,13 +26,17 @@ exec("which mpd",function(err,stdout,stderr) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var mpc = "";
|
exec("netstat -an | grep LISTEN | grep 6600",function(err,stdout,stderr) {
|
||||||
komponist.createConnection(6600, 'localhost', function(err, client) {
|
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");
|
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;
|
||||||
@ -51,10 +57,10 @@ function MPDOut(n) {
|
|||||||
node.mpc.on('error', function(err) {
|
node.mpc.on('error', function(err) {
|
||||||
console.log("MPD: Error:",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);
|
RED.nodes.createNode(this,n);
|
||||||
var node = this;
|
var node = this;
|
||||||
node.mpc = mpc;
|
node.mpc = mpc;
|
||||||
@ -87,5 +93,7 @@ function MPDIn(n) {
|
|||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
// node.mpc.command("stop");
|
// node.mpc.command("stop");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("mpd in",MPDIn);
|
RED.nodes.registerType("mpd in",MPDIn);
|
||||||
|
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user