Skip to content

Bugfix/use media capabilities #51

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

Conversation

anton-karlovskiy
Copy link
Contributor

@wingleung cc @addyosmani

I've created this PR to highlight potential updates on naming and docs in media capabilities hook.

supported,
hasMediaConfig: !!mediaConfig
hasMediaDecodingConfig: !!mediaDecodingConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this? This seems like it should just be an internal variable.

Copy link
Contributor Author

@anton-karlovskiy anton-karlovskiy Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

I agree with @stramel.
I guess try/catch block should wrap navigator.mediaCapabilities.decodingInfo(mediaDecodingConfig) for handling exceptions without hasMediaDecodingConfig.

A TypeError is raised if the MediaConfiguration passed to the decodingInfo() method is invalid, either because the type is not video or audio, the contentType is not a valid codec MIMME type, the media decoding configuration is not a valid value for the media decoding type, or any other error in the media configuration passed to the method, including omitting values required in the media decoding configuration.

From MediaCapabilities.decodingInfo()

mediaCapabilities = (mediaCapabilities.supported && mediaCapabilities.hasMediaConfig)
? navigator.mediaCapabilities.decodingInfo(mediaConfig)
mediaCapabilitiesInfo = (mediaCapabilitiesInfo.supported && mediaCapabilitiesInfo.hasMediaDecodingConfig)
? navigator.mediaCapabilities.decodingInfo(mediaDecodingConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't take into account the fact this returns a promise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about using an API like,

const { supported, decodingInfo, encodingInfo } = useMediaCapabilities(initialState)

either that or we need to wrap the async calls and expose them to show the state of the calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

What are your thoughts?
I agree with @stramel's API suggestion. I think it looks more descriptive rather than just mediaCapabilitiesInfo.
For now, I think it could be like so.

const { supported, smooth, powerEfficient } = useMediaCapabilities(initialState);

};

return {mediaCapabilities};
return {mediaCapabilitiesInfo};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be {...mediaCapabilitiesInfo}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

I agree with @stramel.

@@ -160,16 +160,16 @@ const { deviceMemory } = useMemoryStatus(initialMemoryStatus);

### Media Capabilities

`useMediaCapabilities` utility for adapting based on the user's device media capabilities.
`useMediaCapabilitiesDecodingInfo` utility for adapting based on the user's device media capabilities.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

Looking into the implementation of this hook, I found that it just deals with decoding media capabilities, not all media capabilities (encoding and decoding). So I'd like to suggest updating its name to useMediaCapabilitiesDecodingInfo.
I've got inspired by this MediaCapabilities.decodingInfo().


const webmMediaConfig = {
const webmMediaDecodingConfig = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

According to MediaCapabilities.decodingInfo(), the argument type of mediaCapabilities.decodingInfo(MediaDecodingConfiguration) is MediaDecodingConfiguration.
So I'd like to suggest updating to webmMediaDecodingConfig.


const MyComponent = ({ videoSources }) => {
const { mediaCapabilities } = useMediaCapabilities(webmMediaConfig, initialMediaCapabilities);
const { mediaCapabilitiesInfo } = useMediaCapabilitiesDecodingInfo(webmMediaDecodingConfig, initialMediaCapabilitiesInfo);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

According to MediaCapabilities.decodingInfo(), the return value of mediaCapabilities.decodingInfo(MediaDecodingConfiguration) is a promise fulfilling with a MediaCapabilitiesInfo interface containing three Boolean attributes: supported, smooth, and powerEfficient.
So I'd like to suggest updating to mediaCapabilitiesInfo and initialMediaCapabilitiesInfo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hook itself will return an object that will contain the 3 booleans, as mentioned in https://github.com/GoogleChromeLabs/react-adaptive-hooks/pull/51/files?file-filters%5B%5D=.js&file-filters%5B%5D=.md#r393336802

README.md Outdated
@@ -200,7 +200,9 @@ const MyComponent = ({ videoSources }) => {
};
```

This hook accepts a [media configuration](https://developer.mozilla.org/en-US/docs/Web/API/MediaConfiguration) object argument and an optional `initialMediaCapabilities` object argument, which can be used to provide a `mediaCapabilities` state value when the user's browser does not support the relevant [Media Capabilities API](https://developer.mozilla.org/en-US/docs/Web/API/Media_Capabilities_API) or no media configuration was given.
`mediaCapabilitiesInfo` value contains the three Boolean properties `supported`, `smooth`, and `powerefficient`, which describe whether decoding the media described would be supported, smooth, and powerefficient.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

I think we should explain what we can get from mediaCapabilitiesInfo as we have done in other hooks.
e.g. effectiveConnectionType values can be slow-2g, 2g, 3g, or 4g.

This hook accepts a [media configuration](https://developer.mozilla.org/en-US/docs/Web/API/MediaConfiguration) object argument and an optional `initialMediaCapabilities` object argument, which can be used to provide a `mediaCapabilities` state value when the user's browser does not support the relevant [Media Capabilities API](https://developer.mozilla.org/en-US/docs/Web/API/Media_Capabilities_API) or no media configuration was given.
`mediaCapabilitiesInfo` value contains the three Boolean properties `supported`, `smooth`, and `powerefficient`, which describe whether decoding the media described would be supported, smooth, and powerefficient.

This utility accepts a [MediaDecodingConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/MediaDecodingConfiguration) object argument and an optional `initialMediaCapabilitiesInfo` object argument, which can be used to provide a `mediaCapabilitiesInfo` state value when the user's browser does not support the relevant [Media Capabilities API](https://developer.mozilla.org/en-US/docs/Web/API/Media_Capabilities_API) or no media configuration was given.
Copy link
Contributor Author

@anton-karlovskiy anton-karlovskiy Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

According to MediaCapabilities.decodingInfo():

A TypeError is raised if the MediaConfiguration passed to the decodingInfo() method is invalid, either because the type is not video or audio, the contentType is not a valid codec MIMME type, the media decoding configuration is not a valid value for the media decoding type, or any other error in the media configuration passed to the method, including omitting values required in the media decoding configuration.

From MediaCapabilities.decodingInfo()

supported,
hasMediaConfig: !!mediaConfig
hasMediaDecodingConfig: !!mediaDecodingConfig
Copy link
Contributor Author

@anton-karlovskiy anton-karlovskiy Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

I agree with @stramel.
I guess try/catch block should wrap navigator.mediaCapabilities.decodingInfo(mediaDecodingConfig) for handling exceptions without hasMediaDecodingConfig.

A TypeError is raised if the MediaConfiguration passed to the decodingInfo() method is invalid, either because the type is not video or audio, the contentType is not a valid codec MIMME type, the media decoding configuration is not a valid value for the media decoding type, or any other error in the media configuration passed to the method, including omitting values required in the media decoding configuration.

From MediaCapabilities.decodingInfo()

mediaCapabilities = (mediaCapabilities.supported && mediaCapabilities.hasMediaConfig)
? navigator.mediaCapabilities.decodingInfo(mediaConfig)
mediaCapabilitiesInfo = (mediaCapabilitiesInfo.supported && mediaCapabilitiesInfo.hasMediaDecodingConfig)
? navigator.mediaCapabilities.decodingInfo(mediaDecodingConfig)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

What are your thoughts?
I agree with @stramel's API suggestion. I think it looks more descriptive rather than just mediaCapabilitiesInfo.
For now, I think it could be like so.

const { supported, smooth, powerEfficient } = useMediaCapabilities(initialState);

};

return {mediaCapabilities};
return {mediaCapabilitiesInfo};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

I agree with @stramel.

@@ -16,7 +16,7 @@

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wingleung cc @addyosmani

Just in the scope of naming I'd like to suggest updating like the following.

@anton-karlovskiy anton-karlovskiy force-pushed the bugfix/use-media-capabilities branch from e2bda82 to aa6fa12 Compare March 16, 2020 22:26
@anton-karlovskiy
Copy link
Contributor Author

anton-karlovskiy commented Mar 20, 2020

I'm closing this PR in favor of #52.

Thank you. @stramel @wingleung

@anton-karlovskiy anton-karlovskiy deleted the bugfix/use-media-capabilities branch March 20, 2020 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants