From 8737d0ae6fb362455015e6dd435010c36d023663 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 14 Oct 2021 17:23:52 -0600 Subject: [PATCH] fix: restore the namespace export This restores the previous behavior, where the "io" object available in the browser could be used as a function (`io()`) or as a namespace (`io.connect()`). The breaking change was introduced in [1]. Related: https://github.com/socketio/socket.io/issues/4121 [1]: https://github.com/socketio/socket.io-client/commit/16b65698aed766e1e645c78847f2e91bfc5b6f56 --- lib/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/index.ts b/lib/index.ts index 6dbdc1bd..27d35166 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -71,6 +71,15 @@ function lookup( return io.socket(parsed.path, opts); } +// so that "lookup" can be used both as a function (e.g. `io(...)`) and as a +// namespace (e.g. `io.connect(...)`), for backward compatibility +Object.assign(lookup, { + Manager, + Socket, + io: lookup, + connect: lookup, +}); + /** * Protocol version. *