pub trait AudioWorkletGlobalScopeExt {
// Required method
fn register_processor_ext<P>(&self, name: &str) -> Result<(), Error>
where P: 'static + ExtendAudioWorkletProcessor;
}
Available on
Web
and crate feature audio-worklet
only.Expand description
Extension for AudioWorkletGlobalScope
.
Required Methods§
sourcefn register_processor_ext<P>(&self, name: &str) -> Result<(), Error>where
P: 'static + ExtendAudioWorkletProcessor,
fn register_processor_ext<P>(&self, name: &str) -> Result<(), Error>where
P: 'static + ExtendAudioWorkletProcessor,
Creates a class that extends AudioWorkletProcessor
and calls
AudioWorkletGlobalScope.registerProcessor()
. This is a workaround
for wasm-bindgen
currently unable to extend classes, see
this wasm-bindgen
issue.
§Notes
AudioWorkletGlobalScope.registerProcessor()
does not sync with it’s
corresponding AudioWorkletNode
immediately and requires at least one
yield to the event loop cycle in the AudioWorkletNode
s thread for
AudioWorkletNode::new()
to successfully find the requested
AudioWorkletProcessor
by its name. See yield_now_async()
.
§Errors
- If the
name
is empty. - If a processor with this
name
is already registered. - If this thread was not spawned by
web-thread
.
§Example
use web_sys::{AudioContext, AudioWorkletGlobalScope, AudioWorkletNode};
use web_thread::web::{self, YieldTime};
use web_thread::web::audio_worklet::{AudioWorkletGlobalScopeExt, BaseAudioContextExt};
let context = AudioContext::new().unwrap();
let (sender, receiver) = async_channel::bounded(1);
context.clone().register_thread(
None,
move || {
let global: AudioWorkletGlobalScope = js_sys::global().unchecked_into();
global
.register_processor_ext::<TestProcessor>("test")
.unwrap();
sender.try_send(()).unwrap();
},
).await.unwrap();
// Wait until processor is registered.
receiver.recv().await.unwrap();
web::yield_now_async(YieldTime::UserBlocking).await;
let node = AudioWorkletNode::new(&context, "test").unwrap();
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl AudioWorkletGlobalScopeExt for AudioWorkletGlobalScope
impl AudioWorkletGlobalScopeExt for AudioWorkletGlobalScope
source§fn register_processor_ext<P>(&self, name: &str) -> Result<(), Error>where
P: 'static + ExtendAudioWorkletProcessor,
fn register_processor_ext<P>(&self, name: &str) -> Result<(), Error>where
P: 'static + ExtendAudioWorkletProcessor,
Available on crate feature
audio-worklet
only.