Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 26, 2024
1 parent a0f2243 commit 27e06f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
6 changes: 1 addition & 5 deletions lib/parent-namespace.ts
Expand Up @@ -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);
});
}
Expand Down
32 changes: 31 additions & 1 deletion test/namespaces.ts
Expand Up @@ -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) => {
Expand All @@ -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");
Expand Down

0 comments on commit 27e06f7

Please sign in to comment.