From bfd7b2f26dd39c8c40866163f338addf0693646e Mon Sep 17 00:00:00 2001 From: Chris Bygrave Date: Tue, 10 Jan 2023 20:59:52 +0000 Subject: [PATCH 1/2] Support for passing headers through to ws connect calls Signed-off-by: Chris Bygrave --- lib/firefly.ts | 2 ++ lib/interfaces.ts | 1 + lib/websocket.ts | 1 + package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/firefly.ts b/lib/firefly.ts index 7a80359..ad84e1a 100644 --- a/lib/firefly.ts +++ b/lib/firefly.ts @@ -549,6 +549,7 @@ export default class FireFly extends HttpBase { listen( subscriptions: string | string[] | FireFlySubscriptionBase, callback: FireFlyWebSocketCallback, + headers?: Record, ): FireFlyWebSocket { const options: FireFlyWebSocketOptions = { host: this.options.websocket.host, @@ -559,6 +560,7 @@ export default class FireFly extends HttpBase { autoack: false, reconnectDelay: this.options.websocket.reconnectDelay, heartbeatInterval: this.options.websocket.heartbeatInterval, + headers: headers, }; const handler: FireFlyWebSocketCallback = (socket, event) => { diff --git a/lib/interfaces.ts b/lib/interfaces.ts index ae68ceb..f551127 100644 --- a/lib/interfaces.ts +++ b/lib/interfaces.ts @@ -61,6 +61,7 @@ export interface FireFlyWebSocketOptions { autoack: boolean; reconnectDelay: number; heartbeatInterval: number; + headers?: Record; } // Namespace diff --git a/lib/websocket.ts b/lib/websocket.ts index bb1c3c3..3a38c6a 100644 --- a/lib/websocket.ts +++ b/lib/websocket.ts @@ -59,6 +59,7 @@ export class FireFlyWebSocket { const socket = (this.socket = new WebSocket(url, { auth, handshakeTimeout: this.options.heartbeatInterval, + headers: this.options.headers, })); this.closed = false; diff --git a/package-lock.json b/package-lock.json index 407c77e..4d7988c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hyperledger/firefly-sdk", - "version": "1.2.1", + "version": "1.2.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@hyperledger/firefly-sdk", - "version": "1.2.1", + "version": "1.2.4", "license": "Apache-2.0", "dependencies": { "axios": "^0.26.1", diff --git a/package.json b/package.json index a85316d..e36a11c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/firefly-sdk", - "version": "1.2.3", + "version": "1.2.4", "description": "Client SDK for Hyperledger FireFly", "main": "dist/index.js", "types": "dist/index.d.ts", From 2f4f56552e5c0333561dfd5ac862a0474b3133da Mon Sep 17 00:00:00 2001 From: Chris Bygrave Date: Wed, 11 Jan 2023 08:24:20 +0000 Subject: [PATCH 2/2] Expose all websocket options Signed-off-by: Chris Bygrave --- lib/firefly.ts | 6 ++++-- lib/interfaces.ts | 4 +++- lib/websocket.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/firefly.ts b/lib/firefly.ts index ad84e1a..552f58a 100644 --- a/lib/firefly.ts +++ b/lib/firefly.ts @@ -1,5 +1,7 @@ import { Stream, Readable } from 'stream'; +import * as http from 'http'; import * as FormData from 'form-data'; +import * as WebSocket from 'ws'; import { FireFlyStatusResponse, FireFlyPrivateSendOptions, @@ -549,7 +551,7 @@ export default class FireFly extends HttpBase { listen( subscriptions: string | string[] | FireFlySubscriptionBase, callback: FireFlyWebSocketCallback, - headers?: Record, + socketOptions?: WebSocket.ClientOptions | http.ClientRequestArgs, ): FireFlyWebSocket { const options: FireFlyWebSocketOptions = { host: this.options.websocket.host, @@ -560,7 +562,7 @@ export default class FireFly extends HttpBase { autoack: false, reconnectDelay: this.options.websocket.reconnectDelay, heartbeatInterval: this.options.websocket.heartbeatInterval, - headers: headers, + socketOptions: socketOptions, }; const handler: FireFlyWebSocketCallback = (socket, event) => { diff --git a/lib/interfaces.ts b/lib/interfaces.ts index f551127..80b003a 100644 --- a/lib/interfaces.ts +++ b/lib/interfaces.ts @@ -1,4 +1,6 @@ +import * as http from 'http'; import { AxiosRequestConfig } from 'axios'; +import * as WebSocket from 'ws'; import { operations } from './schema'; /** @@ -61,7 +63,7 @@ export interface FireFlyWebSocketOptions { autoack: boolean; reconnectDelay: number; heartbeatInterval: number; - headers?: Record; + socketOptions?: WebSocket.ClientOptions | http.ClientRequestArgs; } // Namespace diff --git a/lib/websocket.ts b/lib/websocket.ts index 3a38c6a..e3c8ed8 100644 --- a/lib/websocket.ts +++ b/lib/websocket.ts @@ -57,9 +57,9 @@ export class FireFlyWebSocket { ? `${this.options.username}:${this.options.password}` : undefined; const socket = (this.socket = new WebSocket(url, { + ...this.options.socketOptions, auth, handshakeTimeout: this.options.heartbeatInterval, - headers: this.options.headers, })); this.closed = false;