From d62e8537baf954e3170b2b668b451f2572970b72 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Fri, 24 Feb 2023 10:07:08 +0100 Subject: [PATCH] Fixed bell --- gui/dashboard/apiclient.js | 20 +++----------------- gui/dashboard/app.svelte | 11 ++++++++--- gui/dashboard/settings.svelte | 9 ++++++--- index.js | 33 ++++++++------------------------- 4 files changed, 25 insertions(+), 48 deletions(-) diff --git a/gui/dashboard/apiclient.js b/gui/dashboard/apiclient.js index fb75e7c..6f33e11 100644 --- a/gui/dashboard/apiclient.js +++ b/gui/dashboard/apiclient.js @@ -1,5 +1,3 @@ -import { ringBell } from './lib'; - const socketUrl = window.location.href.replace('http', 'ws') + '/socket'; let reconnectAttempts = 0; let ws; @@ -8,20 +6,8 @@ export async function connect({ onData }) { ws = new WebSocket(socketUrl); ws.onmessage = async evt => { - const data = JSON.parse(evt.data || 'false'); - - switch (data.cmd) { - case 'data': - onData(data); - break; - - case 'bell': - ringBell(); - break; - - default: - break; - } + const data = JSON.parse(evt.data || '{}'); + onData(data); }; ws.onopen = () => { @@ -36,5 +22,5 @@ export async function connect({ onData }) { await connect({ onData }); }; - ws.onerror = err => console.error('Connection error', err); + ws.onerror = err => console.error('Connection error:', err); } diff --git a/gui/dashboard/app.svelte b/gui/dashboard/app.svelte index d37e729..31fa8de 100644 --- a/gui/dashboard/app.svelte +++ b/gui/dashboard/app.svelte @@ -3,7 +3,7 @@ import Tile from './tile.svelte'; import Settings from './settings.svelte'; import { flip } from 'svelte/animate'; - import { settings, shuffle } from './lib'; + import { ringBell, settings, shuffle } from './lib'; import { connect } from './apiclient'; const [ send, receive ] = shuffle; @@ -91,13 +91,18 @@ onMount(async () => { await connect({ - onData: data => { - allTiles = data.tiles?.map(tile => { + onData: ({ tiles, newOutage }) => { + allTiles = tiles?.map(tile => { if (tile?.service?.checked) { tile.service.checked = new Date(tile.service.checked); } return tile; }); + + if (newOutage) { + ringBell(); + } + organiseGrid(); hasData = true; }, diff --git a/gui/dashboard/settings.svelte b/gui/dashboard/settings.svelte index c941111..cb8dd74 100644 --- a/gui/dashboard/settings.svelte +++ b/gui/dashboard/settings.svelte @@ -1,6 +1,6 @@