diff --git a/packages/socket.io-postgres-emitter/lib/index.ts b/packages/socket.io-postgres-emitter/lib/index.ts index 76ab377237..a88577a9e5 100644 --- a/packages/socket.io-postgres-emitter/lib/index.ts +++ b/packages/socket.io-postgres-emitter/lib/index.ts @@ -92,7 +92,7 @@ export class Emitter< constructor( readonly pool: any, readonly nsp: string = "/", - opts: Partial = {}, + private readonly opts: Partial = {}, ) { const channelPrefix = opts.channelPrefix || "socket.io"; this.channel = `${channelPrefix}#${nsp}`; @@ -107,7 +107,7 @@ export class Emitter< * @public */ public of(nsp: string): Emitter { - return new Emitter(this.pool, (nsp[0] !== "/" ? "/" : "") + nsp); + return new Emitter(this.pool, (nsp[0] !== "/" ? "/" : "") + nsp, this.opts); } /** diff --git a/packages/socket.io-postgres-emitter/test/index.ts b/packages/socket.io-postgres-emitter/test/index.ts index 181996e6d2..56a26e1864 100644 --- a/packages/socket.io-postgres-emitter/test/index.ts +++ b/packages/socket.io-postgres-emitter/test/index.ts @@ -122,6 +122,18 @@ describe("@socket.io/postgres-emitter", () => { }); }); + it("keeps the options of the emitter in a namespace", () => { + const customEmitter = new Emitter(pool, "/", { + channelPrefix: "custom-prefix", + tableName: "custom_attachments", + payloadThreshold: 100, + }).of("/custom"); + + expect(customEmitter.channel).to.eql("custom-prefix#/custom"); + expect(customEmitter.tableName).to.eql("custom_attachments"); + expect(customEmitter.payloadThreshold).to.eql(100); + }); + it("broadcasts to all clients in a room", (done) => { serverSockets[1].join("room1");