mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Update node-red-nodes social nodes to use strict and pass jshint scan
This commit is contained in:
parent
052a7d587d
commit
43dfded402
95
social/dweetio/55-dweetio.html
Normal file
95
social/dweetio/55-dweetio.html
Normal file
@ -0,0 +1,95 @@
|
||||
<!--
|
||||
Copyright 2014 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="dweetio out">
|
||||
<div class="form-row">
|
||||
<label for="node-input-thing"><i class="icon-flag"></i> Thing</label>
|
||||
<input type="text" id="node-input-thing" placeholder="my-globally-unique-device-id">
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="dweetio out">
|
||||
<p>Sends the <b>msg.payload</b> to Dweet.io</p>
|
||||
<p>Optionally uses <b>msg.thing</b> to set the thing id, if not already set in the properties.</p>
|
||||
<p>You need to make the thing id unique - you are recommended to use a GUID.<p>
|
||||
<p>For further info see the <a href="https://dweetio.io/" target="_new">Dweet.io website</a>.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('dweetio out',{
|
||||
category: 'output',
|
||||
defaults: {
|
||||
thing: {value:""},
|
||||
name: {value:""}
|
||||
},
|
||||
color:"#d7c9a0",
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
icon: "arrow.png",
|
||||
align: "right",
|
||||
label: function() {
|
||||
return this.name||this.title||"dweetio";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="dweetio in">
|
||||
<div class="form-row">
|
||||
<label for="node-input-thing"><i class="icon-flag"></i> Thing</label>
|
||||
<input type="text" id="node-input-thing" placeholder="my-globally-unique-device-id">
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="dweetio in">
|
||||
<p>Listens for messages from Dweet.io</p>
|
||||
<p>The thing id should be globally unique as they are all public - you are recommended to use a GUID.<p>
|
||||
<p>The Thing ID is set into <b>msg.dweet</b>, and the timesamp into <b>msg.created</b>.</p>
|
||||
<p>For further info see the <a href="https://dweetio.io/" target="_new">Dweet.io website</a>.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('dweetio in',{
|
||||
category: 'input',
|
||||
defaults: {
|
||||
thing: {value:""},
|
||||
name: {value:""}
|
||||
},
|
||||
color:"#d7c9a0",
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
icon: "arrow.png",
|
||||
label: function() {
|
||||
return this.name||this.title||"dweetio";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
67
social/dweetio/55-dweetio.js
Normal file
67
social/dweetio/55-dweetio.js
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright 2014 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var DweetClient = require("node-dweetio");
|
||||
var util = require('util');
|
||||
var dweetio = null;
|
||||
|
||||
function DweetioOutNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.thing = n.thing;
|
||||
if (dweetio == null) { dweetio = new DweetClient(); }
|
||||
var node = this;
|
||||
|
||||
this.on("input",function(msg) {
|
||||
//if (typeof(msg.payload) === 'object') {
|
||||
var thing = node.thing || msg.thing;
|
||||
try {
|
||||
dweetio.dweet_for(thing, {some:msg.payload}, function(err, dweet) {
|
||||
//console.log(dweet.thing); // "my-thing"
|
||||
//console.log(dweet.content); // The content of the dweet
|
||||
//console.log(dweet.created); // The create date of the dweet
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
node.log(err);
|
||||
}
|
||||
//} else { node.warn("Dweetio only sends payload objects."); }
|
||||
});
|
||||
|
||||
}
|
||||
RED.nodes.registerType("dweetio out",DweetioOutNode);
|
||||
|
||||
function DweetioInNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.thing = n.thing;
|
||||
if (dweetio == null) { dweetio = new DweetClient(); }
|
||||
var node = this;
|
||||
|
||||
dweetio.listen_for(node.thing, function(dweet){
|
||||
// This will be called anytime there is a new dweet for my-thing
|
||||
dweet.payload = dweet.content.some;
|
||||
delete dweet.content;
|
||||
node.send(dweet);
|
||||
});
|
||||
|
||||
this.on("close", function() {
|
||||
dweetio.stop_listening_for(node.thing);
|
||||
});
|
||||
|
||||
}
|
||||
RED.nodes.registerType("dweetio in",DweetioInNode);
|
||||
}
|
@ -14,89 +14,91 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
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 = null;
|
||||
exec("which mpd",function(err,stdout,stderr) {
|
||||
if (stdout.indexOf('mpd') == -1) {
|
||||
throw 'Error: Cannot find "mpd" command. Please install MPD.';
|
||||
}
|
||||
});
|
||||
|
||||
exec("netstat -an | grep LISTEN | grep 6600",function(err,stdout,stderr) {
|
||||
if (stdout.indexOf('6600') == -1) {
|
||||
throw '[69-mpd.js] Error: MPD daemon not listening on port 6600. Please start MPD.';
|
||||
}
|
||||
komponist.createConnection(6600, 'localhost', function(err, client) {
|
||||
if (err) node.error("MPD: Failed to connect to MPD server");
|
||||
mpc = client;
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var util = require("util");
|
||||
var exec = require('child_process').exec;
|
||||
var komponist = require('komponist');
|
||||
var mpc = null;
|
||||
exec("which mpd",function(err,stdout,stderr) {
|
||||
if (stdout.indexOf('mpd') == -1) {
|
||||
throw 'Error: Cannot find "mpd" command. Please install MPD.';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function MPDOut(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
var node = this;
|
||||
node.mpc = mpc;
|
||||
|
||||
if (mpc != null) {
|
||||
this.on("input", function(msg) {
|
||||
if (msg != null) {
|
||||
try {
|
||||
//node.mpc.command(msg.payload);
|
||||
node.mpc.command(msg.payload, msg.param, function(err, results) {
|
||||
if (err) { node.log("error: "+err); }
|
||||
//else { console.log(results); }
|
||||
});
|
||||
} catch (err) { node.log("error: "+err); }
|
||||
}
|
||||
exec("netstat -an | grep LISTEN | grep 6600",function(err,stdout,stderr) {
|
||||
if (stdout.indexOf('6600') == -1) {
|
||||
throw '[69-mpd.js] Error: MPD daemon not listening on port 6600. Please start MPD.';
|
||||
}
|
||||
komponist.createConnection(6600, 'localhost', function(err, client) {
|
||||
if (err) { node.error("MPD: Failed to connect to MPD server"); }
|
||||
mpc = client;
|
||||
});
|
||||
});
|
||||
|
||||
node.mpc.on('error', function(err) {
|
||||
node.log("error: "+err);
|
||||
});
|
||||
}
|
||||
else { node.warn("MPD not running"); }
|
||||
}
|
||||
RED.nodes.registerType("mpd out",MPDOut);
|
||||
|
||||
function MPDIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
var node = this;
|
||||
node.mpc = mpc;
|
||||
var oldMsg = "";
|
||||
function MPDOut(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
var node = this;
|
||||
node.mpc = mpc;
|
||||
|
||||
if (mpc != null) {
|
||||
getSong();
|
||||
|
||||
function getSong() {
|
||||
node.mpc.currentsong(function(err, info) {
|
||||
if (err) node.log(err);
|
||||
else {
|
||||
var msg = {payload:{},topic:"music"};
|
||||
msg.payload.Artist = info.Artist;
|
||||
msg.payload.Album = info.Album;
|
||||
msg.payload.Title = info.Title;
|
||||
msg.payload.Genre = info.Genre;
|
||||
msg.payload.Date = info.Date;
|
||||
if (JSON.stringify(msg) != oldMsg) {
|
||||
node.send(msg);
|
||||
oldMsg = JSON.stringify(msg);
|
||||
}
|
||||
if (mpc != null) {
|
||||
this.on("input", function(msg) {
|
||||
if (msg != null) {
|
||||
try {
|
||||
//node.mpc.command(msg.payload);
|
||||
node.mpc.command(msg.payload, msg.param, function(err, results) {
|
||||
if (err) { node.log("error: "+err); }
|
||||
//else { console.log(results); }
|
||||
});
|
||||
} catch (err) { node.log("error: "+err); }
|
||||
}
|
||||
});
|
||||
|
||||
node.mpc.on('error', function(err) {
|
||||
node.log("error: "+err);
|
||||
});
|
||||
}
|
||||
|
||||
node.mpc.on('changed', function(system) {
|
||||
getSong();
|
||||
});
|
||||
|
||||
this.on("close", function() {
|
||||
// node.mpc.command("stop");
|
||||
});
|
||||
else { node.warn("MPD not running"); }
|
||||
}
|
||||
else { node.warn("MPD not running"); }
|
||||
RED.nodes.registerType("mpd out",MPDOut);
|
||||
|
||||
function MPDIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
var node = this;
|
||||
node.mpc = mpc;
|
||||
var oldMsg = "";
|
||||
|
||||
if (mpc != null) {
|
||||
getSong();
|
||||
|
||||
var getSong = function() {
|
||||
node.mpc.currentsong(function(err, info) {
|
||||
if (err) { node.log(err); }
|
||||
else {
|
||||
var msg = {payload:{},topic:"music"};
|
||||
msg.payload.Artist = info.Artist;
|
||||
msg.payload.Album = info.Album;
|
||||
msg.payload.Title = info.Title;
|
||||
msg.payload.Genre = info.Genre;
|
||||
msg.payload.Date = info.Date;
|
||||
if (JSON.stringify(msg) != oldMsg) {
|
||||
node.send(msg);
|
||||
oldMsg = JSON.stringify(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
node.mpc.on('changed', function(system) {
|
||||
getSong();
|
||||
});
|
||||
|
||||
this.on("close", function() {
|
||||
// node.mpc.command("stop");
|
||||
});
|
||||
}
|
||||
else { node.warn("MPD not running"); }
|
||||
}
|
||||
RED.nodes.registerType("mpd in",MPDIn);
|
||||
}
|
||||
RED.nodes.registerType("mpd in",MPDIn);
|
||||
|
@ -39,11 +39,11 @@ var querystring = require('querystring');
|
||||
RED.httpAdmin.get('/xmpp-server/:id',function(req,res) {
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
if (credentials) {
|
||||
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
|
||||
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!=="")}));
|
||||
} else if (xmppkey && xmppkey.jid && xmppkey.password) {
|
||||
RED.nodes.addCredentials(req.params.id,{user:xmppkey.jid, password:xmppkey.password, global:true});
|
||||
credentials = RED.nodes.getCredentials(req.params.id);
|
||||
res.send(JSON.stringify({user:credentials.user,global:credentials.global,hasPassword:(credentials.password&&credentials.password!="")}));
|
||||
res.send(JSON.stringify({user:credentials.user,global:credentials.global,hasPassword:(credentials.password&&credentials.password!=="")}));
|
||||
} else {
|
||||
res.send(JSON.stringify({}));
|
||||
}
|
||||
@ -62,12 +62,12 @@ RED.httpAdmin.post('/xmpp-server/:id',function(req,res) {
|
||||
req.on('end', function(){
|
||||
var newCreds = querystring.parse(body);
|
||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||
if (newCreds.user == null || newCreds.user == "") {
|
||||
if (newCreds.user == null || newCreds.user === "") {
|
||||
delete credentials.user;
|
||||
} else {
|
||||
credentials.user = newCreds.user;
|
||||
}
|
||||
if (newCreds.password == "") {
|
||||
if (newCreds.password === "") {
|
||||
delete credentials.password;
|
||||
} else {
|
||||
credentials.password = newCreds.password||credentials.password;
|
||||
@ -228,7 +228,7 @@ function XmppOutNode(n) {
|
||||
}
|
||||
else {
|
||||
var to = msg.topic;
|
||||
if (node.to != "") { to = node.to; }
|
||||
if (node.to !== "") { to = node.to; }
|
||||
if (node.sendAll) {
|
||||
xmpp.send(to, JSON.stringify(msg), node.join);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user