@grame/faustwasm 0.3.2 → 0.4.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -76,8 +76,6 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
76
76
  async listenSensors() {
77
77
  if (this.hasAccInput) {
78
78
  const isAndroid: boolean = /Android/i.test(navigator.userAgent);
79
- console.log(navigator.userAgent);
80
- console.log(isAndroid);
81
79
  let handleDeviceMotion = null;
82
80
  if (isAndroid) {
83
81
  handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
@@ -242,7 +240,6 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
242
240
  this.port.postMessage({ type: "destroy" });
243
241
  this.port.close();
244
242
  }
245
-
246
243
  }
247
244
 
248
245
  /**
@@ -3,7 +3,18 @@ import type { AudioData, FaustDspMeta, FaustUIItem, LooseFaustDspFactory } from
3
3
 
4
4
  /** Read metadata and fetch soundfiles */
5
5
  class SoundfileReader {
6
- static get fallbackPaths() { return [location.href, location.origin]; }
6
+
7
+ // Set the fallback paths
8
+ static get fallbackPaths() { return [location.href, this.getParentUrl(location.href), location.origin]; }
9
+
10
+ /**
11
+ * Extract the parent URL from an URL.
12
+ * @param url : the URL
13
+ * @returns : the parent URL
14
+ */
15
+ private static getParentUrl(url: string) {
16
+ return url.substring(0, url.lastIndexOf('/') + 1);
17
+ }
7
18
 
8
19
  /**
9
20
  * Convert an audio buffer to audio data.
@@ -46,7 +57,10 @@ class SoundfileReader {
46
57
  private static async checkFileExists(url: string): Promise<boolean> {
47
58
  try {
48
59
  console.log(`"checkFileExists" url: ${url}`);
49
- const response = await fetch(url, { method: "HEAD" });
60
+ // Fetch in "HEAD" mode does not properly work with the service-worker.js cache, so use "GET" mode for now
61
+ //const response = await fetch(url, { method: "HEAD" });
62
+ const response = await fetch(url);
63
+ console.log(`"checkFileExists" response.ok: ${response.ok}`);
50
64
  return response.ok; // Will be true if the status code is 200-299
51
65
  } catch (error) {
52
66
  console.error('Fetch error:', error);
@@ -22,13 +22,23 @@ const copyWebStandaloneAssets = (outputDir, dspName, poly = false) => {
22
22
  cpSyncModify(templateJSPath, outputDir + `/${dspName}.js`, "FAUST_DSP", dspName);
23
23
 
24
24
  const templateHTMLPath = path.join(__dirname, "../assets/standalone/index.html");
25
- cpSyncModify(templateHTMLPath, outputDir + `/${dspName}.html`, "FAUST_DSP", dspName);
25
+ //cpSyncModify(templateHTMLPath, outputDir + `/${dspName}.html`, "FAUST_DSP", dspName);
26
+ cpSyncModify(templateHTMLPath, outputDir + `/index.html`, "FAUST_DSP", dspName);
27
+
28
+ const templateServerJSPath = path.join(__dirname, "../assets/standalone/service-worker.js");
29
+ cpSyncModify(templateServerJSPath, outputDir + `/service-worker.js`, "FAUST_DSP", dspName);
30
+
31
+ const templateIconPath = path.join(__dirname, "../assets/standalone/icon.png");
32
+ cpSync(templateIconPath, outputDir + `/icon.png`);
26
33
 
27
34
  const faustwasmPath = path.join(__dirname, "../assets/standalone/faustwasm");
28
35
  cpSync(faustwasmPath, outputDir + "/faustwasm");
29
36
 
30
37
  const faustuiPath = path.join(__dirname, "../assets/standalone/faust-ui");
31
38
  cpSync(faustuiPath, outputDir + "/faust-ui");
39
+
40
+ const templateManifestPath = path.join(__dirname, "../assets/standalone/manifest.json");
41
+ cpSyncModify(templateManifestPath, outputDir + `/manifest.json`, "FAUST_DSP", dspName);
32
42
  };
33
43
 
34
44
  /**
@@ -1211,6 +1211,12 @@ export declare class WavDecoder {
1211
1211
  /** Read metadata and fetch soundfiles */
1212
1212
  export declare class SoundfileReader {
1213
1213
  static get fallbackPaths(): string[];
1214
+ /**
1215
+ * Extract the parent URL from an URL.
1216
+ * @param url : the URL
1217
+ * @returns : the parent URL
1218
+ */
1219
+ private static getParentUrl;
1214
1220
  /**
1215
1221
  * Convert an audio buffer to audio data.
1216
1222
  *
@@ -3496,8 +3496,17 @@ var WavDecoder_default = WavDecoder;
3496
3496
 
3497
3497
  // src/SoundfileReader.ts
3498
3498
  var SoundfileReader = class {
3499
+ // Set the fallback paths
3499
3500
  static get fallbackPaths() {
3500
- return [location.href, location.origin];
3501
+ return [location.href, this.getParentUrl(location.href), location.origin];
3502
+ }
3503
+ /**
3504
+ * Extract the parent URL from an URL.
3505
+ * @param url : the URL
3506
+ * @returns : the parent URL
3507
+ */
3508
+ static getParentUrl(url) {
3509
+ return url.substring(0, url.lastIndexOf("/") + 1);
3501
3510
  }
3502
3511
  /**
3503
3512
  * Convert an audio buffer to audio data.
@@ -3538,7 +3547,8 @@ var SoundfileReader = class {
3538
3547
  static async checkFileExists(url) {
3539
3548
  try {
3540
3549
  console.log(`"checkFileExists" url: ${url}`);
3541
- const response = await fetch(url, { method: "HEAD" });
3550
+ const response = await fetch(url);
3551
+ console.log(`"checkFileExists" response.ok: ${response.ok}`);
3542
3552
  return response.ok;
3543
3553
  } catch (error) {
3544
3554
  console.error("Fetch error:", error);
@@ -3659,8 +3669,6 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3659
3669
  async listenSensors() {
3660
3670
  if (this.hasAccInput) {
3661
3671
  const isAndroid = /Android/i.test(navigator.userAgent);
3662
- console.log(navigator.userAgent);
3663
- console.log(isAndroid);
3664
3672
  let handleDeviceMotion = null;
3665
3673
  if (isAndroid) {
3666
3674
  handleDeviceMotion = ({ accelerationIncludingGravity }) => {