Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaStreamTrack.getCapabilities() return a Map where some values are NativeJavaScriptObject #44319

Closed
wer-mathurin opened this issue Nov 25, 2020 · 7 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. library-html web-libraries Issues impacting dart:html, etc., libraries

Comments

@wer-mathurin
Copy link

This tracker is for issues related to:

  • dart2js

If you aren't sure, file the issue here and we'll find the right home for it.
In your issue, please include:

  • Dart SDK Version (dart --version)
    Dart SDK version: 2.11.0-242.0.dev (dev) (Wed Oct 21 00:38:45 2020 -0700) on "windows_x64"

When calling

final mediaConstraints = <String, dynamic>{
    'audio': true,
    'video': {
      'mandatory': {
        'minWidth': '1280',
        'minHeight': '720',
        'minFrameRate': '30',
      },
    }
  };
var stream = await navigator.getUserMedia(mediaConstraints);
var _capabilities = stream.getVideoTracks()[0].getCapabilities();

If you inspect the map, you will have for example a NativeJavaScriptObject
_capabilities['aspectRatio']
_capabilities['width']
_capabilities['frameRate']
etc...

Seems to me a problem converting javascript type to dart equivalent.(double and int)

I just want to mention: @srujzs
Since the last commit was involving a similar problem, but in the opposite direction :-)

The method that is doing the conversion is:
convertNativeToDart_Dictionary

@srujzs srujzs added area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. library-html web-libraries Issues impacting dart:html, etc., libraries labels Nov 25, 2020
@srujzs
Copy link
Contributor

srujzs commented Nov 25, 2020

Yup, it seems identical to #43802, with the problem being we don't handle nested dictionaries. The fix here will likely involve converting recursively for the same group of accepted types.

@srujzs srujzs self-assigned this Nov 25, 2020
@wer-mathurin
Copy link
Author

@srujzs: according to the specification:

aspectRatio is a double specifying the video aspect ratio or range of aspect ratios which are acceptable and/or required.

Not a tree of objects!

Same for other properties describe in the bug description.

@Hexer10
Copy link

Hexer10 commented May 4, 2021

Is there are update about solving this issue? I'm trying to port this code to Dart but I couldn't succeed:

(javascript)

const userMedia = await navigator.mediaDevices.getUserMedia({video: true, audio: true});

const videoTrack = userMedia.getVideoTracks()[0];
const capabilities = videoTrack.getCapabilities();
const aspectRatio = capabilities.aspectRatio;

console.log(aspectRatio.max);

(dart)

  final userMedia = await window.navigator.mediaDevices!
      .getUserMedia({'video': true, 'audio': false});
  
  final videoTrack = userMedia.getVideoTracks().first;
  final capabilities = videoTrack.getCapabilities();
  final aspectRatio = capabilities['aspectRatio'];
  
  print(aspectRatio['max']); // Here this is thrown:
  /*
  Uncaught (in promise) Error: NoSuchMethodError: '[]'
  Dynamic call of null.
  Receiver: Instance of 'NativeJavaScriptObject'
  */

Any suggested solutions/workarounds?

Check here for the full error stacktrace: https://stackoverflow.com/questions/67375720/call-to-videotrack-getcapabilities-returns-an-instance-of-nativejavascriptobje

@srujzs
Copy link
Contributor

srujzs commented May 6, 2021

Hi,

Sorry for a lack of update on solving this issue. You can workaround this using js_util to work with the underlying JS object for now:

print(js_util.getProperty(aspectRatio, 'max'));

aspectRatio here is an object literal that hasn't been converted to a Dart type, which is why you're seeing the above.

@nshahan nshahan assigned srujzs and GabrielMCastro and unassigned srujzs May 19, 2021
@GabrielMCastro
Copy link

@srujzs would you recommend updating convertNativeToDart_Dictionary to handle nested values or adding separate method to handle it?

@srujzs
Copy link
Contributor

srujzs commented May 21, 2021

I'd say update it. We had the same convo around convertDartToNative_Dictionary and I'm not sure what value there is in having separate methods. These conversions are for dart:html too, so I don't think the web APIs would benefit from both methods. Plus, if we do see that we want that option later, we can just add an optional arg to the method.

@srujzs
Copy link
Contributor

srujzs commented May 21, 2021

One thing to maybe add a check for is recursive lists or maps. convertDartToNative_Dictionary is missing this check as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. library-html web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

4 participants