Commit 18ebc7d4 by Chavee Issariyapat

add feedwatcher

parent c02834a2
module.exports.create = create module.exports.create = create
const DEBUG = false; const DEBUG = true;
const events = require('events'); const events = require('events');
const cache = require('./cache'); const cache = require('./cache');
const RESETDELAY = 1000 const RESETDELAY = 1000
const Coordinator = function(param={}) { const Coordinator = function(param={}) {
let that = this; let that = this;
let resettimer = 0; let resettimer = 0;
...@@ -22,6 +21,38 @@ const Coordinator = function(param={}) { ...@@ -22,6 +21,38 @@ const Coordinator = function(param={}) {
this.mqttclient = param.mqttclient; this.mqttclient = param.mqttclient;
this.flowemitter = param.flowemitter || null; this.flowemitter = param.flowemitter || null;
this.flowemitter.on('registerfeedwatcher', function(client){
let deviceid = client.deviceid;
let devicetoken = client.devicetoken;
let outtopic1 = `@tap/feed/updated/${deviceid}:${devicetoken}`;
if (that.topicstore.addTopic(outtopic1, client.nodeid)) {
if (DEBUG)console.log('----- subscribe : '+outtopic1)
that.mqttclient.subscribe(outtopic1);
}
if (DEBUG) {
console.log('registerfeedwatcher ---------------------------');
console.log(that.topicstore.getRawData());
}
});
this.flowemitter.on('deregisterfeedwatcher', function(client){
let deviceid = client.deviceid;
let devicetoken = client.devicetoken;
let outtopic1 = `@tap/feed/updated/${deviceid}:${devicetoken}`;
if (that.topicstore.delTopic(outtopic1, client.nodeid)) {
if (DEBUG)console.log('----- unsubscribe : '+outtopic1)
that.mqttclient.unsubscribe(outtopic1);
}
if (DEBUG) {
console.log('deregisterfeedwatcher ---------------------------');
console.log(that.topicstore.getRawData());
}
});
this.flowemitter.on('registershadowlistener', function(client){ this.flowemitter.on('registershadowlistener', function(client){
let deviceid = client.deviceid; let deviceid = client.deviceid;
let devicetoken = client.devicetoken; let devicetoken = client.devicetoken;
......
...@@ -12,6 +12,16 @@ const FlowEmitter = function(param = {}) { ...@@ -12,6 +12,16 @@ const FlowEmitter = function(param = {}) {
FlowEmitter.prototype.start = function() { FlowEmitter.prototype.start = function() {
let that = this; let that = this;
this.red.events.on(`${that.channelID}-registerfeedwatcher`, function(client) {
that.emit('registerfeedwatcher', client);
});
this.red.events.on(`${that.channelID}-deregisterfeedwatcher`, function(client) {
that.emit('deregisterfeedwatcher', client);
//that.emit('startcountdownreset');
});
this.red.events.on(`${that.channelID}-registershadowlistener`, function(client) { this.red.events.on(`${that.channelID}-registershadowlistener`, function(client) {
that.emit('registershadowlistener', client); that.emit('registershadowlistener', client);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment