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
ae98af36
Commit
ae98af36
authored
Jan 29, 2020
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit
parent
cd4bc42f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
3 deletions
+44
-3
coordinator.js
+35
-1
flowemitter.js
+9
-2
No files found.
coordinator.js
View file @
ae98af36
...
@@ -104,11 +104,45 @@ const Coordinator = function(param={}) {
...
@@ -104,11 +104,45 @@ const Coordinator = function(param={}) {
});
});
*/
*/
this
.
flowemitter
.
on
(
'flowpub'
,
function
(
topic
,
payload
,
client
){
console
.
log
(
'client published'
,
client
.
id
);
let
outtopic
,
outmsg
;
let
deviceid
=
client
.
id
;
switch
(
topic
)
{
case
'@shadow/data/update'
:
outtopic
=
`@tap/shadow/update/
${
deviceid
}
:
${
client
.
token
}
`
;
outmsg
=
payload
.
toString
();
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
break
;
case
'@local/shadow/get'
:
outtopic
=
`@tap/shadow/get/
${
deviceid
}
:
${
client
.
token
}
`
;
outmsg
=
payload
.
toString
();
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
break
;
case
'@local/device/get'
:
outtopic
=
`@tap/device/get/
${
deviceid
}
:
${
client
.
token
}
`
;
outmsg
=
payload
.
toString
();
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
break
;
default
:
if
(
topic
.
startsWith
(
'@local/msgout/'
))
{
let
part
=
topic
.
substr
(
14
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
client
.
token
}
/
${
part
}
`
;
outmsg
=
payload
.
toString
();
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
}
}
});
this
.
flowemitter
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
this
.
flowemitter
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
let
deviceid
=
client
.
id
.
split
(
':'
)[
0
];
let
deviceid
=
client
.
id
.
split
(
':'
)[
0
];
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
if
(
topic
.
startsWith
(
'@local/msgin/'
))
{
if
(
topic
.
startsWith
(
'@local/msgin/'
))
{
let
msgpart
=
packet
.
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
let
msgpart
=
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
client
.
token
}
/
${
msgpart
}
`
;
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
client
.
token
}
/
${
msgpart
}
`
;
that
.
remoteclient
.
subscribe
(
outtopic
);
that
.
remoteclient
.
subscribe
(
outtopic
);
}
}
...
...
flowemitter.js
View file @
ae98af36
...
@@ -23,8 +23,15 @@ FlowEmitter.prototype.start = function() {
...
@@ -23,8 +23,15 @@ FlowEmitter.prototype.start = function() {
this
.
red
.
events
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
this
.
red
.
events
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
that
.
emit
(
'flowsub'
,
topic
,
{
that
.
emit
(
'flowsub'
,
topic
,
{
id
:
client
.
clientId
,
id
:
client
.
deviceid
,
token
:
client
.
username
token
:
client
.
devicetoken
});
});
this
.
red
.
events
.
on
(
'flowpub'
,
function
(
topic
,
payload
,
client
)
{
that
.
emit
(
'flowpub'
,
topic
,
payload
,
{
id
:
client
.
deviceid
,
token
:
client
.
devicetoken
});
});
});
});
...
...
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