在客户端定义传输types

我需要使用IE的jsonp-polling和Firefox的xhr-polling,所以我试图在客户端定义传输types,如下所示:

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/xx or Firefox xx (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); } 

我在Firefox上testing了它,并在socket.io-client lib上添加了日志logging。 在

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

option.transports是["xhr-polling", "flashsocket", "htmlfile", "xhr-polling", "jsonp-polling"] ,这是正确的。 但是,在

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

我不知道为什么传输会变成["htmlfile", "jsonp- polling", "xhr-polling"] ,它与我在服务器端定义的序列相同。

为什么不使用以前的选项?

这个bug现在已经在socket.io 0.9.6版本中解决了,我可以使用它,它工作正常:

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

在版本1.0.0及以上:

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

在socket.io.client中有一个错误。

所以你不能在客户端设置传输…

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

应该是io.util.merge(this.options, options,0);....