Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / components / learnboost-engine.io-client / lib / transports / index.js
1
2 /**
3  * Module dependencies
4  */
5
6 var XHR = require('./polling-xhr')
7   , JSONP = require('./polling-jsonp')
8   , websocket = require('./websocket')
9   , flashsocket = require('./flashsocket')
10   , util = require('../util');
11
12 /**
13  * Export transports.
14  */
15
16 exports.polling = polling;
17 exports.websocket = websocket;
18 exports.flashsocket = flashsocket;
19
20 /**
21  * Global reference.
22  */
23
24 var global = 'undefined' != typeof window ? window : global;
25
26 /**
27  * Polling transport polymorphic constructor.
28  * Decides on xhr vs jsonp based on feature detection.
29  *
30  * @api private
31  */
32
33 function polling (opts) {
34   var xhr
35     , xd = false
36     , isXProtocol = false;
37
38   if (global.location) {
39     var isSSL = 'https:' == location.protocol;
40     var port = location.port;
41
42     // some user agents have empty `location.port`
43     if (Number(port) != port) {
44       port = isSSL ? 443 : 80;
45     }
46
47     xd = opts.host != location.hostname || port != opts.port;
48     isXProtocol = opts.secure != isSSL;
49   }
50
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);
55   }
56
57   if (xhr && !opts.forceJSONP) {
58     return new XHR(opts);
59   } else {
60     return new JSONP(opts);
61   }
62 };