mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Fix starting with a URL
This commit is contained in:
parent
b33571b240
commit
71f1de7984
@ -15,73 +15,73 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var eddystoneBeacon = require('eddystone-beacon');
|
var eddystoneBeacon = require('eddystone-beacon');
|
||||||
var EddystoneBeaconScanner = require('eddystone-beacon-scanner');
|
var EddystoneBeaconScanner = require('eddystone-beacon-scanner');
|
||||||
|
|
||||||
function Beacon(n){
|
function Beacon(n){
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
var node = this;
|
var node = this;
|
||||||
node.power = n.power;
|
node.power = n.power;
|
||||||
node.period = n.period;
|
node.period = n.period;
|
||||||
node.url = n.url;
|
node.url = n.url;
|
||||||
|
|
||||||
node.options = {
|
node.options = {
|
||||||
txPowerLevel: node.power,
|
txPowerLevel: node.power,
|
||||||
tlmPeriod: node.period
|
tlmPeriod: node.period
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (node.url) {
|
if (node.url) {
|
||||||
try {
|
try {
|
||||||
eddystoneBeacon.advertiseUrl(msg.payload, node.options);
|
eddystoneBeacon.advertiseUrl(node.url, node.options);
|
||||||
} catch(e){
|
} catch(e){
|
||||||
node.error('Error setting beacon URL', e);
|
node.error('Error setting beacon URL', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node.on('input', function(msg){
|
node.on('input', function(msg){
|
||||||
try {
|
try {
|
||||||
eddystoneBeacon.advertiseUrl(msg.payload, node.options);
|
eddystoneBeacon.advertiseUrl(msg.payload, node.options);
|
||||||
} catch(e){
|
} catch(e){
|
||||||
node.error('error updating beacon URL', e);
|
node.error('error updating beacon URL', e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
node.on('close', function(done){
|
node.on('close', function(done){
|
||||||
try {
|
try {
|
||||||
eddystoneBeacon.stop();
|
eddystoneBeacon.stop();
|
||||||
done();
|
done();
|
||||||
} catch(e){
|
} catch(e){
|
||||||
node.error('error shuttingdown beacon', e);
|
node.error('error shuttingdown beacon', e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("PhysicalWeb out", Beacon);
|
RED.nodes.registerType("PhysicalWeb out", Beacon);
|
||||||
|
|
||||||
function Scanner(n){
|
function Scanner(n){
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
var node = this;
|
var node = this;
|
||||||
node.topic = n.topic;
|
node.topic = n.topic;
|
||||||
|
|
||||||
function onFound(beacon) {
|
function onFound(beacon) {
|
||||||
node.send({
|
node.send({
|
||||||
topic: node.topic,
|
topic: node.topic,
|
||||||
payload: beacon
|
payload: beacon
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
EddystoneBeaconScanner.on('found', onFound);
|
EddystoneBeaconScanner.on('found', onFound);
|
||||||
EddystoneBeaconScanner.on('updated', onFound);
|
EddystoneBeaconScanner.on('updated', onFound);
|
||||||
|
|
||||||
node.on('close',function(done){
|
node.on('close',function(done){
|
||||||
EddystoneBeaconScanner.removeListener('found', onFound);
|
EddystoneBeaconScanner.removeListener('found', onFound);
|
||||||
EddystoneBeaconScanner.removeListener('updated', onFound);
|
EddystoneBeaconScanner.removeListener('updated', onFound);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("PhysicalWeb in", Scanner);
|
RED.nodes.registerType("PhysicalWeb in", Scanner);
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user