在wasm-bindgen中扩展Web系统结构吗? 特别是Rust中的AudioWorkletProcessor

问题描述

关于如何使用wasm-bindgen在rust -> wasm流中使用现有javascript网络系统的文档非常简单。简而言之:

  1. 列出所需的功能作为依赖项
// cargo.toml

...omitted...

[dependencies.web-sys]
version = "0.3.4"
features = [
  'AudioContext','OscillatorNode'
]
  1. 通过web_sys进行访问,然后从那里将它们视为正常对象。
// lib.rs

...omitted...

#[wasm_bindgen]
impl FmOsc {
    #[wasm_bindgen(constructor)]
    pub fn new() -> Result<FmOsc,JsValue> {
        let ctx = web_sys::AudioContext::new()?;
        let primary = ctx.create_oscillator()?;
        let fm_osc = ctx.create_oscillator()?;
    
...omitted...

链接到完整示例:https://rustwasm.github.io/docs/wasm-bindgen/examples/web-audio.html


尽管这种方法适用于大多数Web系统,但对于那些需要扩展类的系统而言,并不是那么简单。在这种情况下,我尝试使用AudioWorkletProccessor from wasm-bindgen

在标准用法中,应该扩展AudioWorkletProcessor类,然后注册它。 Mdn示例:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet#Basic_code_framework


我该如何解决这个问题?首先,我需要在Rust中扩展AudioWorkletProcessor(不执行常规类和继承),以覆盖其process()函数。然后,我需要确保将registerProcessor()注入了我的锈蚀空间。


编辑:https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-js-imports/extends.html

解决方法

您将必须在JavaScript方面执行此操作。 wasm-bindgen不支持扩展导入的类并将其重新导出到JavaScript;但是,他们确实希望最终支持它,并且有issue可以跟踪它,还有一个相关的RFC

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...