node-web-audio-api 0.21.1 → 0.21.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # CHANGELOG
2
+
3
+ ## v0.21.3 (06/10/2024)
4
+
5
+ - Fix typescript export
6
+
7
+ ## v0.21.2 (20/09/2024)
8
+
9
+ - Update upstream crate to [v1.0.1](https://github.com/orottier/web-audio-api-rs/blob/main/CHANGELOG.md#version-101-2024-09-18)
10
+ - Fix: Make sure `AudioBuffer` returned by `OfflineContext` is valid
11
+ - Fix: Allow contexts to be properly garbage collected
12
+
1
13
  ## v0.21.1 (10/06/2024)
2
14
 
3
15
  - Feat: Buffer pool for AudioWorketProcessor
@@ -92,7 +104,7 @@
92
104
  ## v0.5.0 (19/12/2022)
93
105
 
94
106
  - Implement AudioParam#setValueCurveAtTime
95
- - Offline context constructor
107
+ - Offline context constructor
96
108
 
97
109
  ## v0.4.0 (07/11/2022)
98
110
 
package/all-checks.sh ADDED
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+
3
+
4
+ echo "-----------------------------------------------"
5
+ echo "> cargo fmt -- --check --color always"
6
+ echo "-----------------------------------------------"
7
+ cargo fmt -- --check --color always
8
+
9
+ echo "-----------------------------------------------"
10
+ echo "> cargo clippy --all-targets --features cpal -- -D warnings"
11
+ echo "-----------------------------------------------"
12
+ cargo clippy --all-targets --features cpal -- -D warnings
13
+
14
+ echo "-----------------------------------------------"
15
+ echo "> Run js tests"
16
+ echo "-----------------------------------------------"
17
+ npm run test
18
+
@@ -104,7 +104,7 @@ module.exports = function(jsExport, nativeBinding) {
104
104
  // object after its instantiation, and that we don't have any initial `resume` call.
105
105
  this[kNapiObj].listen_to_events();
106
106
 
107
- // @todo - check if this is still required
107
+ // @todo - This is probably not requested anymore as the event listeners
108
108
  // prevent garbage collection and process exit
109
109
  const id = contextId++;
110
110
  // store in process to prevent garbage collection
@@ -64,7 +64,7 @@ const resolveModule = async (moduleUrl) => {
64
64
  // get caller site from error stack trace
65
65
  const callerSite = caller(2);
66
66
 
67
- if (callerSite.startsWith('http')) {
67
+ if (callerSite.startsWith('http')) { // this branch exists for wpt where caller site is an url
68
68
  let url;
69
69
  // handle origin relative and caller path relative URLs
70
70
  if (moduleUrl.startsWith('/')) {
@@ -82,24 +82,25 @@ module.exports = function patchOfflineAudioContext(jsExport, nativeBinding) {
82
82
 
83
83
  // Add function to Napi object to bridge from Rust events to JS EventTarget
84
84
  // They will be effectively registered on rust side when `startRendering` is called
85
- this[kNapiObj][kOnStateChange] = (function(err, rawEvent) {
85
+ this[kNapiObj][kOnStateChange] = (function(_err, rawEvent) {
86
86
  const event = new Event(rawEvent.type);
87
87
  propagateEvent(this, event);
88
88
  }).bind(this);
89
89
 
90
90
  // This event is, per spec, the last trigerred one
91
91
  this[kNapiObj][kOnComplete] = (function(err, rawEvent) {
92
- // workaround the fact that this event seems to be triggered before
92
+ // workaround the fact that the oncomplete event is triggered before
93
93
  // startRendering fulfills and that we want to return the exact same instance
94
- if (this.#renderedBuffer === null) {
95
- this.#renderedBuffer = new jsExport.AudioBuffer({ [kNapiObj]: rawEvent.renderedBuffer });
96
- }
94
+ this.#renderedBuffer = new jsExport.AudioBuffer({ [kNapiObj]: rawEvent.renderedBuffer });
97
95
 
98
96
  const event = new jsExport.OfflineAudioCompletionEvent(rawEvent.type, {
99
97
  renderedBuffer: this.#renderedBuffer,
100
98
  });
101
99
 
102
- propagateEvent(this, event);
100
+ // delay event propagation to next tick that it is executed after startRendering fulfills
101
+ setImmediate(() => {
102
+ propagateEvent(this, event);
103
+ }, 0);
103
104
  }).bind(this);
104
105
  }
105
106
 
@@ -145,15 +146,9 @@ module.exports = function patchOfflineAudioContext(jsExport, nativeBinding) {
145
146
  throwSanitizedError(err);
146
147
  }
147
148
 
148
- // release audio worklet, if any
149
+ // release audio worklets
149
150
  await this.audioWorklet[kWorkletRelease]();
150
151
 
151
- // workaround the fact that this event seems to be triggered before
152
- // startRendering fulfills and that we want to return the exact same instance
153
- if (this.#renderedBuffer === null) {
154
- this.#renderedBuffer = new jsExport.AudioBuffer({ [kNapiObj]: nativeAudioBuffer });
155
- }
156
-
157
152
  return this.#renderedBuffer;
158
153
  }
159
154
 
Binary file
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "node-web-audio-api",
3
- "version": "0.21.1",
3
+ "version": "0.21.3",
4
4
  "author": "Benjamin Matuszewski",
5
5
  "description": "Node.js bindings for web-audio-api-rs using napi-rs",
6
6
  "exports": {
7
7
  "import": "./index.mjs",
8
- "require": "./index.cjs"
8
+ "require": "./index.cjs",
9
+ "types": "./index.d.ts"
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
@@ -44,7 +45,8 @@
44
45
  "lint": "npx eslint index.cjs index.mjs && npx eslint js/*.js && npx eslint examples/*.mjs",
45
46
  "preversion": "yarn install && npm run generate",
46
47
  "postversion": "cargo bump $npm_package_version && git commit -am \"v$npm_package_version\" && node .scripts/check-changelog.mjs",
47
- "test": "mocha tests",
48
+ "test": "mocha tests/*.spec.mjs",
49
+ "test:only": "mocha",
48
50
  "wpt": "npm run build && node ./.scripts/wpt-harness.mjs",
49
51
  "wpt:only": "node ./.scripts/wpt-harness.mjs"
50
52
  },