Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nrp-frontend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Neurorobotics Platform
nrp-frontend
Commits
b393f8af
Commit
b393f8af
authored
2 years ago
by
Sandro Weber
Browse files
Options
Downloads
Patches
Plain Diff
small fix to subTokensMap entries (no arrays of arrays)
parent
82d33791
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/nrp-core-dashboard/nrp-core-dashboard.js
+6
-3
6 additions, 3 deletions
src/components/nrp-core-dashboard/nrp-core-dashboard.js
src/services/mqtt-client-service.js
+10
-11
10 additions, 11 deletions
src/services/mqtt-client-service.js
with
16 additions
and
14 deletions
src/components/nrp-core-dashboard/nrp-core-dashboard.js
+
6
−
3
View file @
b393f8af
...
...
@@ -21,9 +21,12 @@ export default class NrpCoreDashboard extends React.Component {
console
.
error
(
err
);
}
});
// As a test to make sure MqttClientService can subscribe to multiple topics at once we use these two for testing
let
token
=
MqttClientService
.
instance
.
subscribeToTopic
(
'
test_topic
'
,
(
param1
)
=>
(
console
.
info
(
param1
)));
token
=
MqttClientService
.
instance
.
subscribeToTopic
(
'
test_topic_proto
'
,
(
param1
)
=>
(
console
.
info
(
param1
)));
// As a test to make sure MqttClientService can subscribe to multiple topics (and the same topic) at once
let
token1
=
MqttClientService
.
instance
.
subscribeToTopic
(
'
test_topic
'
,
(
param1
)
=>
(
console
.
info
(
param1
)));
let
token2
=
MqttClientService
.
instance
.
subscribeToTopic
(
'
test_topic
'
,
(
param1
)
=>
(
console
.
info
(
param1
)));
let
token3
=
MqttClientService
.
instance
.
subscribeToTopic
(
'
test_topic
'
,
(
param1
)
=>
(
console
.
info
(
param1
)));
let
token4
=
MqttClientService
.
instance
.
subscribeToTopic
(
'
test_topic_proto
'
,
(
param1
)
=>
(
console
.
info
(
param1
)));
//TODO: test unsubscribe once implemented
}
render
()
{
...
...
This diff is collapsed.
Click to expand it.
src/services/mqtt-client-service.js
+
10
−
11
View file @
b393f8af
...
...
@@ -4,7 +4,6 @@ import { EventEmitter } from 'events';
//import * as proto from 'nrp-jsproto/nrp-engine_msgs-protobuf.js';
//import { DataPackMessage } from 'nrp-jsproto/nrp-engine_msgs-protobuf.js';
import
jspb
from
'
../../node_modules/google-protobuf/google-protobuf
'
;
import
{
hasSubscribers
}
from
'
diagnostics_channel
'
;
let
_instance
=
null
;
const
SINGLETON_ENFORCER
=
Symbol
();
...
...
@@ -20,8 +19,6 @@ export default class MqttClientService extends EventEmitter {
}
this
.
subTokensMap
=
new
Map
();
//console.info(DataPackMessage);
}
static
get
instance
()
{
...
...
@@ -53,11 +50,11 @@ export default class MqttClientService extends EventEmitter {
onMessage
(
topic
,
payload
,
packet
)
{
//console.info('MQTT message: [topic, payload, packet]');
//console.info([topic, payload, packet]);
//Deserializatin of Data must happen here
//Now we see which callbacks have been assigned for a topic
if
(
typeof
this
.
subTokensMap
.
get
(
topic
)
!==
'
undefined
'
)
{
for
(
var
token
in
this
.
subTokensMap
.
get
(
topic
)){
if
(
typeof
token
.
callback
===
'
function
'
&&
payload
!==
'
undefined
'
){
if
(
typeof
token
.
callback
===
'
function
'
&&
payload
!==
'
undefined
'
)
{
//Deserializatin of Data must happen here
token
.
callback
(
payload
);
}
};
...
...
@@ -80,21 +77,23 @@ export default class MqttClientService extends EventEmitter {
}
//callback should have args topic, payload
subscribeToTopic
(
topic
,
callback
=
Function
()){
subscribeToTopic
(
topic
,
callback
)
{
if
(
typeof
callback
!==
'
function
'
)
{
console
.
error
(
'
trying to subscribe to topic "
'
+
topic
+
'
", but no callback function given!
'
);
return
;
}
const
token
=
{
topic
:
topic
,
callback
:
callback
};
if
(
this
.
subTokensMap
.
has
(
token
.
topic
)){
this
.
subTokensMap
.
set
(
token
.
topic
,
[
this
.
subTokensMap
.
get
(
token
.
topic
),
token
]
);
this
.
subTokensMap
.
get
(
token
.
topic
).
push
(
token
);
}
else
{
this
.
subTokensMap
.
set
(
token
.
topic
,
token
[
token
]
);
}
console
.
info
(
'
You have been subscribed to topic
'
+
topic
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment