From 67fdec20726e48ba3a934cb25bb30d47ec4a4f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20De=20La=20Pe=C3=B1a=20Smirnov?= Date: Wed, 29 Nov 2017 11:44:34 +0300 Subject: Initial commit, version 0.5.3 --- node_modules/socket.io-client/lib/index.js | 94 ++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 node_modules/socket.io-client/lib/index.js (limited to 'node_modules/socket.io-client/lib/index.js') diff --git a/node_modules/socket.io-client/lib/index.js b/node_modules/socket.io-client/lib/index.js new file mode 100644 index 0000000..6bc993c --- /dev/null +++ b/node_modules/socket.io-client/lib/index.js @@ -0,0 +1,94 @@ + +/** + * 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 path = parsed.path; + var sameNamespace = cache[id] && path in cache[id].nsps; + var newConnection = opts.forceNew || opts['force new connection'] || + false === opts.multiplex || sameNamespace; + + var io; + + if (newConnection) { + 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]; + } + if (parsed.query && !opts.query) { + opts.query = parsed.query; + } + return io.socket(parsed.path, opts); +} + +/** + * 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'); -- cgit v1.2.3