'Afraid to Ask' implemented
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user