MCPcopy
hub / github.com/socketio/socket.io / lookup

Function lookup

packages/socket.io-client/lib/index.ts:30–68  ·  view source on GitHub ↗
(
  uri?: string | Partial<ManagerOptions & SocketOptions>,
  opts?: Partial<ManagerOptions & SocketOptions>,
)

Source from the content-addressed store, hash-verified

28 opts?: Partial<ManagerOptions & SocketOptions>,
29): Socket;
30function lookup(
31 uri?: string | Partial<ManagerOptions & SocketOptions>,
32 opts?: Partial<ManagerOptions & SocketOptions>,
33): Socket {
34 if (typeof uri === "object") {
35 opts = uri;
36 uri = undefined;
37 }
38
39 opts = opts || {};
40
41 const parsed = url(uri as string, opts.path || "/socket.io");
42 const source = parsed.source;
43 const id = parsed.id;
44 const path = parsed.path;
45 const sameNamespace = cache[id] && path in cache[id]["nsps"];
46 const newConnection =
47 opts.forceNew ||
48 opts["force new connection"] ||
49 false === opts.multiplex ||
50 sameNamespace;
51
52 let io: Manager;
53
54 if (newConnection) {
55 debug("ignoring socket cache for %s", source);
56 io = new Manager(source, opts);
57 } else {
58 if (!cache[id]) {
59 debug("new io instance for %s", source);
60 cache[id] = new Manager(source, opts);
61 }
62 io = cache[id];
63 }
64 if (parsed.query && !opts.query) {
65 opts.query = parsed.queryKey;
66 }
67 return io.socket(parsed.path, opts);
68}
69
70// so that "lookup" can be used both as a function (e.g. `io(...)`) and as a
71// namespace (e.g. `io.connect(...)`), for backward compatibility

Callers

nothing calls this directly

Calls 3

urlFunction · 0.90
debugFunction · 0.85
socketMethod · 0.45

Tested by

no test coverage detected