mirror of
https://github.com/smartyellow/status.git
synced 2025-01-18 21:47:58 +00:00
Dashboard bell
Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
parent
e0e51d7ad6
commit
87635c790a
@ -3,7 +3,7 @@
|
||||
import TileRawValue from './tile-rawvalue.svelte';
|
||||
import Settings from './settings.svelte';
|
||||
import { flip } from 'svelte/animate';
|
||||
import { shuffle } from './lib';
|
||||
import { shuffle, ringBell } from './lib';
|
||||
|
||||
const [ send, receive ] = shuffle;
|
||||
const size = 3 * 4 - 1;
|
||||
@ -43,7 +43,8 @@
|
||||
ws.onmessage = async evt => {
|
||||
const data = JSON.parse(evt.data || '""');
|
||||
|
||||
if (data.cmd === 'data') {
|
||||
switch (data.cmd) {
|
||||
case 'data':
|
||||
let servicesTemp = [];
|
||||
const { servicesUp, servicesDown, servicesUnknown, total } = data;
|
||||
const upOrUnknown = [ ...servicesUp, ...servicesUnknown ];
|
||||
@ -66,6 +67,14 @@
|
||||
}
|
||||
|
||||
tiles = servicesTemp;
|
||||
break;
|
||||
|
||||
case 'bell':
|
||||
ringBell();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,3 +34,10 @@ export const shuffle = crossfade({
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
//export const ringBell = bell.play;
|
||||
|
||||
export function ringBell() {
|
||||
const bell = new Audio('http://__SERVER__/statusdashboard/sound');
|
||||
bell.addEventListener('canplaythrough', () => bell.play());
|
||||
}
|
||||
|
BIN
gui/sounds/bell.wav
Normal file
BIN
gui/sounds/bell.wav
Normal file
Binary file not shown.
8
index.js
8
index.js
@ -569,6 +569,14 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
|
||||
{ route: '/statusdashboard/sound',
|
||||
method: 'get',
|
||||
handler: (req, res) => {
|
||||
res.headers['content-type'] = 'audio/x-wav';
|
||||
res.sendFile(__dirname + '/gui/sounds/bell.wav');
|
||||
},
|
||||
},
|
||||
|
||||
],
|
||||
|
||||
};
|
||||
|
@ -4,6 +4,8 @@ const { makeId } = require('core/makeid');
|
||||
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
let uws;
|
||||
let downIdsBefore = [];
|
||||
let downIdsAfter = [];
|
||||
|
||||
const mapService = (s, beat) => ({
|
||||
id: s.id,
|
||||
@ -30,7 +32,7 @@ async function createDashboardSocket(server) {
|
||||
const servicesUp = [];
|
||||
const servicesDown = [];
|
||||
const servicesUnknown = [];
|
||||
console.log(heartbeats);
|
||||
downIdsAfter = [];
|
||||
|
||||
for (let service of services) {
|
||||
const beat = heartbeats.find(b => b.webservice === service.id);
|
||||
@ -41,6 +43,7 @@ async function createDashboardSocket(server) {
|
||||
}
|
||||
else if (beat.down) {
|
||||
servicesDown.push(service);
|
||||
downIdsAfter.push(service.id);
|
||||
}
|
||||
else {
|
||||
servicesUp.push(service);
|
||||
@ -53,7 +56,19 @@ async function createDashboardSocket(server) {
|
||||
...servicesUnknown,
|
||||
].length;
|
||||
|
||||
let newOutage = false;
|
||||
for (const id of downIdsAfter) {
|
||||
if (!downIdsBefore.includes(id)) {
|
||||
newOutage = true;
|
||||
}
|
||||
}
|
||||
downIdsBefore = JSON.parse(JSON.stringify(downIdsAfter));
|
||||
|
||||
try {
|
||||
if (newOutage) {
|
||||
ws.send(JSON.stringify({ cmd: 'bell' }));
|
||||
}
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
cmd: 'data',
|
||||
servicesUp,
|
||||
|
Loading…
Reference in New Issue
Block a user