node-web-audio-api 0.19.0 → 0.21.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/CHANGELOG.md +11 -0
- package/README.md +1 -3
- package/index.cjs +81 -83
- package/index.mjs +12 -1
- package/js/AnalyserNode.js +0 -3
- package/js/AudioBuffer.js +10 -11
- package/js/AudioBufferSourceNode.js +0 -6
- package/js/AudioContext.js +44 -13
- package/js/AudioDestinationNode.js +1 -1
- package/js/AudioListener.js +2 -2
- package/js/AudioParamMap.js +88 -0
- package/js/AudioRenderCapacity.js +117 -0
- package/js/AudioScheduledSourceNode.js +15 -0
- package/js/AudioWorklet.js +261 -0
- package/js/AudioWorkletGlobalScope.js +303 -0
- package/js/AudioWorkletNode.js +290 -0
- package/js/BaseAudioContext.js +51 -13
- package/js/BiquadFilterNode.js +0 -3
- package/js/ChannelMergerNode.js +0 -3
- package/js/ChannelSplitterNode.js +0 -3
- package/js/ConstantSourceNode.js +0 -6
- package/js/ConvolverNode.js +0 -3
- package/js/DelayNode.js +0 -3
- package/js/DynamicsCompressorNode.js +0 -3
- package/js/Events.js +230 -0
- package/js/GainNode.js +0 -3
- package/js/IIRFilterNode.js +0 -3
- package/js/MediaStreamAudioSourceNode.js +0 -3
- package/js/OfflineAudioContext.js +57 -34
- package/js/OscillatorNode.js +0 -6
- package/js/PannerNode.js +0 -3
- package/js/ScriptProcessorNode.js +179 -0
- package/js/StereoPannerNode.js +0 -3
- package/js/WaveShaperNode.js +0 -3
- package/js/lib/events.js +6 -16
- package/js/lib/symbols.js +23 -2
- package/load-native.cjs +87 -0
- package/node-web-audio-api.darwin-arm64.node +0 -0
- package/node-web-audio-api.darwin-x64.node +0 -0
- package/node-web-audio-api.linux-arm-gnueabihf.node +0 -0
- package/node-web-audio-api.linux-arm64-gnu.node +0 -0
- package/node-web-audio-api.linux-x64-gnu.node +0 -0
- package/node-web-audio-api.win32-arm64-msvc.node +0 -0
- package/node-web-audio-api.win32-x64-msvc.node +0 -0
- package/package.json +3 -1
- package/TODOS.md +0 -149
- package/js/monkey-patch.js +0 -77
- package/run-wpt.md +0 -27
- package/simple-test.cjs +0 -20
- package/simple-test.mjs +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## v0.21.0 (17/05/2024)
|
|
2
|
+
|
|
3
|
+
- Feat: implement AudioWorkletNode
|
|
4
|
+
|
|
5
|
+
## v0.20.0 (29/04/2024)
|
|
6
|
+
|
|
7
|
+
- Update upstream crate to [v0.44.0](https://github.com/orottier/web-audio-api-rs/blob/main/CHANGELOG.md#version-0440-2024-04-22)
|
|
8
|
+
- Implement ScriptProcessorNode
|
|
9
|
+
- Fix memory leak introduced in v0.19.0
|
|
10
|
+
- Improve events compliance
|
|
11
|
+
|
|
1
12
|
## v0.19.0 (17/04/2024)
|
|
2
13
|
|
|
3
14
|
- Update upstream crate to [1.0.0-rc.5](https://github.com/orottier/web-audio-api-rs/blob/main/CHANGELOG.md#version-0430--100-rc5-2024-04-15)
|
package/README.md
CHANGED
|
@@ -65,9 +65,7 @@ node examples/granular-scrub.mjs
|
|
|
65
65
|
|
|
66
66
|
## Caveats
|
|
67
67
|
|
|
68
|
-
-
|
|
69
|
-
- Streams: only a minimial audio input stream and the `MediaStreamSourceNode` are provided. All other `MediaStream` features are left on the side for now as they principaly concern a different API specification, which is not a trivial problem.
|
|
70
|
-
- Some async methods (e.g. `decodeAudioData`, `setSinkId`) are not trully async yet. This will evolve with the implemetation of the async version in the upstream crate.
|
|
68
|
+
- `Streams`: only a minimial audio input stream and the `MediaStreamSourceNode` are provided. All other `MediaStream` features are left on the side for now as they principaly concern a different API specification, which is not a trivial problem.
|
|
71
69
|
|
|
72
70
|
## Supported Platforms
|
|
73
71
|
|
package/index.cjs
CHANGED
|
@@ -1,90 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
// -------------------------------------------------------------------------- //
|
|
2
|
+
// -------------------------------------------------------------------------- //
|
|
3
|
+
// //
|
|
4
|
+
// //
|
|
5
|
+
// //
|
|
6
|
+
// ██╗ ██╗ █████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ //
|
|
7
|
+
// ██║ ██║██╔══██╗██╔══██╗████╗ ██║██║████╗ ██║██╔════╝ //
|
|
8
|
+
// ██║ █╗ ██║███████║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗ //
|
|
9
|
+
// ██║███╗██║██╔══██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║ //
|
|
10
|
+
// ╚███╔███╔╝██║ ██║██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝ //
|
|
11
|
+
// ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ //
|
|
12
|
+
// //
|
|
13
|
+
// //
|
|
14
|
+
// - This file has been generated --------------------------- //
|
|
15
|
+
// //
|
|
16
|
+
// //
|
|
17
|
+
// -------------------------------------------------------------------------- //
|
|
18
|
+
// -------------------------------------------------------------------------- //
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
|
|
20
|
+
const nativeBinding = require('./load-native.cjs');
|
|
21
|
+
const jsExport = {};
|
|
5
22
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
nativeBinding = require('./node-web-audio-api.win32-arm64-msvc.node');
|
|
19
|
-
} catch (e) {
|
|
20
|
-
loadError = e;
|
|
21
|
-
}
|
|
22
|
-
break;
|
|
23
|
-
default:
|
|
24
|
-
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
25
|
-
}
|
|
26
|
-
break;
|
|
27
|
-
case 'darwin':
|
|
28
|
-
switch (arch) {
|
|
29
|
-
case 'x64':
|
|
30
|
-
try {
|
|
31
|
-
nativeBinding = require('./node-web-audio-api.darwin-x64.node');
|
|
32
|
-
} catch (e) {
|
|
33
|
-
loadError = e;
|
|
34
|
-
}
|
|
35
|
-
break;
|
|
36
|
-
case 'arm64':
|
|
37
|
-
try {
|
|
38
|
-
nativeBinding = require('./node-web-audio-api.darwin-arm64.node');
|
|
39
|
-
} catch (e) {
|
|
40
|
-
loadError = e;
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
default:
|
|
44
|
-
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
45
|
-
}
|
|
46
|
-
break;
|
|
47
|
-
case 'linux':
|
|
48
|
-
switch (arch) {
|
|
49
|
-
case 'x64':
|
|
50
|
-
try {
|
|
51
|
-
nativeBinding = require('./node-web-audio-api.linux-x64-gnu.node');
|
|
52
|
-
} catch (e) {
|
|
53
|
-
loadError = e;
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
case 'arm64':
|
|
57
|
-
try {
|
|
58
|
-
nativeBinding = require('./node-web-audio-api.linux-arm64-gnu.node');
|
|
59
|
-
} catch (e) {
|
|
60
|
-
loadError = e;
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case 'arm':
|
|
64
|
-
try {
|
|
65
|
-
nativeBinding = require('./node-web-audio-api.linux-arm-gnueabihf.node');
|
|
66
|
-
} catch (e) {
|
|
67
|
-
loadError = e;
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
72
|
-
}
|
|
73
|
-
break;
|
|
74
|
-
default:
|
|
75
|
-
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
76
|
-
}
|
|
23
|
+
// --------------------------------------------------------------------------
|
|
24
|
+
// Events
|
|
25
|
+
// --------------------------------------------------------------------------
|
|
26
|
+
jsExport.OfflineAudioCompletionEvent = require('./js/Events').OfflineAudioCompletionEvent;
|
|
27
|
+
jsExport.AudioProcessingEvent = require('./js/Events').AudioProcessingEvent;
|
|
28
|
+
jsExport.AudioRenderCapacityEvent = require('./js/Events').AudioRenderCapacityEvent;
|
|
29
|
+
// --------------------------------------------------------------------------
|
|
30
|
+
// Create Web Audio API facade
|
|
31
|
+
// --------------------------------------------------------------------------
|
|
32
|
+
jsExport.BaseAudioContext = require('./js/BaseAudioContext.js')(jsExport, nativeBinding);
|
|
33
|
+
jsExport.AudioContext = require('./js/AudioContext.js')(jsExport, nativeBinding);
|
|
34
|
+
jsExport.OfflineAudioContext = require('./js/OfflineAudioContext.js')(jsExport, nativeBinding);
|
|
77
35
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
36
|
+
jsExport.ScriptProcessorNode = require('./js/ScriptProcessorNode.js')(jsExport, nativeBinding);
|
|
37
|
+
jsExport.AudioWorkletNode = require('./js/AudioWorkletNode.js')(jsExport, nativeBinding);
|
|
38
|
+
jsExport.AnalyserNode = require('./js/AnalyserNode.js')(jsExport, nativeBinding);
|
|
39
|
+
jsExport.AudioBufferSourceNode = require('./js/AudioBufferSourceNode.js')(jsExport, nativeBinding);
|
|
40
|
+
jsExport.BiquadFilterNode = require('./js/BiquadFilterNode.js')(jsExport, nativeBinding);
|
|
41
|
+
jsExport.ChannelMergerNode = require('./js/ChannelMergerNode.js')(jsExport, nativeBinding);
|
|
42
|
+
jsExport.ChannelSplitterNode = require('./js/ChannelSplitterNode.js')(jsExport, nativeBinding);
|
|
43
|
+
jsExport.ConstantSourceNode = require('./js/ConstantSourceNode.js')(jsExport, nativeBinding);
|
|
44
|
+
jsExport.ConvolverNode = require('./js/ConvolverNode.js')(jsExport, nativeBinding);
|
|
45
|
+
jsExport.DelayNode = require('./js/DelayNode.js')(jsExport, nativeBinding);
|
|
46
|
+
jsExport.DynamicsCompressorNode = require('./js/DynamicsCompressorNode.js')(jsExport, nativeBinding);
|
|
47
|
+
jsExport.GainNode = require('./js/GainNode.js')(jsExport, nativeBinding);
|
|
48
|
+
jsExport.IIRFilterNode = require('./js/IIRFilterNode.js')(jsExport, nativeBinding);
|
|
49
|
+
jsExport.MediaStreamAudioSourceNode = require('./js/MediaStreamAudioSourceNode.js')(jsExport, nativeBinding);
|
|
50
|
+
jsExport.OscillatorNode = require('./js/OscillatorNode.js')(jsExport, nativeBinding);
|
|
51
|
+
jsExport.PannerNode = require('./js/PannerNode.js')(jsExport, nativeBinding);
|
|
52
|
+
jsExport.StereoPannerNode = require('./js/StereoPannerNode.js')(jsExport, nativeBinding);
|
|
53
|
+
jsExport.WaveShaperNode = require('./js/WaveShaperNode.js')(jsExport, nativeBinding);
|
|
54
|
+
|
|
55
|
+
jsExport.AudioNode = require('./js/AudioNode.js');
|
|
56
|
+
jsExport.AudioScheduledSourceNode = require('./js/AudioScheduledSourceNode.js');
|
|
57
|
+
jsExport.AudioParam = require('./js/AudioParam.js');
|
|
58
|
+
jsExport.AudioDestinationNode = require('./js/AudioDestinationNode.js');
|
|
59
|
+
jsExport.AudioListener = require('./js/AudioListener.js');
|
|
60
|
+
jsExport.AudioWorklet = require('./js/AudioWorklet.js');
|
|
61
|
+
jsExport.AudioParamMap = require('./js/AudioParamMap.js');
|
|
62
|
+
jsExport.AudioRenderCapacity = require('./js/AudioRenderCapacity.js');
|
|
63
|
+
|
|
64
|
+
jsExport.PeriodicWave = require('./js/PeriodicWave.js')(jsExport, nativeBinding);
|
|
65
|
+
jsExport.AudioBuffer = require('./js/AudioBuffer.js')(jsExport, nativeBinding);
|
|
82
66
|
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
// --------------------------------------------------------------------------
|
|
68
|
+
// Promisify MediaDevices API
|
|
69
|
+
// --------------------------------------------------------------------------
|
|
70
|
+
jsExport.mediaDevices = {};
|
|
85
71
|
|
|
86
|
-
const
|
|
87
|
-
|
|
72
|
+
const enumerateDevicesSync = nativeBinding.mediaDevices.enumerateDevices;
|
|
73
|
+
jsExport.mediaDevices.enumerateDevices = async function enumerateDevices() {
|
|
74
|
+
const list = enumerateDevicesSync();
|
|
75
|
+
return Promise.resolve(list);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const getUserMediaSync = nativeBinding.mediaDevices.getUserMedia;
|
|
79
|
+
jsExport.mediaDevices.getUserMedia = async function getUserMedia(options) {
|
|
80
|
+
if (options === undefined) {
|
|
81
|
+
throw new TypeError('Failed to execute "getUserMedia" on "MediaDevices": audio must be requested');
|
|
82
|
+
}
|
|
88
83
|
|
|
89
|
-
|
|
84
|
+
const stream = getUserMediaSync(options);
|
|
85
|
+
return Promise.resolve(stream);
|
|
86
|
+
};
|
|
90
87
|
|
|
88
|
+
module.exports = jsExport;
|
package/index.mjs
CHANGED
|
@@ -27,6 +27,12 @@ const require = createRequire(import.meta.url);
|
|
|
27
27
|
|
|
28
28
|
const nativeModule = require('./index.cjs');
|
|
29
29
|
export const {
|
|
30
|
+
// events
|
|
31
|
+
OfflineAudioCompletionEvent,
|
|
32
|
+
AudioProcessingEvent,
|
|
33
|
+
AudioRenderCapacityEvent,
|
|
34
|
+
|
|
35
|
+
// manually written nodes
|
|
30
36
|
BaseAudioContext,
|
|
31
37
|
AudioContext,
|
|
32
38
|
OfflineAudioContext,
|
|
@@ -36,10 +42,15 @@ export const {
|
|
|
36
42
|
AudioParam,
|
|
37
43
|
AudioDestinationNode,
|
|
38
44
|
AudioListener,
|
|
45
|
+
AudioWorklet,
|
|
46
|
+
AudioParamMap,
|
|
47
|
+
AudioRenderCapacity,
|
|
39
48
|
|
|
40
49
|
PeriodicWave,
|
|
41
50
|
AudioBuffer,
|
|
42
|
-
// generated
|
|
51
|
+
// generated nodes
|
|
52
|
+
ScriptProcessorNode,
|
|
53
|
+
AudioWorkletNode,
|
|
43
54
|
AnalyserNode,
|
|
44
55
|
AudioBufferSourceNode,
|
|
45
56
|
BiquadFilterNode,
|
package/js/AnalyserNode.js
CHANGED
package/js/AudioBuffer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const conversions = require(
|
|
1
|
+
const conversions = require('webidl-conversions');
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
throwSanitizedError,
|
|
@@ -9,7 +9,6 @@ const {
|
|
|
9
9
|
} = require('./lib/utils.js');
|
|
10
10
|
const {
|
|
11
11
|
kNapiObj,
|
|
12
|
-
kAudioBuffer,
|
|
13
12
|
} = require('./lib/symbols.js');
|
|
14
13
|
|
|
15
14
|
|
|
@@ -21,7 +20,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
if (typeof options !== 'object') {
|
|
24
|
-
throw new TypeError(
|
|
23
|
+
throw new TypeError(`Failed to construct 'AudioBuffer': argument 1 is not of type 'AudioBufferOptions'`);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
if (kNapiObj in options) {
|
|
@@ -82,7 +81,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
82
81
|
|
|
83
82
|
get sampleRate() {
|
|
84
83
|
if (!(this instanceof AudioBuffer)) {
|
|
85
|
-
throw new TypeError(
|
|
84
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioBuffer'`);
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
return this[kNapiObj].sampleRate;
|
|
@@ -90,7 +89,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
90
89
|
|
|
91
90
|
get duration() {
|
|
92
91
|
if (!(this instanceof AudioBuffer)) {
|
|
93
|
-
throw new TypeError(
|
|
92
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioBuffer'`);
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
return this[kNapiObj].duration;
|
|
@@ -98,7 +97,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
98
97
|
|
|
99
98
|
get length() {
|
|
100
99
|
if (!(this instanceof AudioBuffer)) {
|
|
101
|
-
throw new TypeError(
|
|
100
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioBuffer'`);
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
return this[kNapiObj].length;
|
|
@@ -106,7 +105,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
106
105
|
|
|
107
106
|
get numberOfChannels() {
|
|
108
107
|
if (!(this instanceof AudioBuffer)) {
|
|
109
|
-
throw new TypeError(
|
|
108
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioBuffer'`);
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
return this[kNapiObj].numberOfChannels;
|
|
@@ -114,7 +113,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
114
113
|
|
|
115
114
|
copyFromChannel(destination, channelNumber, bufferOffset = 0) {
|
|
116
115
|
if (!(this instanceof AudioBuffer)) {
|
|
117
|
-
throw new TypeError(
|
|
116
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioBuffer'`);
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
if (arguments.length < 2) {
|
|
@@ -149,7 +148,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
149
148
|
|
|
150
149
|
copyToChannel(source, channelNumber, bufferOffset = 0) {
|
|
151
150
|
if (!(this instanceof AudioBuffer)) {
|
|
152
|
-
throw new TypeError(
|
|
151
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioBuffer'`);
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
if (arguments.length < 2) {
|
|
@@ -184,7 +183,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
184
183
|
|
|
185
184
|
getChannelData(channel) {
|
|
186
185
|
if (!(this instanceof AudioBuffer)) {
|
|
187
|
-
throw new TypeError(
|
|
186
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioBuffer'`);
|
|
188
187
|
}
|
|
189
188
|
|
|
190
189
|
if (arguments.length < 1) {
|
|
@@ -220,7 +219,7 @@ module.exports = (_jsExport, nativeBinding) => {
|
|
|
220
219
|
},
|
|
221
220
|
});
|
|
222
221
|
|
|
223
|
-
Object.defineProperties(AudioBuffer.prototype,
|
|
222
|
+
Object.defineProperties(AudioBuffer.prototype, {
|
|
224
223
|
[Symbol.toStringTag]: {
|
|
225
224
|
__proto__: null,
|
|
226
225
|
writable: false,
|
|
@@ -33,9 +33,6 @@ const {
|
|
|
33
33
|
kNapiObj,
|
|
34
34
|
kAudioBuffer,
|
|
35
35
|
} = require('./lib/symbols.js');
|
|
36
|
-
const {
|
|
37
|
-
bridgeEventTarget,
|
|
38
|
-
} = require('./lib/events.js');
|
|
39
36
|
/* eslint-enable no-unused-vars */
|
|
40
37
|
|
|
41
38
|
const AudioScheduledSourceNode = require('./AudioScheduledSourceNode.js');
|
|
@@ -142,9 +139,6 @@ module.exports = (jsExport, nativeBinding) => {
|
|
|
142
139
|
this[kAudioBuffer] = options.buffer;
|
|
143
140
|
}
|
|
144
141
|
|
|
145
|
-
// Bridge Rust native event to Node EventTarget
|
|
146
|
-
bridgeEventTarget(this);
|
|
147
|
-
|
|
148
142
|
this.#playbackRate = new jsExport.AudioParam({
|
|
149
143
|
[kNapiObj]: this[kNapiObj].playbackRate,
|
|
150
144
|
});
|
package/js/AudioContext.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
const conversions = require(
|
|
1
|
+
const conversions = require('webidl-conversions');
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
throwSanitizedError,
|
|
5
5
|
} = require('./lib/errors.js');
|
|
6
6
|
const {
|
|
7
7
|
isFunction,
|
|
8
|
-
kEnumerableProperty
|
|
8
|
+
kEnumerableProperty,
|
|
9
9
|
} = require('./lib/utils.js');
|
|
10
10
|
const {
|
|
11
11
|
kNapiObj,
|
|
12
|
+
kOnStateChange,
|
|
13
|
+
kOnSinkChange,
|
|
14
|
+
kWorkletRelease,
|
|
12
15
|
} = require('./lib/symbols.js');
|
|
13
16
|
const {
|
|
14
|
-
|
|
17
|
+
propagateEvent,
|
|
15
18
|
} = require('./lib/events.js');
|
|
16
19
|
|
|
17
20
|
let contextId = 0;
|
|
@@ -20,6 +23,8 @@ module.exports = function(jsExport, nativeBinding) {
|
|
|
20
23
|
|
|
21
24
|
class AudioContext extends jsExport.BaseAudioContext {
|
|
22
25
|
#sinkId = '';
|
|
26
|
+
#renderCapacity = null;
|
|
27
|
+
#onsinkchange = null;
|
|
23
28
|
|
|
24
29
|
constructor(options = {}) {
|
|
25
30
|
if (typeof options !== 'object') {
|
|
@@ -49,18 +54,16 @@ module.exports = function(jsExport, nativeBinding) {
|
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
if (options.sinkId !== undefined) {
|
|
52
|
-
const sinkId = options.sinkId;
|
|
53
|
-
|
|
54
57
|
if (typeof options.sinkId === 'object') {
|
|
55
58
|
// https://webaudio.github.io/web-audio-api/#enumdef-audiosinktype
|
|
56
59
|
if (!('type' in options.sinkId) || options.sinkId.type !== 'none') {
|
|
57
|
-
throw TypeError(`Failed to construct 'AudioContext': Failed to read the 'sinkId' property from AudioNodeOptions: Failed to read the 'type' property from 'AudioSinkOptions': The provided value (${sinkId.type}) is not a valid enum value of type AudioSinkType.`);
|
|
60
|
+
throw TypeError(`Failed to construct 'AudioContext': Failed to read the 'sinkId' property from AudioNodeOptions: Failed to read the 'type' property from 'AudioSinkOptions': The provided value (${options.sinkId.type}) is not a valid enum value of type AudioSinkType.`);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
targetOptions.sinkId = 'none';
|
|
61
64
|
} else {
|
|
62
|
-
targetOptions.sinkId = conversions['DOMString'](sinkId, {
|
|
63
|
-
context: `Failed to construct 'AudioContext': Failed to read the 'sinkId' property from AudioNodeOptions: Failed to read the 'type' property from 'AudioSinkOptions': The provided value (${sinkId})`,
|
|
65
|
+
targetOptions.sinkId = conversions['DOMString'](options.sinkId, {
|
|
66
|
+
context: `Failed to construct 'AudioContext': Failed to read the 'sinkId' property from AudioNodeOptions: Failed to read the 'type' property from 'AudioSinkOptions': The provided value (${options.sinkId})`,
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
} else {
|
|
@@ -81,8 +84,33 @@ module.exports = function(jsExport, nativeBinding) {
|
|
|
81
84
|
this.#sinkId = options.sinkId;
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
this.#renderCapacity = new jsExport.AudioRenderCapacity({
|
|
88
|
+
[kNapiObj]: this[kNapiObj].renderCapacity,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Add function to Napi object to bridge from Rust events to JS EventTarget
|
|
92
|
+
this[kNapiObj][kOnStateChange] = (err, rawEvent) => {
|
|
93
|
+
if (typeof rawEvent !== 'object' && !('type' in rawEvent)) {
|
|
94
|
+
throw new TypeError('Invalid [kOnStateChange] Invocation: rawEvent should have a type property');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const event = new Event(rawEvent.type);
|
|
98
|
+
propagateEvent(this, event);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
this[kNapiObj][kOnSinkChange] = (err, rawEvent) => {
|
|
102
|
+
if (typeof rawEvent !== 'object' && !('type' in rawEvent)) {
|
|
103
|
+
throw new TypeError('Invalid [kOnSinkChange] Invocation: rawEvent should have a type property');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const event = new Event(rawEvent.type);
|
|
107
|
+
propagateEvent(this, event);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Workaround to bind the `sinkchange` and `statechange` events to EventTarget.
|
|
111
|
+
// This must be called from JS facade ctor as the JS handler are added to the Napi
|
|
112
|
+
// object after its instantiation, and that we don't have any initial `resume` call.
|
|
113
|
+
this[kNapiObj].listen_to_events();
|
|
86
114
|
|
|
87
115
|
// @todo - check if this is still required
|
|
88
116
|
// prevent garbage collection and process exit
|
|
@@ -137,7 +165,7 @@ module.exports = function(jsExport, nativeBinding) {
|
|
|
137
165
|
throw new TypeError('Invalid Invocation: Value of \'this\' must be of type \'AudioContext\'');
|
|
138
166
|
}
|
|
139
167
|
|
|
140
|
-
|
|
168
|
+
return this.#renderCapacity;
|
|
141
169
|
}
|
|
142
170
|
|
|
143
171
|
get onsinkchange() {
|
|
@@ -145,7 +173,7 @@ module.exports = function(jsExport, nativeBinding) {
|
|
|
145
173
|
throw new TypeError('Invalid Invocation: Value of \'this\' must be of type \'AudioContext\'');
|
|
146
174
|
}
|
|
147
175
|
|
|
148
|
-
return this
|
|
176
|
+
return this.#onsinkchange;
|
|
149
177
|
}
|
|
150
178
|
|
|
151
179
|
set onsinkchange(value) {
|
|
@@ -154,7 +182,7 @@ module.exports = function(jsExport, nativeBinding) {
|
|
|
154
182
|
}
|
|
155
183
|
|
|
156
184
|
if (isFunction(value) || value === null) {
|
|
157
|
-
this
|
|
185
|
+
this.#onsinkchange = value;
|
|
158
186
|
}
|
|
159
187
|
}
|
|
160
188
|
|
|
@@ -187,6 +215,9 @@ module.exports = function(jsExport, nativeBinding) {
|
|
|
187
215
|
throw new TypeError('Invalid Invocation: Value of \'this\' must be of type \'AudioContext\'');
|
|
188
216
|
}
|
|
189
217
|
|
|
218
|
+
// Close audioWorklet first so that `run_audio_worklet_global_scope` exit first
|
|
219
|
+
// The other way around works too because of `recv_timeout` but cleaner this way
|
|
220
|
+
await this.audioWorklet[kWorkletRelease]();
|
|
190
221
|
await this[kNapiObj].close();
|
|
191
222
|
}
|
|
192
223
|
|
|
@@ -20,7 +20,7 @@ class AudioDestinationNode extends AudioNode {
|
|
|
20
20
|
|
|
21
21
|
get maxChannelCount() {
|
|
22
22
|
if (!(this instanceof AudioDestinationNode)) {
|
|
23
|
-
throw new TypeError(
|
|
23
|
+
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioDestinationNode'`);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return this[kNapiObj].maxChannelCount;
|
package/js/AudioListener.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const conversions = require(
|
|
1
|
+
const conversions = require('webidl-conversions');
|
|
2
2
|
|
|
3
3
|
const { throwSanitizedError } = require('./lib/errors.js');
|
|
4
4
|
const { kEnumerableProperty, kHiddenProperty } = require('./lib/utils.js');
|
|
@@ -160,7 +160,7 @@ class AudioListener {
|
|
|
160
160
|
context: `Failed to execute 'setOrientation' on 'AudioListener': The provided float value`,
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
z = conversions['float'](z, {
|
|
164
164
|
context: `Failed to execute 'setOrientation' on 'AudioListener': The provided float value`,
|
|
165
165
|
});
|
|
166
166
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const {
|
|
2
|
+
kPrivateConstructor,
|
|
3
|
+
} = require('./lib/symbols.js');
|
|
4
|
+
const {
|
|
5
|
+
kEnumerableProperty,
|
|
6
|
+
} = require('./lib/utils.js');
|
|
7
|
+
|
|
8
|
+
class AudioParamMap {
|
|
9
|
+
#parameters = null;
|
|
10
|
+
|
|
11
|
+
constructor(options) {
|
|
12
|
+
if (
|
|
13
|
+
(typeof options !== 'object') ||
|
|
14
|
+
options[kPrivateConstructor] !== true
|
|
15
|
+
) {
|
|
16
|
+
throw new TypeError('Illegal constructor');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.#parameters = options.parameters;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get size() {
|
|
23
|
+
return this.#parameters.size;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
entries() {
|
|
27
|
+
return this.#parameters.entries();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
keys() {
|
|
31
|
+
return this.#parameters.keys();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
values() {
|
|
35
|
+
return this.#parameters.values();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
forEach(func) {
|
|
39
|
+
return this.#parameters.forEach(func);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get(name) {
|
|
43
|
+
return this.#parameters.get(name);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
has(name) {
|
|
47
|
+
return this.#parameters.has(name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Object.defineProperties(AudioParamMap, {
|
|
52
|
+
length: {
|
|
53
|
+
__proto__: null,
|
|
54
|
+
writable: false,
|
|
55
|
+
enumerable: false,
|
|
56
|
+
configurable: true,
|
|
57
|
+
value: 0,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
Object.defineProperties(AudioParamMap.prototype, {
|
|
62
|
+
[Symbol.toStringTag]: {
|
|
63
|
+
__proto__: null,
|
|
64
|
+
writable: false,
|
|
65
|
+
enumerable: false,
|
|
66
|
+
configurable: true,
|
|
67
|
+
value: 'AudioParamMap',
|
|
68
|
+
},
|
|
69
|
+
[Symbol.iterator]: {
|
|
70
|
+
value: AudioParamMap.prototype.entries,
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
},
|
|
75
|
+
size: {
|
|
76
|
+
__proto__: null,
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
},
|
|
80
|
+
entries: kEnumerableProperty,
|
|
81
|
+
keys: kEnumerableProperty,
|
|
82
|
+
values: kEnumerableProperty,
|
|
83
|
+
forEach: kEnumerableProperty,
|
|
84
|
+
get: kEnumerableProperty,
|
|
85
|
+
has: kEnumerableProperty,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
module.exports = AudioParamMap;
|