'Afraid to Ask' implemented

This commit is contained in:
aodulov
2025-10-13 13:14:30 +03:00
parent 09269190c1
commit 5f8541a5f3
20 changed files with 2081 additions and 190 deletions

View File

@@ -2,6 +2,7 @@ class WebSocketService {
private ws: WebSocket | null = null;
private messageHandlers: ((message: any) => void)[] = [];
private errorHandlers: ((error: Event) => void)[] = [];
private sessionTerminatedHandlers: (() => void)[] = [];
private currentSessionId: string | null = null;
private currentClientId: string | null = null;
@@ -34,6 +35,7 @@ class WebSocketService {
this.ws.onclose = () => {
console.log('WebSocket disconnected');
this.sessionTerminatedHandlers.forEach(handler => handler());
this.ws = null;
this.currentSessionId = null;
this.currentClientId = null;
@@ -80,6 +82,14 @@ class WebSocketService {
removeErrorHandler(handler: (error: Event) => void) {
this.errorHandlers = this.errorHandlers.filter(h => h !== handler);
}
onSessionTerminated(handler: () => void) {
this.sessionTerminatedHandlers.push(handler);
}
removeSessionTerminatedHandler(handler: () => void) {
this.sessionTerminatedHandlers = this.sessionTerminatedHandlers.filter(h => h !== handler);
}
}
export const webSocketService = new WebSocketService();