@grame/faustwasm 0.4.2 → 0.4.3

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.
@@ -1,27 +1,76 @@
1
1
 
2
2
  const CACHE_NAME = 'FAUST_DSP-static'; // Cache name without versioning
3
3
 
4
+ const POLY_EFFECT_RESOURCES = [
5
+ '/FAUST_DSP/',
6
+ '/FAUST_DSP/faust-ui/index.js',
7
+ '/FAUST_DSP/faust-ui/index.css',
8
+ '/FAUST_DSP/faustwasm/index.js',
9
+ '/FAUST_DSP/FAUST_DSP.js',
10
+ '/FAUST_DSP/FAUST_DSP.wasm',
11
+ '/FAUST_DSP/FAUST_DSP.json',
12
+ '/FAUST_DSP/mixerModule.wasm',
13
+ '/FAUST_DSP/FAUST_DSP_effect.wasm',
14
+ '/FAUST_DSP/FAUST_DSP_effect.json',
15
+ ];
16
+
17
+ const POLY_RESOURCES = [
18
+ '/FAUST_DSP/',
19
+ '/FAUST_DSP/faust-ui/index.js',
20
+ '/FAUST_DSP/faust-ui/index.css',
21
+ '/FAUST_DSP/faustwasm/index.js',
22
+ '/FAUST_DSP/FAUST_DSP.js',
23
+ '/FAUST_DSP/FAUST_DSP.wasm',
24
+ '/FAUST_DSP/FAUST_DSP.json',
25
+ '/FAUST_DSP/mixerModule.wasm',
26
+ ];
27
+
28
+ /**
29
+ * Install the service worker and cache the resources
30
+
31
+ */
4
32
  self.addEventListener('install', event => {
5
33
  event.waitUntil(
6
34
  caches.open(CACHE_NAME).then(cache => {
7
35
  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
- });
36
+ const urlToCheck = '/FAUST_DSP/FAUST_DSP_effect.json';
37
+ return fetchResourceAndCache(cache, urlToCheck);
21
38
  })
22
39
  );
23
40
  });
24
41
 
42
+ /**
43
+ * Fetch the resources and cache them
44
+ *
45
+ * @param {Cache} cache The cache to store the resources
46
+ * @param {string} urlToCheck The URL of the resource to fetch
47
+ *
48
+ * @returns {Promise<void>} A promise that resolves when the resource is fetched and cached
49
+ */
50
+
51
+ function fetchResourceAndCache(cache, urlToCheck) {
52
+ return fetch(urlToCheck).then(response => {
53
+ if (response.ok) {
54
+ return cacheResources(cache, POLY_EFFECT_RESOURCES);
55
+ } else {
56
+ return cacheResources(cache, POLY_RESOURCES);
57
+ }
58
+ }).catch(fetchError => {
59
+ console.error(`Failed to fetch ${urlToCheck}:`, fetchError);
60
+ });
61
+ }
62
+ /**
63
+ *
64
+ * @param {*} cache The cache to store the resources
65
+ * @param {*} resources The resources to cache
66
+ * @returns
67
+ */
68
+ function cacheResources(cache, resources) {
69
+ return cache.addAll(resources).catch(error => {
70
+ console.error('Failed to cache resources:', error);
71
+ });
72
+ }
73
+
25
74
  self.addEventListener("activate", event => {
26
75
  console.log("Service worker activated");
27
76
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",