Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/socket.io-redis-streams-emitter/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,11 @@ export class Emitter<
}

public of(nsp: string) {
return new Emitter(this.#redisClient, this.#opts, nsp);
return new Emitter(
this.#redisClient,
this.#opts,
(nsp[0] !== "/" ? "/" : "") + nsp,
);
}

protected override publish(
Expand Down
26 changes: 26 additions & 0 deletions packages/socket.io-redis-streams-emitter/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ describe("@socket.io/redis-streams-emitter", () => {
});
});

it("broadcasts to all clients in a namespace without a leading slash", () => {
return new Promise<void>((resolve) => {
const partialResolve = times(3, () => {
servers.forEach((server) => server.of("/custom").adapter.close());
resolve();
});

servers.forEach((server) => server.of("/custom"));

const onConnect = times(3, async () => {
await sleep(PROPAGATION_DELAY_IN_MS);

emitter.of("custom").emit("test");
});

clientSockets.forEach((clientSocket) => {
const socket = clientSocket.io.socket("/custom");
socket.on("connect", onConnect);
socket.on("test", () => {
socket.disconnect();
partialResolve();
});
});
});
});

it("broadcasts to all clients in a room", () => {
return new Promise<void>((resolve, reject) => {
serverSockets[1].join("room1");
Expand Down