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
13c23373
Commit
13c23373
authored
Jul 20, 2021
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use channelID to separate pub/sub group
parent
74489dc2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
11 deletions
+15
-11
flowagent.js
+4
-3
flowemitter.js
+11
-8
No files found.
flowagent.js
View file @
13c23373
...
...
@@ -18,7 +18,7 @@ let FlowAgent = function(option = {}) {
flowagentid
:
option
.
flowagentid
,
flowagentsecret
:
option
.
flowagentsecret
,
red
:
option
.
red
||
null
,
namespace
:
option
.
namespace
channelID
:
option
.
channelID
}
if
(
this
.
option
.
red
)
{
...
...
@@ -36,10 +36,11 @@ let FlowAgent = function(option = {}) {
host
:
that
.
option
.
broker_uri
,
options
:
opt
});
console
.
log
(
'flowagent.js --'
);
console
.
log
(
this
.
option
)
let
flowemitter
=
FlowEmitter
.
create
({
red
:
this
.
option
.
red
,
namespace
:
this
.
option
.
namespace
channelID
:
this
.
option
.
channelID
});
this
.
coordinator
=
Coordinatior
.
create
({
...
...
flowemitter.js
View file @
13c23373
...
...
@@ -6,43 +6,46 @@ const FlowEmitter = function(param = {}) {
this
.
red
=
param
.
red
;
// node-red object
this
.
globalcontext
=
param
.
globalcontext
;
this
.
events
=
new
events
.
EventEmitter
;
this
.
namespace
=
param
.
namespace
;
// namespace is
for communicating with RED.events
this
.
channelID
=
param
.
channelID
;
// channelID is a namespace
for communicating with RED.events
}
FlowEmitter
.
prototype
.
start
=
function
()
{
let
that
=
this
;
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-registershadowlistener`
,
function
(
client
)
{
console
.
log
(
'FlowEmitter--'
)
console
.
log
(
'this.channelID == '
+
that
.
channelID
)
this
.
red
.
events
.
on
(
`
${
that
.
channelID
}
-registershadowlistener`
,
function
(
client
)
{
that
.
emit
(
'registershadowlistener'
,
client
);
});
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-deregistershadowlistener`
,
function
(
client
)
{
this
.
red
.
events
.
on
(
`
${
that
.
channelID
}
-deregistershadowlistener`
,
function
(
client
)
{
that
.
emit
(
'deregistershadowlistener'
,
client
);
//that.emit('startcountdownreset');
});
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-flowsub`
,
function
(
topic
,
client
)
{
this
.
red
.
events
.
on
(
`
${
that
.
channelID
}
-flowsub`
,
function
(
topic
,
client
)
{
//that.devicelist[client.nodeid].msgtopic.push(topic);
that
.
emit
(
'flowsub'
,
topic
,
client
);
});
this
.
red
.
events
.
on
(
`
${
that
.
namespace
}
-flowunsub`
,
function
(
topic
,
client
)
{
this
.
red
.
events
.
on
(
`
${
that
.
channelID
}
-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
.
channelID
}
-flowpub`
,
function
(
topic
,
payload
,
client
)
{
that
.
emit
(
'flowpub'
,
topic
,
payload
,
client
);
});
}
FlowEmitter
.
prototype
.
pub
=
function
(
topic
,
payload
)
{
let
that
=
this
;
this
.
red
.
events
.
emit
(
`
${
that
.
namespace
}
-
${
topic
}
`
,
payload
);
this
.
red
.
events
.
emit
(
`
${
that
.
channelID
}
-
${
topic
}
`
,
payload
);
}
FlowEmitter
.
prototype
.
redemit
=
function
(
eventname
,
data1
,
data2
,
data3
)
{
let
that
=
this
;
this
.
red
.
events
.
emit
(
`
${
that
.
namespace
}
-
${
eventname
}
`
,
data1
,
data2
,
data3
);
this
.
red
.
events
.
emit
(
`
${
that
.
channelID
}
-
${
eventname
}
`
,
data1
,
data2
,
data3
);
}
FlowEmitter
.
prototype
.
on
=
function
(
eventname
,
handler
)
{
...
...
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