]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - example/iot-gateway/node_modules/engine.io-client/lib/transports/index.js
Initial commit
[apps/tidep0084.git] / example / iot-gateway / node_modules / engine.io-client / lib / transports / index.js
1 /**
2  * Module dependencies
3  */
5 var XMLHttpRequest = require('xmlhttprequest-ssl');
6 var XHR = require('./polling-xhr');
7 var JSONP = require('./polling-jsonp');
8 var websocket = require('./websocket');
10 /**
11  * Export transports.
12  */
14 exports.polling = polling;
15 exports.websocket = websocket;
17 /**
18  * Polling transport polymorphic constructor.
19  * Decides on xhr vs jsonp based on feature detection.
20  *
21  * @api private
22  */
24 function polling(opts){
25   var xhr;
26   var xd = false;
27   var xs = false;
28   var jsonp = false !== opts.jsonp;
30   if (global.location) {
31     var isSSL = 'https:' == location.protocol;
32     var port = location.port;
34     // some user agents have empty `location.port`
35     if (!port) {
36       port = isSSL ? 443 : 80;
37     }
39     xd = opts.hostname != location.hostname || port != opts.port;
40     xs = opts.secure != isSSL;
41   }
43   opts.xdomain = xd;
44   opts.xscheme = xs;
45   xhr = new XMLHttpRequest(opts);
47   if ('open' in xhr && !opts.forceJSONP) {
48     return new XHR(opts);
49   } else {
50     if (!jsonp) throw new Error('JSONP disabled');
51     return new JSONP(opts);
52   }
53 }