11

I need to use jsonp-polling for IE, and xhr-polling for Firefox, so I tried to define types of transports on the client side like this:

    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits); 
            var socket = io.connect(VG.NODE_SERVER_URL,{ 
                    transports:['xhr-polling'] 
            }); 
    } else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
            var socket = io.connect(VG.NODE_SERVER_URL,{ 
                    transports:['jsonp-polling'] 
            }); 
    } else { 
            var socket = io.connect(VG.NODE_SERVER_URL); 
    }

I tested it on Firefox and added logging on socket.io-client lib. At

https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1509

the option.transports is ["xhr-polling", "flashsocket", "htmlfile", "xhr-polling", "jsonp-polling"], which is right. However, at

https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1679

I do not know why the transports change to ["htmlfile", "jsonp- polling", "xhr-polling"], which has the same sequence as what I defined on server side.

Why doesn't it use the previous option?

Wei An
  • 1,779
  • 4
  • 13
  • 18
  • Not sure what the question is here, is that the given the sequence - `xhr-polling`, etc, above is ignored and instead `htmlfile` goes first? Does this issue replicate with socket.io `0.8.7`? – First Zero Jan 08 '12 at 16:30
  • Thank you for you question! It was answer for my nightmare with FireFox. Socket.io documentation is so bad.. It's the only place I found transport options. :) – Lukas Liesis Jun 18 '15 at 18:49

2 Answers2

19

The bug is now fixed in socket.io version 0.9.6, I can use this and it works fine :

socket = io.connect(HOST_REMOTE, {
    transports: ['xhr-polling']
});

In version 1.0.0 and above:

socket = io.connect(HOST_REMOTE, {
    transports: ['polling']
});
oLeduc
  • 313
  • 1
  • 12
1

there is a bug in socket.io.client.

so you can not set transports in client...

function Socket (options) {
this.options = {
    port: 80
  , secure: false
....
};

io.util.merge(this.options, options);
....
};

should be io.util.merge(this.options, options,0);....

bronze
  • 11
  • 1