Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
4c2fd35d
Commit
4c2fd35d
authored
Nov 15, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add offline status
parent
87c6c2e5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
5 deletions
+30
-5
authhook/index.js
+5
-4
authhook/redis/on_offline.js
+25
-0
authhook/redis/on_register.js
+0
-1
No files found.
authhook/index.js
View file @
4c2fd35d
...
...
@@ -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
);
...
...
authhook/redis/on_offline.js
0 → 100644
View file @
4c2fd35d
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
authhook/redis/on_register.js
View file @
4c2fd35d
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
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment