Skip to content

Commit 6890721

Browse files
Fix ESLint error in WebSocket client
- Replace require() inside function with top-level require - Add eslint-disable comment for necessary require statement - Maintain browser/Node.js compatibility while passing linter Fixes failing CI linter check in GitHub Actions. Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 1735ae9 commit 6890721

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/events/websocket-client.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
import { Event, ConversationCallbackType } from '../types/base';
66

77
// Use native WebSocket in browser, ws library in Node.js
8-
const WebSocketImpl = (() => {
9-
if (typeof window !== 'undefined' && window.WebSocket) {
10-
// Browser environment
11-
return window.WebSocket;
12-
} else {
13-
// Node.js environment
14-
try {
15-
const ws = require('ws');
16-
return ws;
17-
} catch (e) {
18-
throw new Error('WebSocket implementation not available. Install ws package for Node.js environments.');
19-
}
8+
let WebSocketImpl: any;
9+
10+
if (typeof window !== 'undefined' && window.WebSocket) {
11+
// Browser environment
12+
WebSocketImpl = window.WebSocket;
13+
} else {
14+
// Node.js environment
15+
try {
16+
// eslint-disable-next-line @typescript-eslint/no-var-requires
17+
const ws = require('ws');
18+
WebSocketImpl = ws;
19+
} catch (e) {
20+
throw new Error('WebSocket implementation not available. Install ws package for Node.js environments.');
2021
}
21-
})();
22+
}
2223

2324
export interface WebSocketClientOptions {
2425
host: string;

0 commit comments

Comments
 (0)