-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.js
132 lines (98 loc) · 3.81 KB
/
worker.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/****************************************************************************
* worker.js
* openacousticdevices.info
* July 2024
*****************************************************************************/
/* global self, caches, fetch */
// TODO: Update this with changes
const VERSION = '4';
const cacheName = 'audiomothplay-v' + VERSION;
self.addEventListener('install', (e) => {
console.log('Caching assets for offline use');
e.waitUntil((async () => {
const cache = await caches.open(cacheName);
try {
await cache.addAll(['./index.html',
'./scripts/index.js',
'./scripts/amplitudeThreshold.js',
'./scripts/butterworth.js',
'./scripts/constants.js',
'./scripts/downsampler.js',
'./scripts/drawSVG.js',
'./scripts/exportAudio.js',
'./scripts/exportImages.js',
'./scripts/exportVideo.js',
'./scripts/goertzelFilter.js',
'./scripts/labelBuilding.js',
'./scripts/playAudio.js',
'./scripts/resampler.js',
'./scripts/sampleRateControl.js',
'./scripts/sliderControl.js',
'./scripts/spectrogram.js',
'./scripts/stft.js',
'./scripts/uiFiltering.js',
'./scripts/waveform.js',
'./scripts/wavPreviewer.js',
'./scripts/wavReader.js',
'./scripts/wavWriter.js',
'./scripts/external/bootstrap-slider.min.js',
'./scripts/external/bootstrap.bundle.min.js',
'./scripts/external/bootstrap.bundle.min.js.map',
'./scripts/external/complex.min.js',
'./scripts/external/ffmpeg-worker-mp4.js',
'./scripts/external/FreeSans-normal.js',
'./scripts/external/jquery-3.6.0.slim.min.js',
'./scripts/external/jspdf.umd.min.js',
'./scripts/external/jspdf.umd.min.js.map',
'./css/index.css',
'./css/loadingAnimation.css',
'./css/external/bootstrap-slider.css',
'./css/external/bootstrap.min.css',
'./css/external/bootstrap.min.css.map',
'./assets/BAT.WAV',
'./assets/camera-video.svg',
'./assets/camera.svg',
'./assets/chevron-double-left.svg',
'./assets/chevron-double-right.svg',
'./assets/chevron-left.svg',
'./assets/chevron-right.svg',
'./assets/download.svg',
'./assets/favicon.png',
'./assets/gear.svg',
'./assets/GitHub-Mark-32px.png',
'./assets/house.svg',
'./assets/icon.png',
'./assets/METRONOME.WAV',
'./assets/play.svg',
'./assets/stop.svg',
'./assets/SWEEP.WAV',
'./assets/zoom-in.svg',
'./assets/zoom-out.svg'
]);
} catch (error) {
console.error(error);
}
})());
});
self.addEventListener('fetch', (e) => {
e.respondWith((async () => {
const r = await caches.match(e.request);
if (r) {
return r;
}
const response = await fetch(e.request);
const cache = await caches.open(cacheName);
cache.put(e.request, response.clone());
return response;
})());
});
self.addEventListener('activate', (e) => {
e.waitUntil(caches.keys().then((keyList) => {
return Promise.all(keyList.map((key) => {
if (key === cacheName) {
return 0;
}
return caches.delete(key);
}));
}));
});