Skip to content

Commit

Permalink
Merge pull request #75 from davbauer/refactor-modes
Browse files Browse the repository at this point in the history
Load live data instantly
  • Loading branch information
davbauer authored Mar 27, 2024
2 parents a7c5a9c + fe0c93d commit 66dca72
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
8 changes: 0 additions & 8 deletions backend/classes/WebSocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ export default class WebSocketManager {

this.clients.push(clientWithID);
infoLog(`WS Client connection established (Id: ${clientWithID.id})`);
// Send initial data to the client immediately upon connection.
clientWithID.send(
JSON.stringify({
wsConnectionId: clientWithID.id ?? 'undefined',
event: 'liveDataUpdate',
data: LiveData.data
})
);

clientWithID.on('close', () => {
const index = this.clients.findIndex((client) => client.id === clientWithID.id);
Expand Down
8 changes: 8 additions & 0 deletions src/lib/api/services/ServiceLiveData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type LiveData from '$lib/models/LiveData';
import ApiBase from './ApiBase';

export default class extends ApiBase {
static async getLiveData(): Promise<LiveData> {
return this.get<LiveData>('livedata');
}
}
20 changes: 14 additions & 6 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import '../app.css';
import { appInfo, config, toasts } from '$lib/store';
import { appInfo, config, liveData, toasts } from '$lib/store';
import Toast from '$lib/components/Toast.svelte';
import { onMount } from 'svelte';
import ServiceAppInfo from '$lib/api/services/ServiceAppInfo';
Expand All @@ -10,20 +10,28 @@
import BackendTerminalWindow from '$lib/components/SectionBackendTerminal.svelte';
import SectionBackendTerminal from '$lib/components/SectionBackendTerminal.svelte';
import moment from 'moment';
import ServiceLiveData from '$lib/api/services/ServiceLiveData';
import { sendActivitySignal } from '$lib/utilities/UtilStoreActivityDot';
import { SignalStateType } from '$lib/models/SignalStateType';
let initApplication: 'ERROR' | 'SUCCESS' | 'LOADING' = 'LOADING';
onMount(() => {
Promise.all([ServiceAppInfo.getAppInfo(), ServiceConfig.getConfig()])
.then(([appInfoResponse, configResponse]) => {
Promise.all([
ServiceAppInfo.getAppInfo(),
ServiceConfig.getConfig(),
ServiceLiveData.getLiveData()
])
.then(([appInfoResponse, configResponse, liveDataResponse]) => {
appInfo.set(appInfoResponse);
console.log(JSON.stringify(configResponse, null, 2));
config.set(configResponse);
newSuccessToast('Loaded app info and config');
liveData.set(liveDataResponse);
sendActivitySignal(SignalStateType.LIVEDATA);
newSuccessToast('Loaded app info, config and liveData');
initApplication = 'SUCCESS';
})
.catch((_error) => {
newErrorToast('Error loading app info or config');
newErrorToast('Error loading app info, config and liveData');
initApplication = 'ERROR';
});
});
Expand Down

0 comments on commit 66dca72

Please sign in to comment.