From 87ab09d55a3a0ec5c66bf6a8902fc2b1549a0f24 Mon Sep 17 00:00:00 2001 From: Samuel Vogelsanger Date: Tue, 24 Sep 2024 10:05:47 +0200 Subject: [PATCH] fix: make Namespace._fns real private # Conflicts: # packages/socket.io/lib/namespace.ts # packages/socket.io/lib/parent-namespace.ts --- packages/socket.io/lib/namespace.ts | 19 ++++++++++++++++++- packages/socket.io/lib/parent-namespace.ts | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/socket.io/lib/namespace.ts b/packages/socket.io/lib/namespace.ts index d7ae1308fe..245551e61b 100644 --- a/packages/socket.io/lib/namespace.ts +++ b/packages/socket.io/lib/namespace.ts @@ -161,7 +161,7 @@ export class Namespace< SocketData >; - protected _fns: Array< + private _fns: Array< ( socket: Socket, next: (err?: ExtendedError) => void, @@ -187,6 +187,23 @@ export class Namespace< this._initAdapter(); } + protected static copyMiddleware< + ListenEvents extends EventsMap, + EmitEvents extends EventsMap, + ServerSideEvents extends EventsMap, + SocketData + >( + destination: Namespace< + ListenEvents, + EmitEvents, + ServerSideEvents, + SocketData + >, + source: Namespace + ) { + source._fns.forEach((fn) => destination.use(fn)); + } + /** * Initializes the `Adapter` for this nsp. * Run upon changing adapter by `Server#adapter` diff --git a/packages/socket.io/lib/parent-namespace.ts b/packages/socket.io/lib/parent-namespace.ts index 6139b8e969..43ac6be350 100644 --- a/packages/socket.io/lib/parent-namespace.ts +++ b/packages/socket.io/lib/parent-namespace.ts @@ -67,7 +67,7 @@ export class ParentNamespace< ): Namespace { debug("creating child namespace %s", name); const namespace = new Namespace(this.server, name); - this._fns.forEach((fn) => namespace.use(fn)); + Namespace.copyMiddleware(namespace, this); this.listeners("connect").forEach((listener) => namespace.on("connect", listener), );