1 Commits

Author SHA1 Message Date
Fran Jurmanović
fe6a36f3dc move websocket base url inside of constructor 2025-09-18 22:56:47 +02:00

View File

@@ -1,5 +1,3 @@
const BASE_URL = process.env.NEXT_PUBLIC_WEBSOCKET_URL || 'ws://localhost:3000/ws';
export interface WebSocketMessage { export interface WebSocketMessage {
type: 'step' | 'steam_output' | 'error' | 'complete'; type: 'step' | 'steam_output' | 'error' | 'complete';
server_id: string; server_id: string;
@@ -57,9 +55,11 @@ export class WebSocketClient {
private reconnectTimer: NodeJS.Timeout | null = null; private reconnectTimer: NodeJS.Timeout | null = null;
private shouldReconnect = true; private shouldReconnect = true;
private associatedServerId: string | null = null; private associatedServerId: string | null = null;
private baseUrl: string;
constructor(token: string) { constructor(token: string) {
this.token = token; this.token = token;
this.baseUrl = process.env.NEXT_PUBLIC_WEBSOCKET_URL || 'ws://localhost:3000/ws';
} }
connect(): Promise<void> { connect(): Promise<void> {
@@ -72,7 +72,7 @@ export class WebSocketClient {
this.connectionPromise = new Promise((resolve, reject) => { this.connectionPromise = new Promise((resolve, reject) => {
try { try {
this.ws = new WebSocket(`${BASE_URL}?token=${this.token}`); this.ws = new WebSocket(`${this.baseUrl}?token=${this.token}`);
this.ws.onopen = () => { this.ws.onopen = () => {
console.log('WebSocket connected'); console.log('WebSocket connected');