Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define transport types on the client side

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?

like image 562
Wei An Avatar asked Aug 10 '11 18:08

Wei An


2 Answers

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']
});
like image 69
Bruno Gagnon-Adam Avatar answered Nov 15 '22 19:11

Bruno Gagnon-Adam


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);....

like image 44
bronze Avatar answered Nov 15 '22 21:11

bronze