Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ba83ad538 | ||
|
|
fe6a36f3dc |
@@ -20,7 +20,9 @@ export default function RootLayout({
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body className="bg-gray-900 text-white antialiased">
|
<body className="bg-gray-900 text-white antialiased">
|
||||||
<QueryProvider>
|
<QueryProvider>
|
||||||
<WebSocketProvider>
|
<WebSocketProvider
|
||||||
|
websocketURL={process.env.NEXT_PUBLIC_WEBSOCKET_URL || 'ws://localhost:3000/ws'}
|
||||||
|
>
|
||||||
<SteamCMDProvider>
|
<SteamCMDProvider>
|
||||||
<ServerCreationPopupProvider>
|
<ServerCreationPopupProvider>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -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, url: string) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
this.baseUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
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');
|
||||||
|
|||||||
@@ -30,9 +30,10 @@ export function useWebSocket() {
|
|||||||
|
|
||||||
interface WebSocketProviderProps {
|
interface WebSocketProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
|
websocketURL: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WebSocketProvider({ children }: WebSocketProviderProps) {
|
export function WebSocketProvider({ children, websocketURL }: WebSocketProviderProps) {
|
||||||
const [client, setClient] = useState<WebSocketClient | null>(null);
|
const [client, setClient] = useState<WebSocketClient | null>(null);
|
||||||
const [isConnected, setIsConnected] = useState(false);
|
const [isConnected, setIsConnected] = useState(false);
|
||||||
const [connectionStatus, setConnectionStatus] = useState<
|
const [connectionStatus, setConnectionStatus] = useState<
|
||||||
@@ -50,7 +51,7 @@ export function WebSocketProvider({ children }: WebSocketProviderProps) {
|
|||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
const newClient = new WebSocketClient(token);
|
const newClient = new WebSocketClient(token, websocketURL);
|
||||||
|
|
||||||
const statusHandler: ConnectionStatusHandler = (status, error) => {
|
const statusHandler: ConnectionStatusHandler = (status, error) => {
|
||||||
setConnectionStatus(status);
|
setConnectionStatus(status);
|
||||||
|
|||||||
Reference in New Issue
Block a user