"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Socket = exports.io = exports.Manager = exports.protocol = void 0; const url_1 = require("./url"); const manager_1 = require("./manager"); const socket_1 = require("./socket"); Object.defineProperty(exports, "Socket", { enumerable: true, get: function () { return socket_1.Socket; } }); const debug = require("debug")("socket.io-client"); /** * Module exports. */ module.exports = exports = lookup; /** * Managers cache. */ const cache = (exports.managers = {}); function lookup(uri, opts) { if (typeof uri === "object") { opts = uri; uri = undefined; } opts = opts || {}; const parsed = url_1.url(uri); const source = parsed.source; const id = parsed.id; const path = parsed.path; const sameNamespace = cache[id] && path in cache[id].nsps; const newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace; let io; if (newConnection) { debug("ignoring socket cache for %s", source); io = new manager_1.Manager(source, opts); } else { if (!cache[id]) { debug("new io instance for %s", source); cache[id] = new manager_1.Manager(source, opts); } io = cache[id]; } if (parsed.query && !opts.query) { opts.query = parsed.query; } return io.socket(parsed.path, opts); } exports.io = lookup; /** * Protocol version. * * @public */ var socket_io_parser_1 = require("socket.io-parser"); Object.defineProperty(exports, "protocol", { enumerable: true, get: function () { return socket_io_parser_1.protocol; } }); /** * `connect`. * * @param {String} uri * @public */ exports.connect = lookup; /** * Expose constructors for standalone build. * * @public */ var manager_2 = require("./manager"); Object.defineProperty(exports, "Manager", { enumerable: true, get: function () { return manager_2.Manager; } });