ctucx.git: mqtt-webui

webui for mqtt, can be used to control/display data in mqtt-topics

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
'use strict';

let preCache = [
	'./',
	'./manifest.json',
	'./sw.js',
	'./bundle.js',
	'./bundle.css',
	'./favicon-512x512.png',

	'./icons/air_conditioning_indoor.png',
	'./icons/air_conditioning_outdoor.png',
	'./icons/alarm.png',
	'./icons/bulb.png',
	'./icons/cold.png',
	'./icons/dome_camera.png',
	'./icons/door_handle.png',
	'./icons/doorbell.png',
	'./icons/drop.png',
	'./icons/electric_range.png',
	'./icons/eye.png',
	'./icons/garage.png',
	'./icons/heater.png',
	'./icons/houseplant.png',
	'./icons/ip_camera.png',
	'./icons/key.png',
	'./icons/lock_a.png',
	'./icons/lock_b.png',
	'./icons/loudspeakers.png',
	'./icons/pet.png',
	'./icons/plug.png',
	'./icons/pool.png',
	'./icons/power.png',
	'./icons/power_button.png',
	'./icons/recycling.png',
	'./icons/remote_control.png',
	'./icons/router.png',
	'./icons/smartphone.png',
	'./icons/socket_f.png',
	'./icons/socket_g.png',
	'./icons/socket_i.png',
	'./icons/solar_panel.png',
	'./icons/sun.png',
	'./icons/temperature.png',
	'./icons/thermostat.png',
	'./icons/tv.png',
	'./icons/vacuum_cleaning_robot.png',
	'./icons/ventilation.png',
	'./icons/washer.png',
	'./icons/weather.png'
];

const CACHE = 'cache-v7';

self.addEventListener('install', function (evt) {
	self.skipWaiting();
	evt.waitUntil(caches.open(CACHE).then(function (cache) {
		cache.addAll(preCache);
	}));
});

self.addEventListener('fetch', function (evt) {
	evt.respondWith(fromCache(evt.request).then(function (match) {
		if (match) {
			return match;
		} else {
			return fetch(evt.request);
		}
	}));
});

self.addEventListener('activate', function (event) {
	event.waitUntil(clients.claim());
	event.waitUntil(clients.claim().then(function () {
		return caches.keys().then(function (cacheNames) {
			return Promise.all(cacheNames.filter(c => c !== CACHE).map(c => caches.delete(c)));
		});
	}));
});

function fromCache (request) {
	return caches.open(CACHE).then(function (cache) {
		return cache.match(request);
	});
}