Commit 4c2fd35d by zCaesar

add offline status

parent 87c6c2e5
......@@ -7,7 +7,7 @@ var auth_on_subscribe_debug = config.get('auth_on_subscribe_debug');
var on_publish_debug = config.get('on_publish_debug');
var on_deliver_debug = config.get('on_deliver_debug');
var on_unsubscribe_debug = config.get('on_unsubscribe_debug');
var on_offline_debug = config.get('on_offline_debug');
// var on_offline_debug = config.get('on_offline_debug');
var restify = require('restify');
var auth_on_register = require('./auth_on_register')({ debug: auth_on_register_debug });
......@@ -16,7 +16,8 @@ var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscrib
var on_publish = require('./on_publish')({ debug: on_publish_debug });
var on_deliver = require('./on_deliver')({ debug: on_deliver_debug });
var on_unsubscribe = require('./on_unsubscribe')({ debug: on_unsubscribe_debug });
var on_offline = require('./on_offline')({ debug: on_offline_debug });
// var on_offline = require('./on_offline')({ debug: on_offline_debug });
var on_offline = require('./redis/on_offline').on_offline_redis
const server = restify.createServer({
name: 'authhook',
......@@ -46,8 +47,8 @@ server.post('/onsub', (req, res, next) => {
server.post('/onunsub', on_unsubscribe)
server.post('/ondeliver', on_deliver)
server.post('/onpub', on_publish)
server.post('/onoff', on_offline)
server.post('/ongone', on_offline)
server.post('/onoff', on_offline(req.body.client_id))
server.post('/ongone', on_offline(req.body.client_id))
server.listen(port, function () {
console.log('%s listening at %s', server.name, server.url);
......
var Redis = require('ioredis')
var redis = new Redis()
function on_offline_redis(deviceid) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => {
var information = setValue(deviceid)
redis.hset(information.keys, 'status', information.status, 'offline_on', information.offline_on, function (err, res) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
})
}
module.exports.on_offline_redis = on_offline_redis
function setValue(deviceid) {
var dateNow = Math.floor(Date.now() / 1000)
var keys = 'deviceid:' + deviceid
var status = false
var offline_on = dateNow
return {
keys: keys,
status: status,
offline_on: offline_on
}
}
\ No newline at end of file
var Redis = require('ioredis')
var redis = new Redis()
var pub = new Redis()
function on_register_redis(deviceid) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => {
......
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