6 var XHR = require('./polling-xhr')
7 , JSONP = require('./polling-jsonp')
8 , websocket = require('./websocket')
9 , flashsocket = require('./flashsocket')
10 , util = require('../util');
16 exports.polling = polling;
17 exports.websocket = websocket;
18 exports.flashsocket = flashsocket;
24 var global = 'undefined' != typeof window ? window : global;
27 * Polling transport polymorphic constructor.
28 * Decides on xhr vs jsonp based on feature detection.
33 function polling (opts) {
36 , isXProtocol = false;
38 if (global.location) {
39 var isSSL = 'https:' == location.protocol;
40 var port = location.port;
42 // some user agents have empty `location.port`
43 if (Number(port) != port) {
44 port = isSSL ? 443 : 80;
47 xd = opts.host != location.hostname || port != opts.port;
48 isXProtocol = opts.secure != isSSL;
51 xhr = util.request(xd);
52 /* See #7 at http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx */
53 if (isXProtocol && global.XDomainRequest && xhr instanceof global.XDomainRequest) {
54 return new JSONP(opts);
57 if (xhr && !opts.forceJSONP) {
60 return new JSONP(opts);