tiagosiebler / bybit-api

Node.js SDK for the Bybit APIs and WebSockets, with TypeScript & browser support.

Home Page:https://www.npmjs.com/package/bybit-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: _a.terminate is not a function

hirenreshamwala opened this issue · comments

I am using this library in browser. I am getting following error sometimes.

TypeError: _a.terminate is not a function
Call Stack
executeReconnectableClose
node_modules/bybit-api/lib/websocket-client.js (511:0)
<unknown>
node_modules/bybit-api/lib/websocket-client.js (500:0)

Here is what on in websocket-client.js

506     executeReconnectableClose(wsKey, reason) {
507         var _a;
508         this.logger.info(`${reason} - closing socket to reconnect`, Object.assign(Object.assign({}, loggerCategory), { wsKey,
509             reason }));
510         const wasOpen = this.wsStore.isWsOpen(wsKey);
511         (_a = this.getWs(wsKey)) === null || _a === void 0 ? void 0 : _a.terminate();
512         delete this.wsStore.get(wsKey, true).activePongTimer;
513         this.clearPingTimer(wsKey);
514         this.clearPongTimer(wsKey);
515         if (!wasOpen) {
516             this.logger.info(`${reason} - socket already closed - trigger immediate reconnect`, Object.assign(Object.assign({}, loggerCategory), { wsKey,
517                 reason }));
518             this.reconnectWithDelay(wsKey, this.options.reconnectTimeout);
519         }
520     }

Please provide the solution for this issue.

Looks like the websocket terminate() functionality does not exist in browsers, only in nodejs. I'm making improvements so it doesn't throw an exception in browsers (see PR #306). I'm expecting the executeReconnectableClose to still work once my changes are done, since there's also a websocket.close() call which should work in browsers too.

Fixed in v3.8.0. Let me know if there's anything else missing - thanks!