diff --git a/webapp/chat-app/.gitignore b/webapp/chat-app/.gitignore index 26621e8d..2e461737 100644 --- a/webapp/chat-app/.gitignore +++ b/webapp/chat-app/.gitignore @@ -21,12 +21,7 @@ node_modules npm-debug.log* yarn-debug.log* yarn-error.log* -# Gradle files (this is not a Gradle project) -*.gradle -*.gradle.kts -/gradle/ -gradlew -gradlew.bat +# Remove any Gradle-related entries if they exist # dependencies /node_modules /.pnp @@ -47,7 +42,4 @@ gradlew.bat # IDE .idea/ .vscode/ - *.iml - # Gradle - .gradle/ - build/ \ No newline at end of file + *.iml \ No newline at end of file diff --git a/webapp/chat-app/chat-app/.gitignore b/webapp/chat-app/chat-app/.gitignore new file mode 100644 index 00000000..6ec10967 --- /dev/null +++ b/webapp/chat-app/chat-app/.gitignore @@ -0,0 +1,25 @@ ++ # Node ++ node_modules/ ++ build/ ++ dist/ ++ coverage/ ++ ++ # Gradle ++ .gradle/ ++ build/ ++ ++ # IDE ++ .idea/ ++ .vscode/ ++ *.iml ++ ++ # Misc ++ .DS_Store ++ .env.local ++ .env.development.local ++ .env.test.local ++ .env.production.local ++ ++ npm-debug.log* ++ yarn-debug.log* ++ yarn-error.log* \ No newline at end of file diff --git a/webapp/chat-app/src/services/websocket.ts b/webapp/chat-app/src/services/websocket.ts index 4ff495a7..1b1cfd04 100644 --- a/webapp/chat-app/src/services/websocket.ts +++ b/webapp/chat-app/src/services/websocket.ts @@ -13,6 +13,9 @@ export class WebSocketService { private errorHandlers: ((error: Error) => void)[] = []; private isReconnecting = false; private connectionTimeout: NodeJS.Timeout | null = null; + private connectionStartTime = 0; + private messageBuffer: Message[] = []; + private bufferTimeout: NodeJS.Timeout | null = null; public getSessionId(): string { console.debug('[WebSocket] Getting session ID:', this.sessionId); @@ -192,6 +195,7 @@ export class WebSocketService { console.log('[WebSocket] Connection established successfully'); this.reconnectAttempts = 0; this.isReconnecting = false; + this.connectionStartTime = Date.now(); this.connectionHandlers.forEach(handler => handler(true)); if (this.connectionTimeout) { clearTimeout(this.connectionTimeout); @@ -200,6 +204,9 @@ export class WebSocketService { }; this.ws.onmessage = (event) => { this.debugLog('Message received'); + const currentTime = Date.now(); + const timeSinceConnection = currentTime - this.connectionStartTime; + const shouldBuffer = timeSinceConnection < 10000; // First 10 seconds // Find the first two comma positions to extract id and version const firstComma = event.data.indexOf(','); const secondComma = event.data.indexOf(',', firstComma + 1); @@ -241,11 +248,30 @@ export class WebSocketService { console.log('[WebSocket] Processing HTML message'); } - this.messageHandlers.forEach((handler) => handler(message)); + if (shouldBuffer) { + this.messageBuffer.push(message); + if (this.bufferTimeout) { + clearTimeout(this.bufferTimeout); + } + this.bufferTimeout = setTimeout(() => { + const messages = [...this.messageBuffer]; + this.messageBuffer = []; + messages.forEach(msg => { + this.messageHandlers.forEach(handler => handler(msg)); + }); + }, 1000); + } else { + this.messageHandlers.forEach((handler) => handler(message)); + } }; this.ws.onclose = () => { console.log('[WebSocket] Connection closed, stopping heartbeat'); + if (this.bufferTimeout) { + clearTimeout(this.bufferTimeout); + this.bufferTimeout = null; + } + this.messageBuffer = []; this.stopHeartbeat(); this.connectionHandlers.forEach(handler => handler(false)); if (!this.isReconnecting) {