| 4913 | */ |
| 4914 | var cache = {}; |
| 4915 | function lookup(uri, opts) { |
| 4916 | if (_typeof(uri) === "object") { |
| 4917 | opts = uri; |
| 4918 | uri = undefined; |
| 4919 | } |
| 4920 | opts = opts || {}; |
| 4921 | var parsed = url(uri, opts.path || "/socket.io"); |
| 4922 | var source = parsed.source; |
| 4923 | var id = parsed.id; |
| 4924 | var path = parsed.path; |
| 4925 | var sameNamespace = cache[id] && path in cache[id]["nsps"]; |
| 4926 | var newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace; |
| 4927 | var io; |
| 4928 | if (newConnection) { |
| 4929 | debug("ignoring socket cache for %s", source); |
| 4930 | io = new Manager(source, opts); |
| 4931 | } else { |
| 4932 | if (!cache[id]) { |
| 4933 | debug("new io instance for %s", source); |
| 4934 | cache[id] = new Manager(source, opts); |
| 4935 | } |
| 4936 | io = cache[id]; |
| 4937 | } |
| 4938 | if (parsed.query && !opts.query) { |
| 4939 | opts.query = parsed.queryKey; |
| 4940 | } |
| 4941 | return io.socket(parsed.path, opts); |
| 4942 | } |
| 4943 | // so that "lookup" can be used both as a function (e.g. `io(...)`) and as a |
| 4944 | // namespace (e.g. `io.connect(...)`), for backward compatibility |
| 4945 | _extends(lookup, { |