Fixed socket service #70
This commit is contained in:
parent
ea026b351e
commit
24a3a48478
@ -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,15 +17,14 @@ 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
|
||||
@ -33,20 +32,19 @@ export class SocketService {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user