node-red-contrib-fred
Advanced tools
Comparing version 0.0.5 to 0.0.6
103
fred.js
@@ -53,3 +53,3 @@ | ||
node._inputNodes = []; // collection of nodes that want to receive events | ||
node._inputNodes = []; // collection of nodes that want to receive events | ||
node._clients = {}; | ||
@@ -67,4 +67,11 @@ | ||
node.path = p.config.fredHost; // change host in the package for testing | ||
// insert fred account name at the begining of the path following the | ||
// proxy format: wss://{accountname}.fred.sensetecnic.com/{path} | ||
var protocol = node.path.split("://")[0] + "://"; | ||
var path = node.fredUsername + "." + node.path.split("://")[1]; | ||
node.path = protocol + path; | ||
if (!node.private) { | ||
node.path = node.path + "/public/" + node.fredUsername + "/__" + node.endpoint; | ||
node.path = node.path + "/api/public/__" + node.endpoint; | ||
} else { | ||
@@ -102,5 +109,5 @@ node.path = node.path + "/api/__" + node.endpoint; | ||
if (node.isServer) { | ||
node._clients[id] = socket; | ||
node.emit('opened',Object.keys(node._clients).length); | ||
if (node.isServer) { | ||
node._clients[id] = socket; | ||
node.emit('opened',Object.keys(node._clients).length); | ||
} | ||
@@ -116,11 +123,11 @@ | ||
socket.on('close',function() { | ||
if (node.isServer) { | ||
delete node._clients[id]; | ||
node.emit('closed',Object.keys(node._clients).length); | ||
} else { | ||
node.emit('closed'); | ||
if (node.isServer) { | ||
delete node._clients[id]; | ||
node.emit('closed',Object.keys(node._clients).length); | ||
} else { | ||
node.emit('closed'); | ||
} | ||
if (!node.closing && !node.isServer && !node.unauthorized) { // don't reconnect if server returns 401 unauthorized | ||
if (node.tout) { | ||
clearTimeout(node.tout); | ||
if (node.tout) { | ||
clearTimeout(node.tout); | ||
} | ||
@@ -142,4 +149,4 @@ node.emit('reconnecting'); | ||
} | ||
if (node.tout) { | ||
clearTimeout(node.tout); | ||
if (node.tout) { | ||
clearTimeout(node.tout); | ||
} | ||
@@ -170,3 +177,3 @@ node.emit('reconnecting'); | ||
} | ||
} | ||
}; | ||
@@ -217,4 +224,4 @@ RED.server.addListener('newListener',storeListener); | ||
node.server.close(); | ||
if (node.tout) { | ||
clearTimeout(node.tout); | ||
if (node.tout) { | ||
clearTimeout(node.tout); | ||
} | ||
@@ -234,3 +241,3 @@ } | ||
this._inputNodes.push(handler); | ||
} | ||
}; | ||
@@ -243,3 +250,3 @@ FredEndpointNode.prototype.removeInputNode = function(/*Node*/handler) { | ||
}); | ||
} | ||
}; | ||
@@ -264,3 +271,3 @@ FredEndpointNode.prototype.handleEvent = function(id,/*socket*/socket,/*String*/event,/*Object*/data,/*Object*/flags){ | ||
} | ||
} | ||
}; | ||
@@ -279,7 +286,7 @@ FredEndpointNode.prototype.broadcast = function(data) { | ||
if (!this.fredUsername) { | ||
this.emit('erro', RED._("fred.errors.missing-username")); | ||
this.emit('erro', RED._("fred.errors.missing-username")); | ||
} else { | ||
this.emit('erro', RED._("fred.errors.connect-error")); | ||
this.emit('erro', RED._("fred.errors.connect-error")); | ||
} | ||
} | ||
} | ||
} | ||
@@ -290,3 +297,3 @@ } | ||
} | ||
} | ||
}; | ||
@@ -302,3 +309,3 @@ FredEndpointNode.prototype.reply = function(id,data) { | ||
} | ||
} | ||
}; | ||
@@ -313,6 +320,6 @@ function FredInNode(n) { | ||
// TODO: nls | ||
this.serverConfig.on('opened', function(n) { | ||
node.status({fill:"green",shape:"dot",text:"connected "+n}); | ||
this.serverConfig.on('opened', function(n) { | ||
node.status({fill:"green",shape:"dot",text:"connected "+n}); | ||
}); | ||
this.serverConfig.on('erro', function(err) { | ||
this.serverConfig.on('erro', function(err) { | ||
if (err) { | ||
@@ -323,14 +330,14 @@ node.error(RED._("fred.errors.connect-error")+inspect(err)); | ||
else { | ||
node.status({fill:"red",shape:"ring",text:"error"}); | ||
node.status({fill:"red",shape:"ring",text:"error"}); | ||
} | ||
}); | ||
this.serverConfig.on('closed', function() { | ||
this.serverConfig.on('closed', function() { | ||
if (node.serverConfig && node.serverConfig.unauthorized) { | ||
node.status({fill: "red",shape:"dot",text:"unauthorized"}); | ||
} else if (node.serverConfig && | ||
!node.serverConfig.fredUsername && | ||
} else if (node.serverConfig && | ||
!node.serverConfig.fredUsername && | ||
!node.serverConfig.isServer) { | ||
node.status({fill: "red",shape:"dot",text: RED._("fred.errors.missing-username")}); | ||
} else { | ||
node.status({fill:"red",shape:"ring",text:"disconnected"}); | ||
} else { | ||
node.status({fill:"red",shape:"ring",text:"disconnected"}); | ||
} | ||
@@ -340,3 +347,3 @@ }); | ||
var nodeName = (typeof node.name !== 'undefined') ? node.name : "[FRED] " + this.endpoint; | ||
node.status({fill:"red",shape:"ring",text:"connection failed"}); | ||
node.status({fill:"red",shape:"ring",text:"connection failed"}); | ||
node.error(RED._("fred.errors.max-trials") + ": " + nodeName); | ||
@@ -369,28 +376,28 @@ }); | ||
// TODO: nls | ||
this.serverConfig.on('opened', function(n) { | ||
node.status({fill:"green",shape:"dot",text:"connected "+n}); | ||
this.serverConfig.on('opened', function(n) { | ||
node.status({fill:"green",shape:"dot",text:"connected "+n}); | ||
}); | ||
this.serverConfig.on('erro', function(err) { | ||
this.serverConfig.on('erro', function(err) { | ||
if (err) { | ||
node.error(RED._("fred.errors.connect-error")+inspect(err)); | ||
node.status({fill:"red",shape:"ring",text:err}); | ||
node.status({fill:"red",shape:"ring",text:err}); | ||
} | ||
else { | ||
node.status({fill:"red",shape:"ring",text:"error"}); | ||
node.status({fill:"red",shape:"ring",text:"error"}); | ||
} | ||
}); | ||
this.serverConfig.on('closed', function() { | ||
this.serverConfig.on('closed', function() { | ||
if (node.serverConfig && node.serverConfig.unauthorized) { | ||
node.status({fill: "red",shape:"dot",text:"unauthorized"}); | ||
} else if (node.serverConfig && | ||
!node.serverConfig.fredUsername && | ||
} else if (node.serverConfig && | ||
!node.serverConfig.fredUsername && | ||
!node.serverConfig.isServer) { | ||
node.status({fill: "red",shape:"dot",text: RED._("fred.errors.missing-username")}); | ||
} else { | ||
node.status({fill:"red",shape:"ring",text:"disconnected"}); | ||
} | ||
} else { | ||
node.status({fill:"red",shape:"ring",text:"disconnected"}); | ||
} | ||
}); | ||
this.serverConfig.on('maxReConn', function(){ | ||
var nodeName = (typeof node.name !== 'undefined') ? node.name : "[FRED] " + this.endpoint; | ||
node.status({fill:"red",shape:"ring",text:"Failed to connect after " + MAX_CONNECTION_ATTEMPTS + " attempts"}); | ||
node.status({fill:"red",shape:"ring",text:"Failed to connect after " + MAX_CONNECTION_ATTEMPTS + " attempts"}); | ||
node.error(RED._("fred.errors.max-trials") + ": " + nodeName); | ||
@@ -429,2 +436,2 @@ }); | ||
RED.nodes.registerType("fred out",FredOutNode); | ||
} | ||
}; |
{ | ||
"name": "node-red-contrib-fred", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Node set for linking FRED hosted Node-RED to devices", | ||
@@ -5,0 +5,0 @@ "homepage": "https://fred.sensetecnic.com", |
@@ -20,3 +20,3 @@ # node-red-contrib-fred | ||
On FRED, create an named endpoint for your Pi or PC to connect to. For example, the following flow creates a private FRED input endpoint node called 'example' connected to a debug output node. | ||
On FRED, create an named endpoint for your Pi or PC to connect to. The endpoint name must start with a letter and consist of only alpha-numeric, dash and underscore characters (url friendly). For example, the following flow creates a private FRED input endpoint node called 'example' connected to a debug output node. | ||
@@ -23,0 +23,0 @@ ``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
419
42537
8