arnaucube
arnaucube/comunicationLeapPublic Self-hosted repository
comunicationLeap/node_modules/engine.io-client/lib/transports/index.js
node_modules/engine.io-client/lib/transports/index.jsRaw
 1/**
 2 * Module dependencies
 3 */
 4
 5var XMLHttpRequest = require('xmlhttprequest');
 6var XHR = require('./polling-xhr');
 7var JSONP = require('./polling-jsonp');
 8var websocket = require('./websocket');
 9
10/**
11 * Export transports.
12 */
13
14exports.polling = polling;
15exports.websocket = websocket;
16
17/**
18 * Polling transport polymorphic constructor.
19 * Decides on xhr vs jsonp based on feature detection.
20 *
21 * @api private
22 */
23
24function polling(opts){
25  var xhr;
26  var xd = false;
27  var xs = false;
28  var jsonp = false !== opts.jsonp;
29
30  if (global.location) {
31    var isSSL = 'https:' == location.protocol;
32    var port = location.port;
33
34    // some user agents have empty `location.port`
35    if (!port) {
36      port = isSSL ? 443 : 80;
37    }
38
39    xd = opts.hostname != location.hostname || port != opts.port;
40    xs = opts.secure != isSSL;
41  }
42
43  opts.xdomain = xd;
44  opts.xscheme = xs;
45  xhr = new XMLHttpRequest(opts);
46
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}