From 1b92463281cb7ff588c936b364d4f15f55b34632 Mon Sep 17 00:00:00 2001 From: Maxime <57860498+MaximeMRF@users.noreply.github.com> Date: Mon, 9 Jun 2025 22:31:33 +0200 Subject: [PATCH 1/4] feat(transmit): getAllSubscribersUUIDs --- src/transmit.ts | 6 ++++++ tests/transmit.spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/transmit.ts b/src/transmit.ts index dc6e6ab..493f46c 100644 --- a/src/transmit.ts +++ b/src/transmit.ts @@ -235,6 +235,12 @@ export class Transmit { await this.#bus?.disconnect() } + getAllSubscribersUUIDs(channel: string) { + const subscribers = this.#manager.findByChannel(channel) + const uuids = Array.from(subscribers).map((subscriber) => subscriber.getUid()) + return uuids + } + #ping() { for (const [stream] of this.#manager.getAllSubscribers()) { stream.writeMessage({ data: { channel: '$$transmit/ping', payload: {} } }) diff --git a/tests/transmit.spec.ts b/tests/transmit.spec.ts index d8bb387..261092b 100644 --- a/tests/transmit.spec.ts +++ b/tests/transmit.spec.ts @@ -398,4 +398,28 @@ test.group('Transmit', () => { assert.isTrue(dataReceived) }) + + test('should return all subscribers for a channel', async ({ assert }) => { + const transport = makeTransport() + const transmit = makeTransmitWithTransport(transport) + + const stream1 = makeStream(transmit) + const stream2 = makeStream(transmit) + + await transmit.subscribe({ + uid: stream1.getUid(), + channel: 'channel1', + }) + + await transmit.subscribe({ + uid: stream2.getUid(), + channel: 'channel1', + }) + + const uuids = transmit.getAllSubscribersUUIDs('channel1') + + assert.lengthOf(uuids, 2) + assert.equal(uuids[0], stream1.getUid()) + assert.equal(uuids[1], stream2.getUid()) + }) }) From 365cc12abcc520d3e00a901a239f5379074373ed Mon Sep 17 00:00:00 2001 From: Maxime <57860498+MaximeMRF@users.noreply.github.com> Date: Mon, 23 Jun 2025 10:45:26 +0200 Subject: [PATCH 2/4] refacto: method name --- src/transmit.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/transmit.ts b/src/transmit.ts index 493f46c..4e9a3c0 100644 --- a/src/transmit.ts +++ b/src/transmit.ts @@ -235,10 +235,9 @@ export class Transmit { await this.#bus?.disconnect() } - getAllSubscribersUUIDs(channel: string) { + getSubscribersFor(channel: string) { const subscribers = this.#manager.findByChannel(channel) - const uuids = Array.from(subscribers).map((subscriber) => subscriber.getUid()) - return uuids + return Array.from(subscribers).map((subscriber) => subscriber.getUid()) } #ping() { From ed8ace0770cf2183572f6e2675dfa58c6ae0e624 Mon Sep 17 00:00:00 2001 From: Maxime <57860498+MaximeMRF@users.noreply.github.com> Date: Mon, 23 Jun 2025 10:48:03 +0200 Subject: [PATCH 3/4] fix(tests): method name --- tests/transmit.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/transmit.spec.ts b/tests/transmit.spec.ts index 261092b..26cfdf0 100644 --- a/tests/transmit.spec.ts +++ b/tests/transmit.spec.ts @@ -416,7 +416,7 @@ test.group('Transmit', () => { channel: 'channel1', }) - const uuids = transmit.getAllSubscribersUUIDs('channel1') + const uuids = transmit.getSubscribersFor('channel1') assert.lengthOf(uuids, 2) assert.equal(uuids[0], stream1.getUid()) From adb976c838048dffb411ded21486ad51562b7ac2 Mon Sep 17 00:00:00 2001 From: Maxime <57860498+MaximeMRF@users.noreply.github.com> Date: Mon, 23 Jun 2025 21:01:16 +0200 Subject: [PATCH 4/4] refacto(tests) --- tests/transmit.spec.ts | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/transmit.spec.ts b/tests/transmit.spec.ts index 26cfdf0..1b65c98 100644 --- a/tests/transmit.spec.ts +++ b/tests/transmit.spec.ts @@ -405,6 +405,9 @@ test.group('Transmit', () => { const stream1 = makeStream(transmit) const stream2 = makeStream(transmit) + const stream3 = makeStream(transmit) + const stream4 = makeStream(transmit) + const stream5 = makeStream(transmit) await transmit.subscribe({ uid: stream1.getUid(), @@ -416,10 +419,31 @@ test.group('Transmit', () => { channel: 'channel1', }) - const uuids = transmit.getSubscribersFor('channel1') + await transmit.subscribe({ + uid: stream3.getUid(), + channel: 'channel2', + }) + + await transmit.subscribe({ + uid: stream4.getUid(), + channel: 'channel2', + }) + + await transmit.subscribe({ + uid: stream5.getUid(), + channel: 'channel2', + }) + + const uuidsChannel1 = transmit.getSubscribersFor('channel1') + const uuidsChannel2 = transmit.getSubscribersFor('channel2') + + assert.lengthOf(uuidsChannel1, 2) + assert.equal(uuidsChannel1[0], stream1.getUid()) + assert.equal(uuidsChannel1[1], stream2.getUid()) - assert.lengthOf(uuids, 2) - assert.equal(uuids[0], stream1.getUid()) - assert.equal(uuids[1], stream2.getUid()) + assert.lengthOf(uuidsChannel2, 3) + assert.equal(uuidsChannel2[0], stream3.getUid()) + assert.equal(uuidsChannel2[1], stream4.getUid()) + assert.equal(uuidsChannel2[2], stream5.getUid()) }) })