mirror of
https://github.com/smartyellow/status.git
synced 2025-04-10 16:11:02 +00:00
Fixed bell
This commit is contained in:
parent
c27cf5c186
commit
d62e8537ba
@ -1,5 +1,3 @@
|
|||||||
import { ringBell } from './lib';
|
|
||||||
|
|
||||||
const socketUrl = window.location.href.replace('http', 'ws') + '/socket';
|
const socketUrl = window.location.href.replace('http', 'ws') + '/socket';
|
||||||
let reconnectAttempts = 0;
|
let reconnectAttempts = 0;
|
||||||
let ws;
|
let ws;
|
||||||
@ -8,20 +6,8 @@ export async function connect({ onData }) {
|
|||||||
ws = new WebSocket(socketUrl);
|
ws = new WebSocket(socketUrl);
|
||||||
|
|
||||||
ws.onmessage = async evt => {
|
ws.onmessage = async evt => {
|
||||||
const data = JSON.parse(evt.data || 'false');
|
const data = JSON.parse(evt.data || '{}');
|
||||||
|
onData(data);
|
||||||
switch (data.cmd) {
|
|
||||||
case 'data':
|
|
||||||
onData(data);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'bell':
|
|
||||||
ringBell();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
@ -36,5 +22,5 @@ export async function connect({ onData }) {
|
|||||||
await connect({ onData });
|
await connect({ onData });
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = err => console.error('Connection error', err);
|
ws.onerror = err => console.error('Connection error:', err);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import Tile from './tile.svelte';
|
import Tile from './tile.svelte';
|
||||||
import Settings from './settings.svelte';
|
import Settings from './settings.svelte';
|
||||||
import { flip } from 'svelte/animate';
|
import { flip } from 'svelte/animate';
|
||||||
import { settings, shuffle } from './lib';
|
import { ringBell, settings, shuffle } from './lib';
|
||||||
import { connect } from './apiclient';
|
import { connect } from './apiclient';
|
||||||
|
|
||||||
const [ send, receive ] = shuffle;
|
const [ send, receive ] = shuffle;
|
||||||
@ -91,13 +91,18 @@
|
|||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await connect({
|
await connect({
|
||||||
onData: data => {
|
onData: ({ tiles, newOutage }) => {
|
||||||
allTiles = data.tiles?.map(tile => {
|
allTiles = tiles?.map(tile => {
|
||||||
if (tile?.service?.checked) {
|
if (tile?.service?.checked) {
|
||||||
tile.service.checked = new Date(tile.service.checked);
|
tile.service.checked = new Date(tile.service.checked);
|
||||||
}
|
}
|
||||||
return tile;
|
return tile;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (newOutage) {
|
||||||
|
ringBell();
|
||||||
|
}
|
||||||
|
|
||||||
organiseGrid();
|
organiseGrid();
|
||||||
hasData = true;
|
hasData = true;
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import Modal from './modal.svelte';
|
import Modal from './modal.svelte';
|
||||||
import { settings } from './lib';
|
import { ringBell, settings } from './lib';
|
||||||
|
|
||||||
let open = false;
|
let open = false;
|
||||||
let showCopyCheck = false;
|
let showCopyCheck = false;
|
||||||
@ -43,6 +43,9 @@
|
|||||||
</svg>
|
</svg>
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
|
<button on:click={ringBell} class="btn">
|
||||||
|
Test bell
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
@ -87,9 +90,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
button.copy svg {
|
button.copy svg {
|
||||||
fill: var(--green);
|
fill: currentColor;
|
||||||
height: 1rem;
|
height: 1rem;
|
||||||
width: 1rem;
|
width: 1rem;
|
||||||
margin-left: 1rem;
|
margin-left: 0.5rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
33
index.js
33
index.js
@ -349,9 +349,9 @@ module.exports = {
|
|||||||
order: 100,
|
order: 100,
|
||||||
purpose: 'Start the websocket for the dashboard after boot',
|
purpose: 'Start the websocket for the dashboard after boot',
|
||||||
handler: () => {
|
handler: () => {
|
||||||
const decoder = new TextDecoder('utf-8');
|
|
||||||
let downIdsBefore = [];
|
let downIdsBefore = [];
|
||||||
let downIdsAfter = [];
|
let downIdsAfter = [];
|
||||||
|
let newOutage = false;
|
||||||
|
|
||||||
const mapService = (s, beat) => ({
|
const mapService = (s, beat) => ({
|
||||||
id: s.id,
|
id: s.id,
|
||||||
@ -374,9 +374,7 @@ module.exports = {
|
|||||||
.find({ webservice: { $in: services.map(s => s.id) } })
|
.find({ webservice: { $in: services.map(s => s.id) } })
|
||||||
.sort({ date: -1 })
|
.sort({ date: -1 })
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
const tiles = [];
|
const tiles = [];
|
||||||
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);
|
||||||
@ -408,46 +406,31 @@ module.exports = {
|
|||||||
// Let other plugins enrich dashboard tiles with custom badges and priorities.
|
// Let other plugins enrich dashboard tiles with custom badges and priorities.
|
||||||
await server.executePostHooks('pupulateDashboardTiles', { tiles });
|
await server.executePostHooks('pupulateDashboardTiles', { tiles });
|
||||||
|
|
||||||
let newOutage = false;
|
// Check if there are new outages and report them by ringing a bell on the dashboard.
|
||||||
|
newOutage = false;
|
||||||
for (const id of downIdsAfter) {
|
for (const id of downIdsAfter) {
|
||||||
if (!downIdsBefore.includes(id)) {
|
if (!downIdsBefore.includes(id)) {
|
||||||
newOutage = true;
|
newOutage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
downIdsBefore = [ ...downIdsAfter ];
|
downIdsBefore = [ ...downIdsAfter ];
|
||||||
|
downIdsAfter = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (newOutage) {
|
const json = JSON.stringify({ newOutage, tiles });
|
||||||
ws.send(JSON.stringify({ cmd: 'bell' }));
|
ws.send(json);
|
||||||
}
|
|
||||||
|
|
||||||
ws.send(JSON.stringify({ cmd: 'data', tiles: tiles }));
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send statuses on open and every 5 seconds.
|
||||||
sendStatuses();
|
sendStatuses();
|
||||||
setInterval(sendStatuses, 5000);
|
setInterval(sendStatuses, 5000);
|
||||||
},
|
},
|
||||||
onUpgrade: async () => ({ id: makeId(10) }),
|
onUpgrade: async () => ({ id: makeId(10) }),
|
||||||
onMessage: async (ws, msg) => {
|
onMessage: async () => { /* do nothing */ },
|
||||||
msg = JSON.parse(decoder.decode(msg));
|
|
||||||
|
|
||||||
if (!msg || !msg.command) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (msg.command) {
|
|
||||||
case 'data':
|
|
||||||
ws.send('data');
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user