update websocket url passing through server

This commit is contained in:
Fran Jurmanović
2025-09-18 23:14:45 +02:00
parent fe6a36f3dc
commit c02f67a946
3 changed files with 8 additions and 5 deletions

View File

@@ -20,7 +20,9 @@ export default function RootLayout({
<html lang="en">
<body className="bg-gray-900 text-white antialiased">
<QueryProvider>
<WebSocketProvider>
<WebSocketProvider
websocketURL={process.env.NEXT_PUBLIC_WEBSOCKET_URL || 'ws://localhost:3000/ws'}
>
<SteamCMDProvider>
<ServerCreationPopupProvider>
{children}

View File

@@ -57,9 +57,9 @@ export class WebSocketClient {
private associatedServerId: string | null = null;
private baseUrl: string;
constructor(token: string) {
constructor(token: string, url: string) {
this.token = token;
this.baseUrl = process.env.NEXT_PUBLIC_WEBSOCKET_URL || 'ws://localhost:3000/ws';
this.baseUrl = url;
}
connect(): Promise<void> {

View File

@@ -30,9 +30,10 @@ export function useWebSocket() {
interface WebSocketProviderProps {
children: ReactNode;
websocketURL: string;
}
export function WebSocketProvider({ children }: WebSocketProviderProps) {
export function WebSocketProvider({ children, websocketURL }: WebSocketProviderProps) {
const [client, setClient] = useState<WebSocketClient | null>(null);
const [isConnected, setIsConnected] = useState(false);
const [connectionStatus, setConnectionStatus] = useState<
@@ -50,7 +51,7 @@ export function WebSocketProvider({ children }: WebSocketProviderProps) {
client.disconnect();
}
const newClient = new WebSocketClient(token);
const newClient = new WebSocketClient(token, websocketURL);
const statusHandler: ConnectionStatusHandler = (status, error) => {
setConnectionStatus(status);