check for javascript autobahn subscription

#1

Can one determine is a subscription already exists for a topic?
In javascript, I’ve tried the following code:

session.unsubscribe(topic, function);

session.subscribe(topic, function);

weird, yes, but I want to insure that I only have one subscription to a given topic. It would be convenient to run a function like:

if (session.issubscribed(topic) ){

don’t subscribe

} else {

session.subscribe(topic, function);

}

As it is, I find that I subscribe to a function multiple times.

Kind of a related question, if my server doesn’t allow the subscription because of permissions the subscription is silently dropped. I’d like to know all active subscriptions for a javascript client. Is there a way to get a list?

-g

0 Likes

#2

Can one determine is a subscription already exists for a topic?
In javascript, I've tried the following code:

session.unsubscribe(topic, function);
session.subscribe(topic, function);

weird, yes, but I want to insure that I only have one subscription to a
given topic. It would be convenient to run a function like:

if (session.issubscribed(topic) ){
   # don't subscribe
} else {
    session.subscribe(topic, function);
}

AutobahnJS will only emit a WAMP SUBSCRIBE message if no subscription exists yet

https://github.com/tavendo/AutobahnJS/blob/master/autobahn/autobahn.js#L811

and it will only add the event handler to the list of handlers for that subscription if it is not yet therein

https://github.com/tavendo/AutobahnJS/blob/master/autobahn/autobahn.js#L830

If it is, it'll throw an exception.

As it is, I find that I subscribe to a function multiple times.

Do you mean you subscribe to the same topic the same handler function multiple times?

Why do you do that? :wink:

We could have AutobahnJS just silently ignore, instead of throwing an exception. Is that what you want?

Kind of a related question, if my server doesn't allow the subscription
because of permissions the subscription is silently dropped. I'd like

This is solved in WAMPv2, where SUBSCRIBE is part of a request/response exchange, and the subscribing client gets a success acknowledge or an error return.

to know all active subscriptions for a javascript client. Is there a way
to get a list?

Getting a list of subscriptions currently active within a client is currently not in AutobahnJS:

https://github.com/tavendo/AutobahnJS/issues/34

Getting a list of all subscribers on a topic (the WAMP session IDs of all clients subscribed to a topic) is an advanced feature that comes with WAMPv2:

https://github.com/tavendo/WAMP/tree/master/spec#subscriber-list

/Tobias

···

Am 22.01.2014 15:58, schrieb Greg Fausak:

-g

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Likes

#3

Can one determine is a subscription already exists for a topic?

In javascript, I’ve tried the following code:

session.unsubscribe(topic, function);

session.subscribe(topic, function);

weird, yes, but I want to insure that I only have one subscription to a

given topic. It would be convenient to run a function like:

if (session.issubscribed(topic) ){

don’t subscribe

} else {

session.subscribe(topic, function);

}

AutobahnJS will only emit a WAMP SUBSCRIBE message if no subscription
exists yet

https://github.com/tavendo/AutobahnJS/blob/master/autobahn/autobahn.js#L811

and it will only add the event handler to the list of handlers for that
subscription if it is not yet therein

https://github.com/tavendo/AutobahnJS/blob/master/autobahn/autobahn.js#L830

If it is, it’ll throw an exception.

I get that. There is only one real subscription between the browser and the server for a specific topic. When the browser adds a second subscription internally that piggybacks on the first one.

As it is, I find that I subscribe to a function multiple times.

Do you mean you subscribe to the same topic the same handler function
multiple times?

Why do you do that? :wink:

Stupid, I guess!

We could have AutobahnJS just silently ignore, instead of throwing an
exception. Is that what you want?

No, an exception would be good. I’m not getting that. Instead, if I subscribe twice to the same topic with the same handler, the handler is called twice. I think it is a basic utilitarian need. What am I subscribed to? What can I subscribe to? What rpc methods can I call?

I’ve tried a sequence:

unsubscribe(topic, handler)

subscribe(topic, handler)

in the hopes that if I am already subscribed I’ll unsubscribe first. That doesn’t seem to work (although I haven’t put much time into it yet).

Kind of a related question, if my server doesn’t allow the subscription

because of permissions the subscription is silently dropped. I’d like

This is solved in WAMPv2, where SUBSCRIBE is part of a request/response
exchange, and the subscribing client gets a success acknowledge or an
error return.

cool.

thanks,

-g

···

On Thursday, January 23, 2014 5:03:07 AM UTC-6, Tobias Oberstein wrote:

Am 22.01.2014 15:58, schrieb Greg Fausak:

to know all active subscriptions for a javascript client. Is there a way

to get a list?

Getting a list of subscriptions currently active within a client is
currently not in AutobahnJS:

https://github.com/tavendo/AutobahnJS/issues/34

Getting a list of all subscribers on a topic (the WAMP session IDs of
all clients subscribed to a topic) is an advanced feature that comes
with WAMPv2:

https://github.com/tavendo/WAMP/tree/master/spec#subscriber-list

/Tobias

-g

You received this message because you are subscribed to the Google

Groups “Autobahn” group.

To unsubscribe from this group and stop receiving emails from it, send

an email to autobahnws+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

0 Likes

#4

    Do you mean you subscribe to the same topic the same handler function
    multiple times?

    Why do you do that? :wink:

Stupid, I guess!

    We could have AutobahnJS just silently ignore, instead of throwing an
    exception. Is that what you want?

No, an exception would be good. I'm not getting that. Instead, if I
subscribe twice to the same topic with the same handler, the handler is
called twice. I think it is a basic utilitarian need. What am I

Consider the following 2 code snippets:

Variant 1:

function myhandler(topic, event) {
   // .. event handler code for topic http://myapp.com/mytopic
}

session.subscribe("http://myapp.com/mytopic1", myhandler);

// this _should_ throw an exception ..
session.subscribe("http://myapp.com/mytopic1", myhandler);

Variant 2:

session.subscribe("http://myapp.com/mytopic1", function (topic, event) {
   // .. event handler code for topic http://myapp.com/mytopic
});

// this will NOT throw an exception, since the anonymous event
// handler function is _different_ from the above
session.subscribe("http://myapp.com/mytopic1", function (topic, event) {
   // .. event handler code for topic http://myapp.com/mytopic
});

···

==

If you say you don't get an exception with Variant 2, that's expected. We cannot detect this.

If you say you don't get an exception with Variant 1, that would be unexpected ..

subscribed to? What can I subscribe to? What rpc methods can I call?

I can see what you mean. And I agree that it'll be useful.

This is a piece of the puzzle which WAMPv2 calls "reflection":

https://github.com/tavendo/WAMP/tree/master/spec#reflection

This is unfinished stuff. And it will be an "advanced" feature that depends on specific WAMPv2 broker/dealer support.

If you have ideas/wishes/requirements in this area, that would be interesting to hear! Either via mailing list here, or file an issue against the WAMP repo on GitHub and comment there ..

I've tried a sequence:

unsubscribe(topic, handler)
subscribe(topic, handler)

in the hopes that if I am already subscribed I'll unsubscribe first.
  That doesn't seem to work (although I haven't put much time into it yet).

     >
     > Kind of a related question, if my server doesn't allow the
    subscription
     > because of permissions the subscription is silently dropped. I'd
    like

    This is solved in WAMPv2, where SUBSCRIBE is part of a request/response
    exchange, and the subscribing client gets a success acknowledge or an
    error return.

cool.
thanks,

-g

     > to know all active subscriptions for a javascript client. Is
    there a way
     > to get a list?

    Getting a list of subscriptions currently active within a client is
    currently not in AutobahnJS:

    https://github.com/tavendo/AutobahnJS/issues/34
    <https://github.com/tavendo/AutobahnJS/issues/34>

    Getting a list of all subscribers on a topic (the WAMP session IDs of
    all clients subscribed to a topic) is an advanced feature that comes
    with WAMPv2:

    https://github.com/tavendo/WAMP/tree/master/spec#subscriber-list
    <https://github.com/tavendo/WAMP/tree/master/spec#subscriber-list>

    /Tobias

     >
     > -g
     >
     > --
     > You received this message because you are subscribed to the Google
     > Groups "Autobahn" group.
     > To unsubscribe from this group and stop receiving emails from it,
    send
     > an email to autobah...@googlegroups.com <javascript:>.
     > For more options, visit https://groups.google.com/groups/opt_out
    <https://groups.google.com/groups/opt_out>.

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Likes