Skip to content

Commit

Permalink
web: Fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie authored and torokati44 committed Aug 20, 2024
1 parent 0ac25b5 commit d824a02
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 5 additions & 3 deletions web/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing_subscriber::layer::Layered;
use tracing_subscriber::Registry;
use tracing_wasm::WASMLayer;
use wasm_bindgen::prelude::*;
use web_sys::AudioContext;
use web_sys::{AudioContext, AudioScheduledSourceNode};

#[allow(dead_code)]
pub struct WebAudioBackend {
Expand Down Expand Up @@ -230,7 +230,8 @@ impl Buffer {
audio_node
.connect_with_audio_node(&self.context.destination())
.into_js_result()?;
audio_node.set_onended(Some(self.on_ended_handler.as_ref().unchecked_ref()));
let scheduled: &AudioScheduledSourceNode = &audio_node;
scheduled.set_onended(Some(self.on_ended_handler.as_ref().unchecked_ref()));

// Sanity: ensure our player time is not in the past. This can happen due to underruns.
self.time
Expand All @@ -250,7 +251,8 @@ impl Buffer {
impl Drop for Buffer {
fn drop(&mut self) {
if let Some(audio_node) = self.audio_node.take() {
audio_node.set_onended(None);
let scheduled: &AudioScheduledSourceNode = &audio_node;
scheduled.set_onended(None);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ impl<E: FromWasmAbi + 'static> JsCallback<E> {
let target = target.as_ref();
let closure = Closure::new(closure);

let options = AddEventListenerOptions::new();
options.set_passive(false);
options.set_capture(is_capture);
target
.add_event_listener_with_callback_and_add_event_listener_options(
name,
closure.as_ref().unchecked_ref(),
AddEventListenerOptions::new()
.passive(false)
.capture(is_capture),
&options,
)
.warn_on_error();

Expand Down
12 changes: 7 additions & 5 deletions web/src/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,17 @@ impl NavigatorBackend for WebNavigatorBackend {
};

Box::pin(async move {
let mut init = RequestInit::new();
let init = RequestInit::new();

init.method(&request.method().to_string());
init.credentials(credentials);
init.set_method(&request.method().to_string());
init.set_credentials(credentials);

if let Some((data, mime)) = request.body() {
let options = BlobPropertyBag::new();
options.set_type(mime);
let blob = Blob::new_with_buffer_source_sequence_and_options(
&Array::from_iter([Uint8Array::from(data.as_slice()).buffer()]),
BlobPropertyBag::new().type_(mime),
&options,
)
.map_err(|_| ErrorResponse {
url: url.to_string(),
Expand All @@ -289,7 +291,7 @@ impl NavigatorBackend for WebNavigatorBackend {
error: Error::FetchError("Got JS error".to_string()),
})?;

init.body(Some(&blob));
init.set_body(&blob);
}

let web_request = match WebRequest::new_with_str_and_init(url.as_str(), &init) {
Expand Down

0 comments on commit d824a02

Please sign in to comment.