streamana/site/dummy-worklet.js
2021-07-08 20:55:27 +01:00

23 lines
611 B
JavaScript

import { UpdateLimiter } from './update-limiter.js';
class DummyProcessor extends AudioWorkletProcessor {
constructor(options) {
super(options);
this.stopped = false;
this.port.onmessage = () => this.stopped = true;
this.update_limiter = new UpdateLimiter(options.processorOptions.update_rate);
}
process() {
if (this.stopped) {
return false;
}
if (this.update_limiter.check()) {
this.port.postMessage({ type: 'update' });
}
return true;
}
}
registerProcessor('dummy-processor', DummyProcessor);