rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.63k stars 1.05k forks source link

Incorrect signature for MediaDevices.get_user_media() #1887

Open astepanov256 opened 4 years ago

astepanov256 commented 4 years ago

Describe the Bug

As per MDN (https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia), MediaDevices.getUserMedia call requires one parameter (a map of device constraints). Attempt to call the method w/o the constraint map results in exception.

Current web-sys implementation does not allow for passing in the constraint map. Any attempt to access media device(s) from Rust returns Err(TypeError)

Steps to Reproduce

Sample code:

let cameras: MediaDevices = navigator.media_devices().expect("No available Media Devices found");
  let promise: js_sys::Promise = cameras.get_user_media().unwrap();
  let user_media = JsFuture::from(promise).await.expect("Unable to access user media");

Results in panic: panicked at 'Unable to access user media: JsValue(TypeError: audio and/or video is required )', src/libcore/result.rs:1165:5

Expected Behavior

get_user_media(...) definition should declare a JsValue parameter for the constraint map, and the generated shim should pass that value to the JS call

Additional Context

I am running the latest stable web-sys (at the moment, 0.3.32) and latest wasm-bindgen (0.2.55)

alexcrichton commented 4 years ago

Thanks for the report! Looks like this is a bug in the source WebIDL file which lists the type as optional.

This would unfortunately be a breaking change to land though, so I'm going to tag it as such.