connection.isRetrying not working for me (sort of)

51 views
Skip to first unread message

Greg Fausak

unread,
Nov 21, 2014, 8:43:37 AM11/21/14
to autob...@googlegroups.com
I have the javascript code:

var connection = new autobahn.Connection({
         url: '%s',
         realm: '%s'
      });

connection.onclose = function (session) {
    console.log('Session to database closed');
    if(connection.isRetrying == true) {
        document.getElementById("info").innerHTML = '<p>Autobahn Connection Closed (retrying)</p>';
    } else {
        document.getElementById("info").innerHTML = '<p>Autobahn Connection Closed (forever)</p>';
    };
};

I tried to debug this for a while.  I was just killing the router, which triggered the onclose. The problem I was seeing was my javascript was picking up connection.isRetrying == false.

It appears that when the connection first goes down, isRetrying is false.  Then, after the first retry, isRetrying is true. What is the proper way to determine if my connection will be retried?

-g

Tobias Oberstein

unread,
Nov 21, 2014, 4:32:59 PM11/21/14
to autob...@googlegroups.com
Hi Greg,

try:

connection.onclose = function (details) {
   console.log(details.will_retry);
}

You can also (manually) stop automatic retrying by returning true from above handler.

Cheers,
/Tobias

Greg Fausak

unread,
Nov 23, 2014, 9:31:09 AM11/23/14
to autob...@googlegroups.com
Tobias,

I tried the following code:

connection.onclose = function (details) {

    console.log('will_retry ', details.will_retry);

...

Here is the console log for that message:

will_retry  undefined 

Maybe my autobahn.min.js file is old?



-g

Greg Miller

unread,
Nov 23, 2014, 9:48:25 AM11/23/14
to autob...@googlegroups.com
I get 'true', with version 0.9.5.

Greg Fausak

unread,
Nov 23, 2014, 10:21:29 AM11/23/14
to autob...@googlegroups.com
That's weird.

When I just log the value of 'details' I get 'lost', like details is just a string.

The source ...

         // fire app code handler
         //
         if (self.onclose) {
            var details = {
               reason: self._session_close_reason,
               message: self._session_close_message,
               retry_delay: next_retry.delay,
               retry_count: next_retry.count,
               will_retry: next_retry.will_retry
            };
            try {
               // Connection.onclose() allows to cancel any subsequent retry attempt
               var stop_retrying = self.onclose(reason, details);
            } catch (e) {
               log.debug("Exception raised from app code while firing Connection.onclose()", e);
            }
         }
 
So I had the function declared with one argument(details) instead of two (reason,details).

-g

Greg Miller

unread,
Nov 23, 2014, 11:28:32 AM11/23/14
to autob...@googlegroups.com
I just have:

connection.onclose = function (reason, details) {
  console
.log(details.will_retry)
  console
.log("Connection lost: " + reason);
}


Greg Fausak

unread,
Nov 23, 2014, 2:11:52 PM11/23/14
to autob...@googlegroups.com
that's what it was, my code:

connection.onclose = function (details) {

    console.log('will_retry ', details.will_retry);


did not declare the first argument.


thx,

-g



--
You received this message because you are subscribed to a topic in the Google Groups "Autobahn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/HLTL9jzXENE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/e260c81a-af6e-458c-833a-abf91939e051%40googlegroups.com.

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



--
Reply all
Reply to author
Forward
0 new messages