Skip to content

Commit d8dc385

Browse files
committed
fix format
1 parent 8a9a17a commit d8dc385

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

lazer/sdk/js/examples/index.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ import { PythLazerClient } from "../src/index.js";
77
console.debug = () => {};
88

99
const client = await PythLazerClient.create({
10-
urls: ["wss://pyth-lazer-0.dourolabs.app/v1/stream", "wss://pyth-lazer-1.dourolabs.app/v1/stream"],
11-
token: "you-access-token-here", // Replace with your actual access token
12-
numConnections: 4, // Optionally specify number of parallel redundant connections to reduce the chance of dropped messages. The connections will round-robin across the provided URLs. Default is 4.
13-
logger: console, // Optionally log socket operations (to the console in this case.)
14-
onError: (error) => {
15-
console.error("WebSocket error:", error);
16-
},
17-
rwsConfig: { // Optional configuration for resilient WebSocket connections
18-
heartbeatTimeoutDurationMs: 5000, // Optional heartbeat timeout duration in milliseconds
19-
maxRetryDelayMs: 1000, // Optional maximum retry delay in milliseconds
20-
logAfterRetryCount: 10, // Optional log after how many retries
21-
}
10+
urls: [
11+
"wss://pyth-lazer-0.dourolabs.app/v1/stream",
12+
"wss://pyth-lazer-1.dourolabs.app/v1/stream",
13+
],
14+
token: "you-access-token-here", // Replace with your actual access token
15+
numConnections: 4, // Optionally specify number of parallel redundant connections to reduce the chance of dropped messages. The connections will round-robin across the provided URLs. Default is 4.
16+
logger: console, // Optionally log socket operations (to the console in this case.)
17+
onError: (error) => {
18+
console.error("WebSocket error:", error);
19+
},
20+
// Optional configuration for resilient WebSocket connections
21+
rwsConfig: {
22+
heartbeatTimeoutDurationMs: 5000, // Optional heartbeat timeout duration in milliseconds
23+
maxRetryDelayMs: 1000, // Optional maximum retry delay in milliseconds
24+
logAfterRetryCount: 10, // Optional log after how many retries
25+
},
2226
});
2327

2428
// Read and process messages from the Lazer stream

lazer/sdk/js/src/client.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import WebSocket from "isomorphic-ws";
22

33
import type { ParsedPayload, Request, Response } from "./protocol.js";
44
import { BINARY_UPDATE_FORMAT_MAGIC_LE, FORMAT_MAGICS_LE } from "./protocol.js";
5-
import type {WebSocketPoolConfig} from "./socket/websocket-pool.js";
6-
import { WebSocketPool } from "./socket/websocket-pool.js";
5+
import type { WebSocketPoolConfig } from "./socket/websocket-pool.js";
6+
import { WebSocketPool } from "./socket/websocket-pool.js";
77

88
export type BinaryResponse = {
99
subscriptionId: number;
@@ -34,9 +34,7 @@ export class PythLazerClient {
3434
* @param numConnections - The number of parallel WebSocket connections to establish (default: 3). A higher number gives a more reliable stream. The connections will round-robin across the provided URLs.
3535
* @param logger - Optional logger to get socket level logs. Compatible with most loggers such as the built-in console and `bunyan`.
3636
*/
37-
static async create(
38-
config: WebSocketPoolConfig
39-
): Promise<PythLazerClient> {
37+
static async create(config: WebSocketPoolConfig): Promise<PythLazerClient> {
4038
const wsp = await WebSocketPool.create(config);
4139
return new PythLazerClient(wsp);
4240
}

lazer/sdk/js/src/socket/resilient-websocket.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type ResilientWebSocketConfig = {
1616
heartbeatTimeoutDurationMs?: number;
1717
maxRetryDelayMs?: number;
1818
logAfterRetryCount?: number;
19-
}
19+
};
2020

2121
export class ResilientWebSocket {
2222
private endpoint: string;
@@ -49,17 +49,14 @@ export class ResilientWebSocket {
4949
onMessage: (data: WebSocket.Data) => void;
5050
onReconnect: () => void;
5151

52-
constructor(
53-
config: ResilientWebSocketConfig,
54-
) {
52+
constructor(config: ResilientWebSocketConfig) {
5553
this.endpoint = config.endpoint;
5654
this.wsOptions = config.wsOptions;
5755
this.logger = config.logger ?? dummyLogger;
5856
this.heartbeatTimeoutDurationMs =
5957
config.heartbeatTimeoutDurationMs ??
6058
DEFAULT_HEARTBEAT_TIMEOUT_DURATION_MS;
61-
this.maxRetryDelayMs =
62-
config.maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS;
59+
this.maxRetryDelayMs = config.maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS;
6360
this.logAfterRetryCount =
6461
config.logAfterRetryCount ?? DEFAULT_LOG_AFTER_RETRY_COUNT;
6562

@@ -90,7 +87,7 @@ export class ResilientWebSocket {
9087
startWebSocket() {
9188
if (this.wsUserClosed) {
9289
this.logger.error("Connection was explicitly close. Won't reconnect.");
93-
return
90+
return;
9491
}
9592

9693
if (this.wsClient !== undefined) {
@@ -119,7 +116,9 @@ export class ResilientWebSocket {
119116

120117
this.wsClient.addEventListener("close", (e) => {
121118
if (this.wsUserClosed) {
122-
this.logger.info(`WebSocket connection to ${this.endpoint} closed by user`);
119+
this.logger.info(
120+
`WebSocket connection to ${this.endpoint} closed by user`,
121+
);
123122
} else {
124123
if (this.shouldLogRetry()) {
125124
this.logger.warn(
@@ -161,7 +160,9 @@ export class ResilientWebSocket {
161160

162161
private handleReconnect() {
163162
if (this.wsUserClosed) {
164-
this.logger.info("WebSocket connection closed by user, not reconnecting.");
163+
this.logger.info(
164+
"WebSocket connection closed by user, not reconnecting.",
165+
);
165166
return;
166167
}
167168

@@ -173,7 +174,6 @@ export class ResilientWebSocket {
173174
clearTimeout(this.retryTimeout);
174175
}
175176

176-
177177
this.wsFailedAttempts += 1;
178178
this.wsClient = undefined;
179179

@@ -189,7 +189,7 @@ export class ResilientWebSocket {
189189

190190
this.retryTimeout = setTimeout(() => {
191191
this.startWebSocket();
192-
}, this.retryDelayMs());
192+
}, this.retryDelayMs());
193193
}
194194

195195
closeWebSocket(): void {

lazer/sdk/js/src/socket/websocket-pool.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { Logger } from "ts-log";
55
import { dummyLogger } from "ts-log";
66

77
import type { Request, Response } from "../protocol.js";
8-
import type {ResilientWebSocketConfig} from "./resilient-websocket.js";
9-
import { ResilientWebSocket } from "./resilient-websocket.js";
8+
import type { ResilientWebSocketConfig } from "./resilient-websocket.js";
9+
import { ResilientWebSocket } from "./resilient-websocket.js";
1010

1111
const DEFAULT_NUM_CONNECTIONS = 4;
1212

@@ -15,7 +15,7 @@ export type WebSocketPoolConfig = {
1515
token: string;
1616
numConnections?: number;
1717
logger?: Logger;
18-
rwsConfig?: Omit<ResilientWebSocketConfig, 'logger' | 'endpoint'>;
18+
rwsConfig?: Omit<ResilientWebSocketConfig, "logger" | "endpoint">;
1919
onError?: (error: ErrorEvent) => void;
2020
};
2121

@@ -49,9 +49,7 @@ export class WebSocketPool {
4949
* @param numConnections - Number of parallel WebSocket connections to maintain (default: 3)
5050
* @param logger - Optional logger to get socket level logs. Compatible with most loggers such as the built-in console and `bunyan`.
5151
*/
52-
static async create(
53-
config: WebSocketPoolConfig,
54-
): Promise<WebSocketPool> {
52+
static async create(config: WebSocketPoolConfig): Promise<WebSocketPool> {
5553
if (config.urls.length === 0) {
5654
throw new Error("No URLs provided");
5755
}
@@ -75,7 +73,7 @@ export class WebSocketPool {
7573
...config.rwsConfig,
7674
endpoint: url,
7775
wsOptions,
78-
logger
76+
logger,
7977
});
8078

8179
// If a websocket client unexpectedly disconnects, ResilientWebSocket will reestablish
@@ -115,7 +113,7 @@ export class WebSocketPool {
115113

116114
pool.logger.info(
117115
`At least one WebSocket connection is established. WebSocketPool is ready.`,
118-
)
116+
);
119117

120118
return pool;
121119
}

0 commit comments

Comments
 (0)