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
d176edea
Commit
d176edea
authored
Dec 03, 2019
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use different topic on @msg pub and sub
parent
9c029cc7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
coordinator.js
+20
-10
No files found.
coordinator.js
View file @
d176edea
...
...
@@ -7,7 +7,7 @@ const cache = require('./cache');
const
Coordinator
=
function
(
param
=
{})
{
let
that
=
this
;
//console.log(param)
this
.
remoteclient
=
param
.
remoteclient
;
this
.
localserver
=
param
.
localserver
;
...
...
@@ -59,8 +59,14 @@ const Coordinator = function(param={}) {
this
.
localserver
.
on
(
'clientSubscribed'
,
function
(
packet
,
client
)
{
let
deviceid
=
client
.
id
.
split
(
':'
)[
0
];
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
if
(
packet
.
topic
.
startsWith
(
'@msg/'
))
{
let
msgpart
=
packet
.
topic
.
split
(
'/'
).
splice
(
3
).
join
(
'/'
);
// if (packet.topic.startsWith('@msg/')) {
// let msgpart = packet.topic.split('/').splice(3).join('/');
// outtopic = `@tap/msg/topic/${deviceid}:${client.token}/${msgpart}`;
// that.remoteclient.subscribe(outtopic);
// }
if
(
packet
.
topic
.
startsWith
(
'@local/msgin/'
))
{
let
msgpart
=
packet
.
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
client
.
token
}
/
${
msgpart
}
`
;
that
.
remoteclient
.
subscribe
(
outtopic
);
}
...
...
@@ -92,8 +98,14 @@ const Coordinator = function(param={}) {
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
break
;
default
:
if
(
packet
.
topic
.
startsWith
(
'@msg/'
))
{
let
part
=
packet
.
topic
.
substr
(
5
);
// if (packet.topic.startsWith('@msg/')) {
// let part = packet.topic.substr(5);
// outtopic = `@tap/msg/topic/${deviceid}:${client.token}/${part}`;
// outmsg = packet.payload.toString();
// that.remoteclient.publish(outtopic, outmsg);
// }
if
(
packet
.
topic
.
startsWith
(
'@local/msgout/'
))
{
let
part
=
packet
.
topic
.
substr
(
14
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
client
.
token
}
/
${
part
}
`
;
outmsg
=
packet
.
payload
.
toString
();
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
...
...
@@ -108,7 +120,6 @@ const Coordinator = function(param={}) {
setTimeout
(
function
()
{
for
(
let
deviceid
in
that
.
localserver
.
sublist
)
{
//console.log(deviceid, that.localserver.sublist[deviceid])
that
.
remoteclient
.
subscribe
(
`@tap/shadow/updated/
${
deviceid
}
:
${
that
.
localserver
.
sublist
[
deviceid
].
token
}
`
);
that
.
remoteclient
.
subscribe
(
`@tap/device/changed/
${
deviceid
}
:
${
that
.
localserver
.
sublist
[
deviceid
].
token
}
`
);
...
...
@@ -144,10 +155,9 @@ const Coordinator = function(param={}) {
that
.
localserver
.
publish
(
`
${
jsonpayload
.
deviceid
}
/device/get`
,
JSON
.
stringify
(
jsonpayload
));
}
else
if
(
topic
.
startsWith
(
'@msg/'
))
{
console
.
log
(
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
)
console
.
log
({
topic
,
payload
})
that
.
localserver
.
publish
(
topic
,
payload
);
let
part
=
topic
.
split
(
'/'
).
splice
(
1
).
join
(
'/'
);
let
localtopic
=
`@local/msgin/
${
part
}
`
;
that
.
localserver
.
publish
(
localtopic
,
payload
);
}
});
}
...
...
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