Sha256: 956c118739bcdfe12ad3cb3b361b7f3fe5bf31d40d4165c9a8f580a102234333

Contents?: true

Size: 1.47 KB

Versions: 88

Compression:

Stored size: 1.47 KB

Contents

/**
 * Module dependencies.
 */

var url = require('./url');
var parser = require('socket.io-parser');
var Manager = require('./manager');
var debug = require('debug')('socket.io-client');

/**
 * Module exports.
 */

module.exports = exports = lookup;

/**
 * Managers cache.
 */

var cache = exports.managers = {};

/**
 * Looks up an existing `Manager` for multiplexing.
 * If the user summons:
 *
 *   `io('http://localhost/a');`
 *   `io('http://localhost/b');`
 *
 * We reuse the existing instance based on same scheme/port/host,
 * and we initialize sockets for each namespace.
 *
 * @api public
 */

function lookup(uri, opts) {
  if (typeof uri == 'object') {
    opts = uri;
    uri = undefined;
  }

  opts = opts || {};

  var parsed = url(uri);
  var source = parsed.source;
  var id = parsed.id;
  var io;

  if (opts.forceNew || opts['force new connection'] || false === opts.multiplex) {
    debug('ignoring socket cache for %s', source);
    io = Manager(source, opts);
  } else {
    if (!cache[id]) {
      debug('new io instance for %s', source);
      cache[id] = Manager(source, opts);
    }
    io = cache[id];
  }

  return io.socket(parsed.path);
}

/**
 * Protocol version.
 *
 * @api public
 */

exports.protocol = parser.protocol;

/**
 * `connect`.
 *
 * @param {String} uri
 * @api public
 */

exports.connect = lookup;

/**
 * Expose constructors for standalone build.
 *
 * @api public
 */

exports.Manager = require('./manager');
exports.Socket = require('./socket');

Version data entries

88 entries across 88 versions & 2 rubygems

Version Path
flok-0.0.105 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.103 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.102 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
gulp_assets-1.0.0.pre.5 template/node_modules/webpack-dev-server/node_modules/socket.io-client/lib/index.js
gulp_assets-1.0.0.pre.4 template/node_modules/webpack-dev-server/node_modules/socket.io-client/lib/index.js
gulp_assets-1.0.0.pre.3 template/node_modules/webpack-dev-server/node_modules/socket.io-client/lib/index.js
flok-0.0.101 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.100 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.99 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.98 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.97 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.96 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.95 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.94 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.93 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.92 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.91 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.90 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.89 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js
flok-0.0.88 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-client/lib/index.js