Closed
Description
In our development process, we have to restart the rosbridge quite a lot, and reloading the whole web app every time is a big hassle. So I came up with a way to automatically re-advertise and re-subscribe to topics upon reconnecting to the rosbridge:
function refresh(topics) {
// resend advertise / subscribe messages
// http://robotwebtools.org/jsdoc/roslibjs/current/core_Topic.js.html
for (var i=0; i < topics.length; i++) {
var topic = topics[i];
if (topic.isAdvertised) {
rosBridge.callOnConnection({
op: 'advertise',
id: topic.advertiseId,
type: topic.messageType,
topic: topic.name,
latch: topic.latch,
queue_size: topic.queue_size
});
}
if (topic.subscribeId) {
rosBridge.callOnConnection({
op: 'subscribe',
id: topic.subscribeId,
type: topic.messageType,
topic: topic.name,
compression: topic.compression,
throttle_rate: topic.throttle_rate,
queue_length: topic.queue_length
});
}
}
}
I just keep an array with all the topics I'm using and call refresh(topics)
on close
, which works pretty well. However,
- The refresh function duplicates code from
Topic.js
and I would like to refactor that part asreadvertise
or_advertise
so the same code can be reused. - Unless this is considered an edge case,
Ros
should handle the refresh by keeping a list of all topics and doing an automatic refresh onclose
.
Please let me know what you think. I'd especially appreciate your input regarding naming the functions before I create a PR for (1).
Metadata
Metadata
Assignees
Labels
No labels