You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
[Web] Fix Webkit leak caused by the position reporting audio worklets
Co-authored-by: PizzaLovers007 <trex@parkvue.com>
This commit is contained in:
@@ -28,40 +28,31 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
const POST_THRESHOLD_S = 0.1;
|
||||
|
||||
class GodotPositionReportingProcessor extends AudioWorkletProcessor {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.lastPostTime = currentTime;
|
||||
this.position = 0;
|
||||
this.ended = false;
|
||||
|
||||
this.port.onmessage = (event) => {
|
||||
if (event?.data?.type === 'ended') {
|
||||
this.ended = true;
|
||||
switch (event?.data?.type) {
|
||||
case 'reset':
|
||||
this.position = 0;
|
||||
break;
|
||||
default:
|
||||
// Do nothing.
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
process(inputs, _outputs, _parameters) {
|
||||
if (this.ended) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inputs.length > 0) {
|
||||
const input = inputs[0];
|
||||
if (input.length > 0) {
|
||||
this.position += input[0].length;
|
||||
this.port.postMessage({ type: 'position', data: this.position });
|
||||
}
|
||||
}
|
||||
|
||||
// Posting messages is expensive. Let's limit the number of posts.
|
||||
if (currentTime - this.lastPostTime > POST_THRESHOLD_S) {
|
||||
this.lastPostTime = currentTime;
|
||||
this.port.postMessage({ type: 'position', data: this.position });
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user