Skip to content

Topics don't support reconnect #246

Closed
@stepmuel

Description

@stepmuel

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,

  1. The refresh function duplicates code from Topic.js and I would like to refactor that part as readvertise or _advertise so the same code can be reused.
  2. Unless this is considered an edge case, Ros should handle the refresh by keeping a list of all topics and doing an automatic refresh on close.

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions