From 5144dafa19bdf4e571c110a4a2998680d0da1978 Mon Sep 17 00:00:00 2001 From: JP Camara Date: Mon, 10 Nov 2025 23:01:55 -0500 Subject: [PATCH 1/2] Add whisper to the top-level compat interface * Otherwise when using compat, accessing whipsper is very awkward. ie, if you have "channel = this.consumer.subscriptions.create", you need to call "channel.channel.whisper" * With this change, you can call "channel.whisper" instead --- packages/core/action_cable_compat/index.d.ts | 1 + packages/core/action_cable_compat/index.js | 4 ++++ .../core/create-cable/integration.test.ts | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/packages/core/action_cable_compat/index.d.ts b/packages/core/action_cable_compat/index.d.ts index 9086427..fdf7e21 100644 --- a/packages/core/action_cable_compat/index.d.ts +++ b/packages/core/action_cable_compat/index.d.ts @@ -16,6 +16,7 @@ export class ActionCableSubscription { perform(action: string, payload?: object): void send(payload: object): void + whisper(payload: object): void unsubscribe(): void } diff --git a/packages/core/action_cable_compat/index.js b/packages/core/action_cable_compat/index.js index f6469fe..230d820 100644 --- a/packages/core/action_cable_compat/index.js +++ b/packages/core/action_cable_compat/index.js @@ -21,6 +21,10 @@ export class ActionCableSubscription { this.channel.send(data) } + whisper(data) { + this.channel.whisper(data) + } + get identifier() { return this.channel.identifier } diff --git a/packages/core/create-cable/integration.test.ts b/packages/core/create-cable/integration.test.ts index bb54ab8..db25420 100644 --- a/packages/core/create-cable/integration.test.ts +++ b/packages/core/create-cable/integration.test.ts @@ -19,11 +19,13 @@ class CableTransport extends TestTransport { pongsCount: number = 0 nextSid: string = '' nextRestoredIds: string[] | null = null + whispers: any[] = [] constructor(url: string) { super(url) this.subscriptions = {} + this.whispers = [] } open() { @@ -88,6 +90,11 @@ class CableTransport extends TestTransport { identifier }) } + } else if (command === 'whisper') { + this.whispers.push({ + identifier, + data: msg.data + }) } } @@ -642,4 +649,21 @@ describe('Action Cable compatibility', () => { expect(transport.pongsCount).toEqual(1) }) + + it('whispers on subscription', async () => { + await consumer.ensureActiveConnection() + + let subscription = consumer.subscriptions.create({ + channel: 'TestChannel' + }) + + await subscription.channel.ensureSubscribed() + await subscription.whisper({ event: 'typing', user: 'john' }) + + expect(transport.whispers).toHaveLength(1) + expect(transport.whispers[0]).toMatchObject({ + identifier: subscription.channel.identifier, + data: { event: 'typing', user: 'john' } + }) + }) }) From b3f53b4ad5fe72f6751038f76a948afcafe242db Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Tue, 11 Nov 2025 04:11:13 -0800 Subject: [PATCH 2/2] Update packages/core/action_cable_compat/index.js --- packages/core/action_cable_compat/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/action_cable_compat/index.js b/packages/core/action_cable_compat/index.js index 230d820..192c296 100644 --- a/packages/core/action_cable_compat/index.js +++ b/packages/core/action_cable_compat/index.js @@ -22,7 +22,7 @@ export class ActionCableSubscription { } whisper(data) { - this.channel.whisper(data) + return this.channel.whisper(data) } get identifier() {