Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Web Audio API isn't supported in nodejs?

I understand Web Audio API is a client side feature but nodejs is based on V8 Chrome client side implementation of ECMAScript, which include Web Audio API.
Why there is no complete support of Web Audio API in nodejs ?
Is it because AudioContext is based on the global window object ?
Am I missing a point here ?
Is there a plan to make it available in the future ?

like image 203
TGrif Avatar asked Nov 15 '15 21:11

TGrif


People also ask

What different API functions does node js support?

You can find two types of API functions in Node. js, namely Synchronous, blocking functions, and Asynchronous, non-blocking functions.

What is AudioContext?

The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode . An audio context controls both the creation of the nodes it contains and the execution of the audio processing, or decoding.


2 Answers

Node.js doesn't support Web Audio because it isn't part of the JavaScript language itself - it's a separate web platform JavaScript API.

You can think of it like Web Workers, requestAnimationFrame or XMLHttpRequest - they are part of the browser's JavaScript environment, but they don't necessarily make sense for other runtimes.

V8 is a generic JavaScript engine; it doesn't include web platform features. That's one of the reasons that Node.js is able to use it. Chrome's implementation of Web Audio is part of Blink, the rendering engine.

The web-audio-api npm module aims to implement Web Audio for Node.js.

like image 110
joews Avatar answered Sep 21 '22 17:09

joews


The reason why the Web Audio API (WAA) is not implemented in NodeJS is fundamentally a design decision. And the fact that AudioContext is part of window has nothing to do with it. For example, console is part of window interface but is in "node-core".

The fact that the WAA is not part of ECMAScript specs is also not sufficient to explain why WAA is not in node-core. For example HTTP2, web crypto API, setInterval(),... are not in ECMAScript spec but are in node-core.

There is no clear cut between what should be in node-core, and what should be in userland (meaning not be in node-core). But in general, NodeJS prefers to keep its standard lib small, expirements new API in userland. You can read this article which talks about that in more depth (see).

Should we see WAA in node-core in near future? Probably not (see issue #64546), but it doesn't mean that 's impossible.

I should add that portability in Audio programming is not an easy task, and this certainly explain in part why NodeJS maintainers are not eager to implement WAA in core.

like image 39
Jerboas86 Avatar answered Sep 19 '22 17:09

Jerboas86