Is there possibility to subscribe before connect?

48 views
Skip to first unread message

Michal Lohniský

unread,
Oct 29, 2014, 12:06:53 PM10/29/14
to autob...@googlegroups.com
Hello,

I use the JS implementation like this:

<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>
<script>
 
var conn = new ab.Session('ws://localhost:8080',
   
function() {
     conn
.subscribe('kittensCategory', function(topic, data) {
       
// This is where you would add the new article to the DOM (beyond the scope of this tutorial)
       console
.log('New article published to category "' + topic + '" : ' + data.title);
     
});
   
},
   
function() {
     console
.warn('WebSocket connection closed');
   
}
 
);
</script>

Is there any possibility to do this:

 conn.subscribe('kittensCategory', function(topic, data) {

without error "Autobahn not connected"?

I would suggest to change the function ab.Session.prototype.subscribe in this way (pseudo code):
if (! is_connected) {
  self.before_connect_subscribe_data.push(subscribe_data);
} else {
  // normal subscribe
}


And then change the function ab.Session in this way (pseudo code):
before calling
self._websocket_onopen();
do
foreach (self.before_connect_subscribe_data as data) {
   do_subscribe(data);
}


Is my suggestion clear?

Thanks,
Michal

Tobias Oberstein

unread,
Oct 29, 2014, 1:43:32 PM10/29/14
to autob...@googlegroups.com
Hi,

> And then change the function ab.Session in this way (pseudo code):
> before calling
> self._websocket_onopen();
> do
> foreach (self.before_connect_subscribe_data as data) {
> do_subscribe(data);
> }
>
> Is my suggestion clear?

Yes, but:

1) AutobahnJS/WAMP1 (the version that is mentioned above) is no longer
maintained. No changes will be applied to that code base anymore.
2) What's the point adding complexity when you just can subscribe when
connected?

Cheers,
/Tobias


>
> Thanks,
> Michal
>
> --
> 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
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/11bb13ad-04cb-4c41-bbd7-c7d08a10d0f6%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/11bb13ad-04cb-4c41-bbd7-c7d08a10d0f6%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Michal Lohniský

unread,
Oct 29, 2014, 3:30:54 PM10/29/14
to autob...@googlegroups.com

Is there any other JS version suitable for usage with PHP server (like Ratchet)?

I would like to provide the session as service in window object. Now I have to specify all subscriptions (which I want to do immediately) in the onconnect callback. After implementation of my suggestion I could use
conn.subscribe('kittensCategory', ...
anywhere and it would send the subscription in first possible moment.
Or is there a workaroud with which I could use conn.subscribe anywhere on different places? (For example use conn.onload(function(){}) multiple times and even after success connection?)


Dne středa, 29. října 2014 18:43:32 UTC+1 Tobias Oberstein napsal(a):
Hi,

> And then change the function ab.Session in this way (pseudo code):
> before calling
> self._websocket_onopen();
> do
> foreach (self.before_connect_subscribe_data as data) {
>     do_subscribe(data);
> }
>
> Is my suggestion clear?

Yes, but:

1) AutobahnJS/WAMP1 (the version that is mentioned above) is no longer
maintained. No changes will be applied to that code base anymore.
2) What's the point adding complexity when you just can subscribe when
connected?

Cheers,
/Tobias


>
> Thanks,
> Michal
>
> --
> 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

Tobias Oberstein

unread,
Oct 30, 2014, 7:25:12 PM10/30/14
to autob...@googlegroups.com
Hi Michal,

Am 29.10.2014 20:30, schrieb Michal Lohniský:
>
> Is there any other JS version suitable for usage with PHP server (like
> Ratchet)?

Have a look at Thruway:

https://github.com/voryx/Thruway

This is a WAMP v2 implementation that works with the latest AutobahnJS.
It is actively maintained and developed.

It is both a WAMP client implementation (allows you to write app
components), and also includes a router.

It also works like a charm with Crossbar.io:

http://crossbar.io/docs/Getting-started-with-PHP/

>
> I would like to provide the session as service in window object. Now I
> have to specify all subscriptions (which I want to do immediately) in
> the onconnect callback. After implementation of my suggestion I could use
> ||conn.subscribe('kittensCategory', ...
> ||anywhere and it would send the subscription in first possible moment.||
> ||Or is there a workaroud with which I could use conn.subscribe anywhere
> on different places? (For example use conn.onload(function(){}) multiple
> times and even after success connection?)

This is not how it works today, and to be honest, I don't see the point
of being able to subscribe when there is no connection at all. I think
it's a road to spaghetti / headaches ..

But hey, it's open-source: hack it! Probably I just don't get it yet ..

Cheers,
/Tobias


>
>
> Dne středa, 29. října 2014 18:43:32 UTC+1 Tobias Oberstein napsal(a):
>
> Hi,
>
> > And then change the function ab.Session in this way (pseudo code):
> > before calling
> > self._websocket_onopen();
> > do
> > foreach (self.before_connect_subscribe_data as data) {
> > do_subscribe(data);
> > }
> >
> > Is my suggestion clear?
>
> Yes, but:
>
> 1) AutobahnJS/WAMP1 (the version that is mentioned above) is no longer
> maintained. No changes will be applied to that code base anymore.
> 2) What's the point adding complexity when you just can subscribe when
> connected?
>
> Cheers,
> /Tobias
>
>
> >
> > Thanks,
> > Michal
> >
> > --
> > 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 <javascript:>
> > <mailto:autobahnws+...@googlegroups.com <javascript:>>.
> > To post to this group, send email to autob...@googlegroups.com
> <javascript:>
> > <mailto:autob...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/autobahnws/11bb13ad-04cb-4c41-bbd7-c7d08a10d0f6%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/optout>.
>
> --
> 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
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/531c4004-775f-49cc-b861-18e986515923%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/531c4004-775f-49cc-b861-18e986515923%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages