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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
6 deletions
+47
-6
coordinator.js
+40
-3
flowemitter.js
+7
-3
No files found.
coordinator.js
View file @
beb2058d
...
...
@@ -12,6 +12,8 @@ const Coordinator = function(param={}) {
let
that
=
this
;
let
resettimer
=
0
;
this
.
topicstore
=
require
(
'./topicstore'
).
create
();
this
.
x
=
0
;
this
.
started
=
false
;
...
...
@@ -20,19 +22,34 @@ const Coordinator = function(param={}) {
this
.
mqttclient
=
param
.
mqttclient
;
this
.
flowemitter
=
param
.
flowemitter
||
null
;
this
.
flowemitter
.
on
(
'newclient'
,
function
(
client
){
this
.
flowemitter
.
on
(
'new
shadow
client'
,
function
(
client
){
let
deviceid
=
client
.
deviceid
;
let
devicetoken
=
client
.
devicetoken
;
console
.
log
that
.
mqttclient
.
subscribe
(
`@tap/shadow/updated/
${
deviceid
}
:
${
devicetoken
}
`
);
that
.
mqttclient
.
subscribe
(
`@tap/device/changed/
${
deviceid
}
:
${
devicetoken
}
`
);
if
(
DEBUG_SUBLIST
)
{
console
.
log
(
`\nshadow client #
${
deviceid
}
connected -->`
)
console
.
log
(
that
.
flowemitter
.
sublist
);
//
console.log(`\nshadow client #${deviceid} connected -->`)
//
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
){
let
outtopic
,
outmsg
;
let
deviceid
=
client
.
deviceid
;
...
...
@@ -65,14 +82,34 @@ const Coordinator = function(param={}) {
this
.
flowemitter
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
console
.
log
(
client
.
nodeid
+
' flowsub --> '
+
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
.
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
{
}
...
...
flowemitter.js
View file @
beb2058d
...
...
@@ -12,11 +12,11 @@ const FlowEmitter = function(param = {}) {
FlowEmitter
.
prototype
.
start
=
function
()
{
let
that
=
this
;
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-register`
,
function
(
client
)
{
that
.
emit
(
'newclient'
,
client
);
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-register
shadowlistener
`
,
function
(
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'
);
});
...
...
@@ -25,6 +25,10 @@ FlowEmitter.prototype.start = function() {
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
)
{
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