Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
flowagent
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
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
node-red
flowagent
Commits
beb2058d
Commit
beb2058d
authored
Apr 19, 2020
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redesign event
parent
936fad75
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
coordinator.js
+41
-4
flowemitter.js
+7
-3
No files found.
coordinator.js
View file @
beb2058d
...
@@ -12,6 +12,8 @@ const Coordinator = function(param={}) {
...
@@ -12,6 +12,8 @@ const Coordinator = function(param={}) {
let
that
=
this
;
let
that
=
this
;
let
resettimer
=
0
;
let
resettimer
=
0
;
this
.
topicstore
=
require
(
'./topicstore'
).
create
();
this
.
x
=
0
;
this
.
x
=
0
;
this
.
started
=
false
;
this
.
started
=
false
;
...
@@ -20,19 +22,34 @@ const Coordinator = function(param={}) {
...
@@ -20,19 +22,34 @@ 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
(
'newclient'
,
function
(
client
){
this
.
flowemitter
.
on
(
'new
shadow
client'
,
function
(
client
){
let
deviceid
=
client
.
deviceid
;
let
deviceid
=
client
.
deviceid
;
let
devicetoken
=
client
.
devicetoken
;
let
devicetoken
=
client
.
devicetoken
;
console
.
log
that
.
mqttclient
.
subscribe
(
`@tap/shadow/updated/
${
deviceid
}
:
${
devicetoken
}
`
);
that
.
mqttclient
.
subscribe
(
`@tap/shadow/updated/
${
deviceid
}
:
${
devicetoken
}
`
);
that
.
mqttclient
.
subscribe
(
`@tap/device/changed/
${
deviceid
}
:
${
devicetoken
}
`
);
that
.
mqttclient
.
subscribe
(
`@tap/device/changed/
${
deviceid
}
:
${
devicetoken
}
`
);
if
(
DEBUG_SUBLIST
)
{
if
(
DEBUG_SUBLIST
)
{
console
.
log
(
`\nshadow client #
${
deviceid
}
connected -->`
)
// console.log(`\nshadow client #${deviceid} connected -->`)
console
.
log
(
that
.
flowemitter
.
sublist
);
// console.log(that.flowemitter.sublist);
}
});
this
.
flowemitter
.
on
(
'newmsgclient'
,
function
(
client
){
let
deviceid
=
client
.
deviceid
;
let
devicetoken
=
client
.
devicetoken
;
that
.
mqttclient
.
subscribe
(
`@tap/device/changed/
${
deviceid
}
:
${
devicetoken
}
`
);
if
(
DEBUG_SUBLIST
)
{
// console.log(`\nshadow client #${deviceid} connected -->`)
// console.log(that.flowemitter.sublist);
}
}
});
});
this
.
flowemitter
.
on
(
'flowpub'
,
function
(
topic
,
payload
,
client
){
this
.
flowemitter
.
on
(
'flowpub'
,
function
(
topic
,
payload
,
client
){
let
outtopic
,
outmsg
;
let
outtopic
,
outmsg
;
let
deviceid
=
client
.
deviceid
;
let
deviceid
=
client
.
deviceid
;
...
@@ -65,14 +82,34 @@ const Coordinator = function(param={}) {
...
@@ -65,14 +82,34 @@ const Coordinator = function(param={}) {
this
.
flowemitter
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
this
.
flowemitter
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
console
.
log
(
client
.
nodeid
+
' flowsub --> '
+
topic
)
let
deviceid
=
client
.
deviceid
;
let
deviceid
=
client
.
deviceid
;
let
devicetoken
=
client
.
devicetoken
;
let
devicetoken
=
client
.
devicetoken
;
if
(
topic
.
startsWith
(
'@local/msgin/'
))
{
if
(
topic
.
startsWith
(
'@local/msgin/'
))
{
let
msgpart
=
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
let
msgpart
=
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
devicetoken
}
/
${
msgpart
}
`
;
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
devicetoken
}
/
${
msgpart
}
`
;
that
.
mqttclient
.
subscribe
(
outtopic
);
if
(
that
.
topicstore
.
addTopic
(
outtopic
,
client
.
nodeid
))
{
that
.
mqttclient
.
subscribe
(
outtopic
);
}
}
else
{
}
});
this
.
flowemitter
.
on
(
'flowunsub'
,
function
(
topic
,
client
)
{
console
.
log
(
client
.
nodeid
+
' flowunsub --> '
+
topic
)
let
deviceid
=
client
.
deviceid
;
let
devicetoken
=
client
.
devicetoken
;
if
(
topic
.
startsWith
(
'@local/msgin/'
))
{
let
msgpart
=
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
devicetoken
}
/
${
msgpart
}
`
;
if
(
that
.
topicstore
.
delTopic
(
outtopic
,
client
.
nodeid
))
{
//console.log('----- unsubscribe : '+outtopic)
that
.
mqttclient
.
unsubscribe
(
outtopic
);
}
}
}
else
{
else
{
}
}
...
...
flowemitter.js
View file @
beb2058d
...
@@ -12,11 +12,11 @@ const FlowEmitter = function(param = {}) {
...
@@ -12,11 +12,11 @@ const FlowEmitter = function(param = {}) {
FlowEmitter
.
prototype
.
start
=
function
()
{
FlowEmitter
.
prototype
.
start
=
function
()
{
let
that
=
this
;
let
that
=
this
;
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-register`
,
function
(
client
)
{
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-register
shadowlistener
`
,
function
(
client
)
{
that
.
emit
(
'newclient'
,
client
);
that
.
emit
(
'new
shadow
client'
,
client
);
});
});
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-deregister`
,
function
(
client
)
{
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-deregister
shadowlistener
`
,
function
(
client
)
{
that
.
emit
(
'startcountdownreset'
);
that
.
emit
(
'startcountdownreset'
);
});
});
...
@@ -25,6 +25,10 @@ FlowEmitter.prototype.start = function() {
...
@@ -25,6 +25,10 @@ FlowEmitter.prototype.start = function() {
that
.
emit
(
'flowsub'
,
topic
,
client
);
that
.
emit
(
'flowsub'
,
topic
,
client
);
});
});
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-flowunsub`
,
function
(
topic
,
client
)
{
that
.
emit
(
'flowunsub'
,
topic
,
client
);
});
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-flowpub`
,
function
(
topic
,
payload
,
client
)
{
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-flowpub`
,
function
(
topic
,
payload
,
client
)
{
that
.
emit
(
'flowpub'
,
topic
,
payload
,
client
);
that
.
emit
(
'flowpub'
,
topic
,
payload
,
client
);
});
});
...
...
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