5 var XMLHttpRequest = require('xmlhttprequest-ssl');
6 var XHR = require('./polling-xhr');
7 var JSONP = require('./polling-jsonp');
8 var websocket = require('./websocket');
14 exports.polling = polling;
15 exports.websocket = websocket;
18 * Polling transport polymorphic constructor.
19 * Decides on xhr vs jsonp based on feature detection.
24 function polling (opts) {
28 var jsonp = false !== opts.jsonp;
30 if (typeof location !== 'undefined') {
31 var isSSL = 'https:' === location.protocol;
32 var port = location.port;
34 // some user agents have empty `location.port`
36 port = isSSL ? 443 : 80;
39 xd = opts.hostname !== location.hostname || port !== opts.port;
40 xs = opts.secure !== isSSL;
45 xhr = new XMLHttpRequest(opts);
47 if ('open' in xhr && !opts.forceJSONP) {
50 if (!jsonp) throw new Error('JSONP disabled');
51 return new JSONP(opts);