From 27e06f7c34ed7c11f6d029427344aefa4fb84e52 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 26 Apr 2024 15:23:59 +0200 Subject: [PATCH] minor update --- lib/parent-namespace.ts | 6 +----- test/namespaces.ts | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/parent-namespace.ts b/lib/parent-namespace.ts index e17bfe8c8d..5a158b74e8 100644 --- a/lib/parent-namespace.ts +++ b/lib/parent-namespace.ts @@ -113,12 +113,8 @@ export class ParentNamespace< * @private file */ class ParentBroadcastAdapter extends Adapter { - constructor(private readonly parentNsp: any) { - super(parentNsp); - } - broadcast(packet: any, opts: BroadcastOptions) { - this.parentNsp.children.forEach((nsp) => { + this.nsp.children.forEach((nsp) => { nsp.adapter.broadcast(packet, opts); }); } diff --git a/test/namespaces.ts b/test/namespaces.ts index c9cfe5f6f8..621c589cef 100644 --- a/test/namespaces.ts +++ b/test/namespaces.ts @@ -505,7 +505,6 @@ describe("namespaces", () => { .on("connect", (socket) => { expect(socket.nsp.name).to.be("/dynamic-101"); dynamicNsp.emit("hello", 1, "2", { 3: "4" }); - dynamicNsp.to(socket.id).emit("there", 1, "2", { 3: "4" }); partialDone(); }) .use((socket, next) => { @@ -526,6 +525,37 @@ describe("namespaces", () => { }); }); + it("should allow connections to dynamic namespaces with a regex and emit in a room", (done) => { + const io = new Server(0); + const socket = createClient(io, "/dynamic-101"); + const partialDone = createPartialDone(4, successFn(done, io, socket)); + + let dynamicNsp = io + .of(/^\/dynamic-\d+$/) + .on("connect", (socket) => { + expect(socket.nsp.name).to.be("/dynamic-101"); + socket.join("some-room"); + dynamicNsp.to("some-room").emit("hello", 4, "3", { 2: "1" }); + partialDone(); + }) + .use((socket, next) => { + next(); + partialDone(); + }); + socket.on("connect_error", (err) => { + expect().fail(); + }); + socket.on("connect", () => { + partialDone(); + }); + socket.on("hello", (a, b, c) => { + expect(a).to.eql(4); + expect(b).to.eql("3"); + expect(c).to.eql({ 2: "1" }); + partialDone(); + }); + }); + it("should allow connections to dynamic namespaces with a function", (done) => { const io = new Server(0); const socket = createClient(io, "/dynamic-101");