port
2024年02月06日
一、认识
二、语法
xxxProcessor.js
class XxxProcessor extends AudioWorkletProcessor {
constructor(...args) {
super(...args);
this.port.onmessage = (e) => {
console.log(e.data);
this.port.postMessage("pong");
};
}
process(inputs, outputs, parameters) {
return true;
}
}
registerProcessor("xxx-processor", XxxProcessor);
const audioContext = new AudioContext();
await audioContext.audioWorklet.addModule('xxxProcessor.js');
const audioWorkletNode = new AudioWorkletNode(audioContext, 'xxx-processor', options);
audioContext.context(audioWorkletNode).context(audioContext.destination);
audioWorkletNode.port.onmessage = (e) => console.log(e.data);