diff --git a/packages/transport-http/src/subscribe/handlers/types.ts b/packages/transport-http/src/subscribe/handlers/types.ts index 83e1ded6b..939b6c59f 100644 --- a/packages/transport-http/src/subscribe/handlers/types.ts +++ b/packages/transport-http/src/subscribe/handlers/types.ts @@ -15,21 +15,21 @@ export interface SubscriptionHandler< ): DataSubscriber } -export interface DataSubscriber { +export interface DataSubscriber { /** * The callback to call when a data is received */ - sendData(data: Data): void + onData(data: DataDto): void /** * The callback to call when an error is received */ - sendError(error: Error): void + onError(error: Error): void /** * The arguments to connect or reconnect to the subscription */ - encodeArgs(args: Args): ArgsModel + argsToDto(args: Args): ArgsDto /** * Get the arguments to connect or reconnect to the subscription diff --git a/packages/transport-http/src/subscribe/subscription-manager.test.ts b/packages/transport-http/src/subscribe/subscription-manager.test.ts index 77f705bf4..0d656ebb9 100644 --- a/packages/transport-http/src/subscribe/subscription-manager.test.ts +++ b/packages/transport-http/src/subscribe/subscription-manager.test.ts @@ -29,9 +29,9 @@ describe("SubscriptionManager", () => { mockWs = new WS("wss://localhost:8080") mockSubscriber = { - sendData: jest.fn(), - sendError: jest.fn(), - encodeArgs: jest.fn().mockReturnValue(mockConnectionArgs), + onData: jest.fn(), + onError: jest.fn(), + argsToDto: jest.fn().mockReturnValue(mockConnectionArgs), get connectionArgs() { return mockConnectionArgs }, @@ -156,9 +156,9 @@ describe("SubscriptionManager", () => { await serverPromise - expect(mockSubscriber.sendData).toHaveBeenCalledTimes(1) - expect(mockSubscriber.sendData).toHaveBeenCalledWith({key: "value"}) - expect(mockSubscriber.sendError).toHaveBeenCalledTimes(0) + expect(mockSubscriber.onData).toHaveBeenCalledTimes(1) + expect(mockSubscriber.onData).toHaveBeenCalledWith({key: "value"}) + expect(mockSubscriber.onError).toHaveBeenCalledTimes(0) serverPromise = (async () => { const msg = (await mockWs.nextMessage) as string @@ -232,9 +232,9 @@ describe("SubscriptionManager", () => { await serverPromise - expect(mockSubscriber.sendData).toHaveBeenCalledTimes(1) - expect(mockSubscriber.sendData).toHaveBeenCalledWith({key: "value"}) - expect(mockSubscriber.sendError).toHaveBeenCalledTimes(0) + expect(mockSubscriber.onData).toHaveBeenCalledTimes(1) + expect(mockSubscriber.onData).toHaveBeenCalledWith({key: "value"}) + expect(mockSubscriber.onError).toHaveBeenCalledTimes(0) // Close the connection and create a new one mockWs.close() @@ -275,7 +275,7 @@ describe("SubscriptionManager", () => { await serverPromise - expect(mockSubscriber.sendData).toHaveBeenCalledTimes(2) - expect(mockSubscriber.sendData.mock.calls[1]).toEqual([{key: "value2"}]) + expect(mockSubscriber.onData).toHaveBeenCalledTimes(2) + expect(mockSubscriber.onData.mock.calls[1]).toEqual([{key: "value2"}]) }) }) diff --git a/packages/transport-http/src/subscribe/subscription-manager.ts b/packages/transport-http/src/subscribe/subscription-manager.ts index dc36da429..2c5000312 100644 --- a/packages/transport-http/src/subscribe/subscription-manager.ts +++ b/packages/transport-http/src/subscribe/subscription-manager.ts @@ -162,7 +162,7 @@ export class SubscriptionManager< }) this.subscriptions.forEach(sub => { - sub.subscriber.sendError( + sub.subscriber.onError( new Error( `Failed to reconnect to the server after ${this.reconnectAttempts + 1} attempts: ${error}` ) @@ -318,7 +318,7 @@ export class SubscriptionManager< } // Send data to the subscriber - sub.subscriber.sendData(message.data) + sub.subscriber.onData(message.data) } private getHandler(topic: string) {