Skip to content

Commit

Permalink
fix adapter broadcast bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gkt5015 committed Apr 25, 2024
1 parent 14d4997 commit a0f2243
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/parent-namespace.ts
Expand Up @@ -48,7 +48,7 @@ export class ParentNamespace<
* @private
*/
_initAdapter(): void {
this.adapter = new ParentBroadcastAdapter(this, this.children);
this.adapter = new ParentBroadcastAdapter(this);
}

public emit<Ev extends EventNamesWithoutAck<EmitEvents>>(
Expand Down Expand Up @@ -113,12 +113,12 @@ export class ParentNamespace<
* @private file
*/
class ParentBroadcastAdapter extends Adapter {
constructor(parentNsp: any, private readonly children: Set<Namespace>) {
constructor(private readonly parentNsp: any) {
super(parentNsp);
}

broadcast(packet: any, opts: BroadcastOptions) {
this.children.forEach((nsp) => {
this.parentNsp.children.forEach((nsp) => {
nsp.adapter.broadcast(packet, opts);
});
}
Expand Down
1 change: 1 addition & 0 deletions test/namespaces.ts
Expand Up @@ -505,6 +505,7 @@ 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 Down

0 comments on commit a0f2243

Please sign in to comment.