Re-added optional topic to avoid breaking compatibility

This commit is contained in:
Nathanaël Lécaudé 2016-05-20 10:17:58 -04:00
parent eef6f28e89
commit 6d32edc0f2
2 changed files with 27 additions and 12 deletions

View File

@ -11,6 +11,10 @@
limitations under the License.
-->
<script type="text/x-red" data-template-name="PhysicalWeb in">
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="eddystone">
</div>
<div class="form-row">
<label><i class="fa fa-list"></i> Duplicates</span></label>
<input type="checkbox" id="node-input-duplicates" style="display: inline-block; width: auto; vertical-align: top;">
@ -26,6 +30,7 @@
<p><a href="https://google.github.io/physical-web/">Physical Web</a> node to scan for Eddystone beacons.</p>
<p>This node scans for Eddystones and publishes what it finds. The status of the Eddystone
(found, updated or lost) will be sent as <code>msg.topic</code> and the data as <code>msg.payload</code></p>
<p>If a <code>topic</code> is specified in the node configuration, it will override the status.</p>
<p><b>URL</b> type:</p>
<ul>
<li><code>type</code> - Eddystone type</li>
@ -62,6 +67,7 @@
category: 'input',
defaults: {
name: {value:""},
topic: {value:""},
duplicates: {value: true}
},
color: "#2F7ACD",

View File

@ -187,24 +187,33 @@ module.exports = function(RED) {
node.duplicates = n.duplicates;
function onFound(beacon) {
node.send({
topic: 'found',
payload: beacon
});
var topic_data;
if (node.topic !== "") {
topic_data = node.topic;
} else {
topic_data = 'found';
}
node.send({topic: topic_data, payload: beacon});
}
function onUpdated(beacon) {
node.send({
topic: 'updated',
payload: beacon
});
var topic_data;
if (node.topic !== "") {
topic_data = node.topic;
} else {
topic_data = 'updated';
}
node.send({topic: topic_data, payload: beacon});
}
function onLost(beacon) {
node.send({
topic: 'lost',
payload: beacon
});
var topic_data;
if (node.topic !== "") {
topic_data = node.topic;
} else {
topic_data = 'lost';
}
node.send({topic: topic_data, payload: beacon});
}
EddystoneBeaconScanner.on('found', onFound);