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 TileRawValue from './tile-rawvalue.svelte';
|
||||||
import Settings from './settings.svelte';
|
import Settings from './settings.svelte';
|
||||||
import { flip } from 'svelte/animate';
|
import { flip } from 'svelte/animate';
|
||||||
import { shuffle } from './lib';
|
import { shuffle, ringBell } from './lib';
|
||||||
|
|
||||||
const [ send, receive ] = shuffle;
|
const [ send, receive ] = shuffle;
|
||||||
const size = 3 * 4 - 1;
|
const size = 3 * 4 - 1;
|
||||||
@ -43,29 +43,38 @@
|
|||||||
ws.onmessage = async evt => {
|
ws.onmessage = async evt => {
|
||||||
const data = JSON.parse(evt.data || '""');
|
const data = JSON.parse(evt.data || '""');
|
||||||
|
|
||||||
if (data.cmd === 'data') {
|
switch (data.cmd) {
|
||||||
let servicesTemp = [];
|
case 'data':
|
||||||
const { servicesUp, servicesDown, servicesUnknown, total } = data;
|
let servicesTemp = [];
|
||||||
const upOrUnknown = [ ...servicesUp, ...servicesUnknown ];
|
const { servicesUp, servicesDown, servicesUnknown, total } = data;
|
||||||
servicesTemp = servicesDown.slice(0, size);
|
const upOrUnknown = [ ...servicesUp, ...servicesUnknown ];
|
||||||
|
servicesTemp = servicesDown.slice(0, size);
|
||||||
|
|
||||||
if (pageNum === -1 || total >= size) {
|
if (pageNum === -1 || total >= size) {
|
||||||
pageNum++;
|
pageNum++;
|
||||||
|
|
||||||
if (pageNum > Math.ceil(upOrUnknown.length / size)) {
|
if (pageNum > Math.ceil(upOrUnknown.length / size)) {
|
||||||
pageNum = 0;
|
pageNum = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const placesLeft = size - servicesTemp.length;
|
const placesLeft = size - servicesTemp.length;
|
||||||
const offset = placesLeft * pageNum;
|
const offset = placesLeft * pageNum;
|
||||||
if (placesLeft > 0) {
|
if (placesLeft > 0) {
|
||||||
servicesTemp.push(
|
servicesTemp.push(
|
||||||
...upOrUnknown.slice(offset, placesLeft + offset)
|
...upOrUnknown.slice(offset, placesLeft + offset)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
tiles = servicesTemp;
|
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');
|
const decoder = new TextDecoder('utf-8');
|
||||||
let uws;
|
let uws;
|
||||||
|
let downIdsBefore = [];
|
||||||
|
let downIdsAfter = [];
|
||||||
|
|
||||||
const mapService = (s, beat) => ({
|
const mapService = (s, beat) => ({
|
||||||
id: s.id,
|
id: s.id,
|
||||||
@ -30,7 +32,7 @@ async function createDashboardSocket(server) {
|
|||||||
const servicesUp = [];
|
const servicesUp = [];
|
||||||
const servicesDown = [];
|
const servicesDown = [];
|
||||||
const servicesUnknown = [];
|
const servicesUnknown = [];
|
||||||
console.log(heartbeats);
|
downIdsAfter = [];
|
||||||
|
|
||||||
for (let service of services) {
|
for (let service of services) {
|
||||||
const beat = heartbeats.find(b => b.webservice === service.id);
|
const beat = heartbeats.find(b => b.webservice === service.id);
|
||||||
@ -41,6 +43,7 @@ async function createDashboardSocket(server) {
|
|||||||
}
|
}
|
||||||
else if (beat.down) {
|
else if (beat.down) {
|
||||||
servicesDown.push(service);
|
servicesDown.push(service);
|
||||||
|
downIdsAfter.push(service.id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
servicesUp.push(service);
|
servicesUp.push(service);
|
||||||
@ -53,7 +56,19 @@ async function createDashboardSocket(server) {
|
|||||||
...servicesUnknown,
|
...servicesUnknown,
|
||||||
].length;
|
].length;
|
||||||
|
|
||||||
|
let newOutage = false;
|
||||||
|
for (const id of downIdsAfter) {
|
||||||
|
if (!downIdsBefore.includes(id)) {
|
||||||
|
newOutage = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
downIdsBefore = JSON.parse(JSON.stringify(downIdsAfter));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (newOutage) {
|
||||||
|
ws.send(JSON.stringify({ cmd: 'bell' }));
|
||||||
|
}
|
||||||
|
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
cmd: 'data',
|
cmd: 'data',
|
||||||
servicesUp,
|
servicesUp,
|
||||||
|
Loading…
Reference in New Issue
Block a user