From bb6f3fa04684730bd0d5d138bec565bb2d9f1b5b Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Tue, 2 Apr 2024 22:16:37 +0100 Subject: [PATCH] feat(): bump ws to latest --- package-lock.json | 12 ++++++------ package.json | 2 +- src/lib/BaseWSClient.ts | 14 +++++++++++--- src/types/websockets/client.ts | 5 +---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 582c0c6..6124580 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "axios": "^1.6.6", "isomorphic-ws": "^4.0.1", - "ws": "^7.4.0" + "ws": "^8.16.0" }, "devDependencies": { "@types/axios": "^0.14.0", @@ -5136,15 +5136,15 @@ } }, "node_modules/ws": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", - "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", "engines": { - "node": ">=8.3.0" + "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "utf-8-validate": ">=5.0.2" }, "peerDependenciesMeta": { "bufferutil": { diff --git a/package.json b/package.json index 5fd396b..d9dd07c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "dependencies": { "axios": "^1.6.6", "isomorphic-ws": "^4.0.1", - "ws": "^7.4.0" + "ws": "^8.16.0" }, "devDependencies": { "@types/axios": "^0.14.0", diff --git a/src/lib/BaseWSClient.ts b/src/lib/BaseWSClient.ts index 32269db..2af3a20 100644 --- a/src/lib/BaseWSClient.ts +++ b/src/lib/BaseWSClient.ts @@ -435,7 +435,15 @@ export abstract class BaseWebsocketClient< this.clearPongTimer(wsKey); this.logger.trace('Sending ping', { ...WS_LOGGER_CATEGORY, wsKey }); - this.sendPingEvent(wsKey, this.wsStore.get(wsKey, true).ws); + const ws = this.wsStore.get(wsKey, true).ws; + + if (!ws) { + this.logger.error( + `Unable to send ping for wsKey "${wsKey}" - no connection found`, + ); + return; + } + this.sendPingEvent(wsKey, ws); this.wsStore.get(wsKey, true).activePongTimer = setTimeout(() => { this.logger.info('Pong timeout - closing socket to reconnect', { @@ -570,8 +578,8 @@ export abstract class BaseWebsocketClient< wsKey, }); - const agent = this.options.requestOptions?.agent; - const ws = new WebSocket(url, undefined, agent ? { agent } : undefined); + const ws = new WebSocket(url, undefined); + ws.onopen = (event: any) => this.onWsOpen(event, wsKey); ws.onmessage = (event: any) => this.onWsMessage(event, wsKey); ws.onerror = (event: any) => diff --git a/src/types/websockets/client.ts b/src/types/websockets/client.ts index 000c423..f39f3fa 100644 --- a/src/types/websockets/client.ts +++ b/src/types/websockets/client.ts @@ -33,10 +33,7 @@ export interface WSClientConfigurableOptions { /** Delay in milliseconds before respawning the connection */ reconnectTimeout?: number; - requestOptions?: { - /** override the user agent when opening the websocket connection (some proxies use this) */ - agent?: string; - }; + requestOptions?: {}; wsUrl?: string;