mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
usprawnienia pobierania danych; statusy SWDR na semaforze
This commit is contained in:
+3
-47
@@ -47,8 +47,6 @@ import TrainModal from './components/TrainsView/TrainModal.vue';
|
||||
import StorageManager from './managers/storageManager';
|
||||
import { useApiStore } from './store/apiStore';
|
||||
import { Status } from './typings/common';
|
||||
import { Websocket } from './typings/api';
|
||||
import socket from './websocket';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -88,39 +86,7 @@ export default defineComponent({
|
||||
this.setReleaseURL();
|
||||
this.setupOfflineHandling();
|
||||
|
||||
this.apiStore.setupStaticAPIData();
|
||||
this.connectToWebsocket();
|
||||
},
|
||||
|
||||
async connectToWebsocket() {
|
||||
this.apiStore.dataStatuses.connection = Status.Data.Loading;
|
||||
|
||||
console.log('ws connecting');
|
||||
|
||||
socket.on('connect_error', (err) => {
|
||||
console.error(`WS connection error: ${err.message}`);
|
||||
|
||||
this.apiStore.dataStatuses.connection = Status.Data.Error;
|
||||
this.apiStore.websocketData = undefined;
|
||||
});
|
||||
|
||||
let timeFrom = Date.now();
|
||||
socket.on('connect', () => {
|
||||
socket.emit('CONNECTION', { version: packageInfo.version }, () => {
|
||||
console.log(`Connection time: ${Date.now() - timeFrom}ms`);
|
||||
});
|
||||
|
||||
console.log('ws connected');
|
||||
});
|
||||
|
||||
socket.on('UPDATE', (data: Websocket.Payload) => {
|
||||
console.log('ws update');
|
||||
|
||||
this.apiStore.websocketData = data;
|
||||
this.apiStore.dataStatuses.connection = Status.Data.Loaded;
|
||||
});
|
||||
|
||||
this.fetchWebsocketData();
|
||||
this.apiStore.setupAPIData();
|
||||
},
|
||||
|
||||
setupOfflineHandling() {
|
||||
@@ -135,24 +101,14 @@ export default defineComponent({
|
||||
handleOfflineMode() {
|
||||
this.store.isOffline = true;
|
||||
|
||||
this.apiStore.websocketData = undefined;
|
||||
this.apiStore.activeData = undefined;
|
||||
this.apiStore.dataStatuses.connection = Status.Data.Offline;
|
||||
},
|
||||
|
||||
handleOnlineMode() {
|
||||
this.store.isOffline = false;
|
||||
|
||||
this.apiStore.setupStaticAPIData();
|
||||
this.connectToWebsocket();
|
||||
},
|
||||
|
||||
fetchWebsocketData() {
|
||||
socket.emit('FETCH_DATA', (data: Websocket.Payload) => {
|
||||
console.log('ws fetch data');
|
||||
|
||||
this.apiStore.websocketData = data;
|
||||
this.apiStore.dataStatuses.connection = Status.Data.Loaded;
|
||||
});
|
||||
this.apiStore.setupAPIData();
|
||||
},
|
||||
|
||||
changeLang(lang: string) {
|
||||
|
||||
Reference in New Issue
Block a user