v-kiniv / rws

WebSocket gateway for ROS2 topics and services
Apache License 2.0
8 stars 4 forks source link

Doing unsubscribe unsubscribes all subscribers for a topic #6

Closed aroxenhag closed 9 months ago

aroxenhag commented 10 months ago

I've noticed a difference in behavior of rws compared to rosbridge when using subscriptions through roslibjs. With rosbridge, if I subscribe to the same topic from two places and unsubscribe once, I still get messages to the remaining subscriber. With rws, this is not the case. It appears rosbridge keeps track of the ids of the subscribers and does not kill the ros subscription until all subscribers of a topic have unsubscribed.

Looking at the ROSLIB.Topic object created it seems it has a concept subscribeId: "subscribe:/echoer/int32:805" with a number at the end, unique to each subscriber. When calling subscribe, this is passed to the bridge as

{"op":"subscribe","id":"subscribe:/echoer/int32:805","type":"std_msgs/msg/Int32","topic":"/echoer/int32","compression":"none","throttle_rate":0,"queue_length":0}

While one might argue keeping track of this should be done in roslibjs rather than in the bridge, that's how it works today and it would be nice to be able to use roslibjs with rws as is.

v-kiniv commented 10 months ago

I have no experience with roslibjs, can you explain a bit why one client might want to subscribe to the same topic multiple times? Although I believe that a client should subscribe to the same topic once, I agree that it would be better to reflect the original behavior of rosbridge.

aroxenhag commented 10 months ago

E.g. you might have a dashboard with a gauge showing a momentary value and a chart plotting the value over time, both listening to the same topic. They'd work independently of each other, not knowing if there are other subscribers to the topic.

v-kiniv commented 10 months ago

This sounds to me like, as you mentioned, a task for the client library to manage. It can be fixed at application level if you still want to use rws, so I prefer not to add unnecessary complexity to the server.

aroxenhag commented 9 months ago

Actually roslibjs supported unsubscribe with the specific callback as argument so we were able to do that and let roslibjs keep track of if there were any remaining listeners or if it should issue an unsubscribe to the bridge.