* 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)
| 663 | */ |
| 664 | |
| 665 | function lookup(uri, opts) { |
| 666 | if (typeof uri == 'object') { |
| 667 | opts = uri; |
| 668 | uri = undefined; |
| 669 | } |
| 670 | |
| 671 | opts = opts || {}; |
| 672 | |
| 673 | var parsed = url(uri); |
| 674 | var source = parsed.source; |
| 675 | var id = parsed.id; |
| 676 | var io; |
| 677 | |
| 678 | if (opts.forceNew || opts['force new connection'] || false === opts.multiplex) { |
| 679 | debug('ignoring socket cache for %s', source); |
| 680 | io = Manager(source, opts); |
| 681 | } else { |
| 682 | if (!cache[id]) { |
| 683 | debug('new io instance for %s', source); |
| 684 | cache[id] = Manager(source, opts); |
| 685 | } |
| 686 | io = cache[id]; |
| 687 | } |
| 688 | |
| 689 | return io.socket(parsed.path); |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * Protocol version. |