AutobahnJS how to correctly unsubscribe?

#1

Hi,

I’m afraid the following might be more of a generic Javascript question than a specific AutobahnJS question. But I thought I should give it a try and ask politely:

I’m using AutobahnJS to visualize measurement data received via different WAMP events. Works pretty good. Sometimes I need to unsubscribe from a topic and instead subscribe to a different topic. For this exercise lets assume I’m switching between the reception of data from two sensors. Furthermore lets assume I have a global variable called sensorSubscription that stores my subscription and is initialized with NULL.

The subscription process works and sensorSubscription becomes a Subscription object. So far so good. The problem now is that after wampSession.unsubscribe(sensorSubscription) I thought that my subscription object is being destroyed and my sensorSubscription variable is becoming NULL again. After I realized that sensorSubscription still references the same Subscription object I checked if it might contain some property that I can use to verify if my subscription is still valid or not (before overwriting it with a new subscription). I found the active property but realized that it’s always set to FALSE. No matter if I unsubscribed or not.

I guess my question is simply how to correctly unsubscribe in AutobahnJS so that I can reuse my sensorSubscription variable for a new subscription.

Many thanks for your help,

Franz

0 Likes

#2

Interesting Franz, could you not just overwrite your subscription var? What happens if you just try and use the car for new assignment?

As to your next question regarding active. I don't know, but maybe active is dependent on the server side for single source of truth. Maybe have a subscriptionCheck topic that will look for active subscription on client and if that succeeds (or doesn't) then go check at the server. A little jankie but would give the whole picture.... Just thinking out loud :grin:

0 Likes

#3

I could indeed overwrite the sensorSubscription variable. But only at the time when I make a new subscription. While there is no new subscription the old object remains kinda orphaned and other components in the program aren’t able to easily verify if this is a valid subscription or not.

I just have the feeling I should invalidate the object somehow and don’t understand why this isn’t done by the unsubscribe process.

···

Am Donnerstag, 14. Juni 2018 16:08:42 UTC+2 schrieb Dave Thomas:

Interesting Franz, could you not just overwrite your subscription var? What happens if you just try and use the car for new assignment?

As to your next question regarding active. I don’t know, but maybe active is dependent on the server side for single source of truth. Maybe have a subscriptionCheck topic that will look for active subscription on client and if that succeeds (or doesn’t) then go check at the server. A little jankie but would give the whole picture… Just thinking out loud :grin:

0 Likes