Skip to content

Commit dc8b749

Browse files
committed
Fix lint
1 parent bc8a6a9 commit dc8b749

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

lazer/sdk/js/examples/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { PythLazerClient } from "../src/index.js";
55

66
// Ignore debug messages
7-
console.debug = () => {};
7+
console.debug = () => { };
88

99
const client = await PythLazerClient.create({
1010
urls: [

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ClientRequestArgs } from "node:http";
2+
13
import TTLCache from "@isaacs/ttlcache";
24
import type { ErrorEvent } from "isomorphic-ws";
35
import WebSocket from "isomorphic-ws";
@@ -7,7 +9,16 @@ import { dummyLogger } from "ts-log";
79
import type { Request, Response } from "../protocol.js";
810
import type { ResilientWebSocketConfig } from "./resilient-websocket.js";
911
import { ResilientWebSocket } from "./resilient-websocket.js";
10-
import type { ClientRequestArgs } from "node:http";
12+
13+
/**
14+
* Browser global interface for proper typing
15+
*/
16+
type BrowserGlobal = {
17+
window?: {
18+
document?: unknown;
19+
};
20+
importScripts?: (...urls: string[]) => void;
21+
}
1122

1223
/**
1324
* Detects if the code is running in a regular DOM or Web Worker context.
@@ -17,8 +28,8 @@ function isBrowser(): boolean {
1728
try {
1829
// Check for browser's window object (DOM context)
1930
if (typeof globalThis !== "undefined") {
20-
const global = globalThis as any;
21-
if (global.window && global.window.document) {
31+
const global = globalThis as BrowserGlobal;
32+
if (global.window?.document) {
2233
return true;
2334
}
2435

@@ -51,19 +62,16 @@ function addAuthentication(
5162
url: string,
5263
token: string,
5364
wsOptions: WebSocket.ClientOptions | ClientRequestArgs | undefined = {}
54-
): { endpoint: string; wsOptions: any } {
65+
): { endpoint: string; wsOptions: WebSocket.ClientOptions | ClientRequestArgs | undefined } {
5566
if (isBrowser()) {
5667
// Browser: Add token as query parameter
5768
const urlObj = new URL(url);
5869
urlObj.searchParams.set("ACCESS_TOKEN", token);
5970

60-
// For browsers, we need to filter out any options that aren't valid for WebSocket constructor
61-
// Browser WebSocket constructor only accepts protocols as second parameter
62-
const browserWsOptions = wsOptions.protocol ? wsOptions.protocol : undefined;
63-
71+
// For browsers, filter out wsOptions since headers aren't supported
6472
return {
6573
endpoint: urlObj.toString(),
66-
wsOptions: browserWsOptions,
74+
wsOptions: undefined,
6775
};
6876
} else {
6977
// Node.js: Add Authorization header
@@ -72,7 +80,7 @@ function addAuthentication(
7280
wsOptions: {
7381
...wsOptions,
7482
headers: {
75-
...wsOptions.headers,
83+
...(wsOptions.headers as Record<string, string> | undefined),
7684
Authorization: `Bearer ${token}`,
7785
},
7886
},

0 commit comments

Comments
 (0)