Skip to content

Commit

Permalink
implement active get
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Nov 12, 2017
1 parent d7fc5bf commit bea531f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ mqtt.on('connect', () => {
mqtt.subscribe(config.name + '/prop/#');
log.debug('mqtt subscribe', config.name + '/query/#');
mqtt.subscribe(config.name + '/query/#');
log.debug('mqtt subscribe', config.name + '/get/+/#');
mqtt.subscribe(config.name + '/get/+/#');
});

mqtt.on('close', () => {
Expand Down Expand Up @@ -100,12 +102,30 @@ mqtt.on('message', (topic, payload) => {

break;

case 'get':
let [type, gid] = mw(topic, config.name + '/get/+/#');
get(type, id);
break;

/* istanbul ignore next */
default:
log.error('unknown cmd', cmd);
}
});

function get(type, id) {
switch (type) {
case 'doc':
mqtt.publish(config.name + '/doc/' + id, core.db[id] ? JSON.stringify(core.db[id]) : '');
break;
case 'view':
mqtt.publish(config.name + '/view/' + id, core.views[id] ? JSON.stringify(core.views[id]) : '');
break;
default:
log.error('unknown get type', type);
}
}

core.on('ready', () => {
const oIds = Object.keys(core.db);
if (!config.retainDisable) {
Expand Down

0 comments on commit bea531f

Please sign in to comment.