@grame/faustwasm 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
const CACHE_NAME = 'FAUST_DSP-static'; // Cache name without versioning
|
|
3
|
+
|
|
4
|
+
self.addEventListener('install', event => {
|
|
5
|
+
event.waitUntil(
|
|
6
|
+
caches.open(CACHE_NAME).then(cache => {
|
|
7
|
+
console.log("Service worker installed");
|
|
8
|
+
return cache.addAll([
|
|
9
|
+
'/FAUST_DSP/',
|
|
10
|
+
'/FAUST_DSP/faust-ui/index.js',
|
|
11
|
+
'/FAUST_DSP/faust-ui/index.css',
|
|
12
|
+
'/FAUST_DSP/faustwasm/index.js',
|
|
13
|
+
'/FAUST_DSP/FAUST_DSP.js',
|
|
14
|
+
'/FAUST_DSP/FAUST_DSP.wasm',
|
|
15
|
+
'/FAUST_DSP/FAUST_DSP.json',
|
|
16
|
+
'/FAUST_DSP/mixerModule.wasm',
|
|
17
|
+
]).catch(error => {
|
|
18
|
+
// Catch and log any errors during the caching process
|
|
19
|
+
console.error('Failed to cache resources during install:', error);
|
|
20
|
+
});
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
self.addEventListener("activate", event => {
|
|
26
|
+
console.log("Service worker activated");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
self.addEventListener('fetch', event => {
|
|
30
|
+
event.respondWith((async () => {
|
|
31
|
+
const cache = await caches.open(CACHE_NAME);
|
|
32
|
+
const cachedResponse = await cache.match(event.request);
|
|
33
|
+
if (cachedResponse) {
|
|
34
|
+
return cachedResponse;
|
|
35
|
+
} else {
|
|
36
|
+
try {
|
|
37
|
+
const fetchResponse = await fetch(event.request);
|
|
38
|
+
// Ensure the response is valid before caching it
|
|
39
|
+
if (event.request.method === 'GET' && fetchResponse && fetchResponse.status === 200 && fetchResponse.type === 'basic') {
|
|
40
|
+
cache.put(event.request, fetchResponse.clone());
|
|
41
|
+
}
|
|
42
|
+
return fetchResponse;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// Network access failure
|
|
45
|
+
console.log('Network access error', e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
})());
|
|
49
|
+
});
|
package/package.json
CHANGED
|
@@ -25,8 +25,13 @@ const copyWebStandaloneAssets = (outputDir, dspName, poly = false) => {
|
|
|
25
25
|
//cpSyncModify(templateHTMLPath, outputDir + `/${dspName}.html`, "FAUST_DSP", dspName);
|
|
26
26
|
cpSyncModify(templateHTMLPath, outputDir + `/index.html`, "FAUST_DSP", dspName);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (poly) {
|
|
29
|
+
const templateWorkerPath = path.join(__dirname, "../assets/standalone/service-worker-poly.js");
|
|
30
|
+
cpSyncModify(templateWorkerPath, outputDir + `/service-worker.js`, "FAUST_DSP", dspName);
|
|
31
|
+
} else {
|
|
32
|
+
const templateWorkerPath = path.join(__dirname, "../assets/standalone/service-worker.js");
|
|
33
|
+
cpSyncModify(templateWorkerPath, outputDir + `/service-worker.js`, "FAUST_DSP", dspName);
|
|
34
|
+
}
|
|
30
35
|
|
|
31
36
|
const templateIconPath = path.join(__dirname, "../assets/standalone/icon.png");
|
|
32
37
|
cpSync(templateIconPath, outputDir + `/icon.png`);
|