crossbario / autobahn-js

WAMP in JavaScript for Browsers and NodeJS
http://crossbar.io/autobahn
MIT License
1.44k stars 230 forks source link

Use other transports as fallback #191

Open herm opened 8 years ago

herm commented 8 years ago

My WAMP router is running at home behind a DS-Lite cable modem (i.e. I only have an external IPv6 address, but no IPv4). I use Cloudflare to proxy IPv4 to IPv6. However it does not support websockets. Therefore I use longpoll as a secondary transport.

Currently autobahn tries to use the websocket transport because it is the first one in the list and then tries this transport again and again without ever going to the second option.

There should be an option to try all transports. This could also be used as a fallback mechanism. If one WAMP router is not reachable the app automatically tries connecting to the next one.

oberstet commented 8 years ago

Yes, definitely. However, different retry/reconnect strategies are conceivable here. Eg try 5x WebSocket, and then continue with next transport, cycle infinitely through list, or try each one only once per move, or differentiate between whether the connection succeeded in the past at least once or never worked etc etc

Hence, a good start would be a parametrized fallback/retry/reconnect strategy that works for the 80% (or more) cases.

jremmurd commented 7 years ago

Any updates concerning the fallback enhancement?

markerikson commented 7 years ago

Bumping this request. Would love to see this functionality.

Skimming through the code, I'm not even sure that additional transports even get meaningfully used at all. I do see a couple places that loop through options.transports, but the code in connection.js does this:

Connection.prototype._create_transport = function () {
   for (var i = 0; i < this._transport_factories.length; ++i) {
      var transport_factory = this._transport_factories[i];
      log.debug("trying to create WAMP transport of type: " + transport_factory.type);
      try {
         var transport = transport_factory.create();
         if (transport) {

It looks like the Websocket transport always returns an object, so that check will always be true when trying a Websocket transport, and it never will fall back to any others.

oberstet commented 5 years ago

ok, we're finally getting to fix this. I added an example (which currently fails to behave as intended .. because of this bug):