blob: 374620b0001966fc4aa642bafa1cac7b6ef069ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/**
* Module dependencies
*/
var XHR = require('./polling-xhr')
, JSONP = require('./polling-jsonp')
, websocket = require('./websocket')
, flashsocket = require('./flashsocket')
, util = require('../util');
/**
* Export transports.
*/
exports.polling = polling;
exports.websocket = websocket;
exports.flashsocket = flashsocket;
/**
* Global reference.
*/
var global = 'undefined' != typeof window ? window : global;
/**
* Polling transport polymorphic constructor.
* Decides on xhr vs jsonp based on feature detection.
*
* @api private
*/
function polling (opts) {
var xhr
, xd = false
, isXProtocol = false;
if (global.location) {
var isSSL = 'https:' == location.protocol;
var port = location.port;
// some user agents have empty `location.port`
if (Number(port) != port) {
port = isSSL ? 443 : 80;
}
xd = opts.host != location.hostname || port != opts.port;
isXProtocol = opts.secure != isSSL;
}
xhr = util.request(xd);
/* See #7 at http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx */
if (isXProtocol && global.XDomainRequest && xhr instanceof global.XDomainRequest) {
return new JSONP(opts);
}
if (xhr && !opts.forceJSONP) {
return new XHR(opts);
} else {
return new JSONP(opts);
}
};
|