* 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
(uri, opts)
| 93 | */ |
| 94 | |
| 95 | function lookup(uri, opts) { |
| 96 | if ((typeof uri === 'undefined' ? 'undefined' : _typeof(uri)) === 'object') { |
| 97 | opts = uri; |
| 98 | uri = undefined; |
| 99 | } |
| 100 | |
| 101 | opts = opts || {}; |
| 102 | |
| 103 | var parsed = url(uri); |
| 104 | var source = parsed.source; |
| 105 | var id = parsed.id; |
| 106 | var path = parsed.path; |
| 107 | var sameNamespace = cache[id] && path in cache[id].nsps; |
| 108 | var newConnection = opts.forceNew || opts['force new connection'] || false === opts.multiplex || sameNamespace; |
| 109 | |
| 110 | var io; |
| 111 | |
| 112 | if (newConnection) { |
| 113 | debug('ignoring socket cache for %s', source); |
| 114 | io = Manager(source, opts); |
| 115 | } else { |
| 116 | if (!cache[id]) { |
| 117 | debug('new io instance for %s', source); |
| 118 | cache[id] = Manager(source, opts); |
| 119 | } |
| 120 | io = cache[id]; |
| 121 | } |
| 122 | if (parsed.query && !opts.query) { |
| 123 | opts.query = parsed.query; |
| 124 | } else if (opts && 'object' === _typeof(opts.query)) { |
| 125 | opts.query = encodeQueryString(opts.query); |
| 126 | } |
| 127 | return io.socket(parsed.path, opts); |
| 128 | } |
| 129 | /** |
| 130 | * Helper method to parse query objects to string. |
| 131 | * @param {object} query |
nothing calls this directly
no test coverage detected