diff --git a/kdb-web/src/app/services/socket/socket.service.ts b/kdb-web/src/app/services/socket/socket.service.ts index 66b07cb175..a5520b3fc3 100644 --- a/kdb-web/src/app/services/socket/socket.service.ts +++ b/kdb-web/src/app/services/socket/socket.service.ts @@ -7,7 +7,7 @@ import io from "socket.io-client"; import { MessageService } from "primeng/api"; @Injectable({ - providedIn: 'root' + providedIn: "root" }) export class SocketService { private socket: any; @@ -17,36 +17,34 @@ export class SocketService { private settingsService: SettingsService, private toastService: ToastService, private spinnerService: SpinnerService, - private messageService: MessageService, + private messageService: MessageService ) { } startSocket() { - this.socket = io(`${this.settingsService.getApiURL()}`, {path: '/api/socket.io'}) - this.socket.on('connect', () => { + this.socket = io(`${this.settingsService.getApiURL()}`, { path: "/api/socket.io" }); + this.socket.on("connect", () => { if (this.disconnected) { - if (this.spinnerService.showSpinnerState) { - this.spinnerService.hideSpinner(); - const options: ToastOptions = { - closable: false - }; - this.messageService.clear(); - this.toastService.info("Server verbunden", "Die Verbindung zum Server konnte hergestellt werden.", options); - } + this.spinnerService.hideSpinner(); + const options: ToastOptions = { + closable: false + }; + this.messageService.clear(); + this.toastService.info("Server verbunden", "Die Verbindung zum Server konnte hergestellt werden.", options); } this.disconnected = false; - console.log('Connected!') + console.info("Connected!"); }); - this.socket.on('connect_error', (err: Error) => { + this.socket.on("connect_error", (err: Error) => { if (this.disconnected) { this.spinnerService.showSpinner(); return; } + console.warn("Connect error!"); this.disconnected = true; - const options: ToastOptions = { sticky: true, closable: false @@ -56,8 +54,13 @@ export class SocketService { console.error(err.toString()); }); - this.socket.on('disconnect', () => { - console.log('Disconnected!'); + this.socket.on("disconnect", () => { + if (this.disconnected) { + return; + } + + console.warn("Disconnected!"); + this.disconnected = true; const options: ToastOptions = { sticky: true, closable: false