-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResonateInstallWPA.js
72 lines (67 loc) · 2.14 KB
/
ResonateInstallWPA.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
// VV WPA support
const CACHE_NAME = `Resonate`;
// Use the install event to pre-cache all initial resources.
self.addEventListener('install', event => {
event.waitUntil((async () => {
const cache = await caches.open(CACHE_NAME);
cache.addAll([
'./Resonate.js',
'./Resonate.wasm',
'./index.html',
'./icons/ResonateIcon.png',
'./icons/ResonateIconLarge.png',
'./icons/ResonateIconUnsaved.png',
'./plugins/audiostretchworker.js',
'./plugins/zip.js',
'./plugins/LoadingScreenWorker.js',
'./plugins/timestretch.js',
'./plugins/RubberBand.js',
'./plugins/RubberBand.js.mem',
'./plugins/paulstretch.js',
'./plugins/VexWarp/tools.js',
'./plugins/VexWarp/stretch.js',
'./plugins/VexWarp/require.js',
'./plugins/VexWarp/main.js',
'./plugins/VexWarp/jquery-2.0.3.js',
'./plugins/VexWarp/dsp.js',
]);
})());
});
self.addEventListener('fetch', event => {
event.respondWith((async () => {
const cache = await caches.open(CACHE_NAME);
//const injectHeaders = (request)=>{
// const headers = new Headers(request.headers);
// headers.set('Cross-Origin-Embedder-Policy', 'require-corp');
// headers.set('Cross-Origin-Opener-Policy', 'same-origin');
// const newRequest = new Request(request, {
// mode: request.mode,
// credentials: request.credentials,
// headers: headers
// });
// return newRequest;
//};
// Get the resource from the cache.
//const cachedResponse = await cache.match(event.request);
//if (cachedResponse) {
// return cachedResponse;
//} else {
try {
// If the resource was not in the cache, try the network.
//const fetchResponse = await fetch(injectHeaders(event.request));
const fetchResponse = await fetch(event.request);
if(event.request.method != 'POST'){
// Save the resource in the cache and return it.
cache.put(event.request, fetchResponse.clone());
}
return fetchResponse;
} catch (e) {
// The network failed.
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
return cachedResponse;
}
}
//}
})());
});