-
Notifications
You must be signed in to change notification settings - Fork 115
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
Bugfix/use media capabilities #51
Conversation
supported, | ||
hasMediaConfig: !!mediaConfig | ||
hasMediaDecodingConfig: !!mediaDecodingConfig |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
mediaCapabilities = (mediaCapabilities.supported && mediaCapabilities.hasMediaConfig) | ||
? navigator.mediaCapabilities.decodingInfo(mediaConfig) | ||
mediaCapabilitiesInfo = (mediaCapabilitiesInfo.supported && mediaCapabilitiesInfo.hasMediaDecodingConfig) | ||
? navigator.mediaCapabilities.decodingInfo(mediaDecodingConfig) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}; |
There was a problem hiding this comment.
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}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
supported, | ||
hasMediaConfig: !!mediaConfig | ||
hasMediaDecodingConfig: !!mediaDecodingConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
mediaCapabilities = (mediaCapabilities.supported && mediaCapabilities.hasMediaConfig) | ||
? navigator.mediaCapabilities.decodingInfo(mediaConfig) | ||
mediaCapabilitiesInfo = (mediaCapabilitiesInfo.supported && mediaCapabilitiesInfo.hasMediaDecodingConfig) | ||
? navigator.mediaCapabilities.decodingInfo(mediaDecodingConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @stramel.
@@ -16,7 +16,7 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in the scope of naming I'd like to suggest updating like the following.
e2bda82
to
aa6fa12
Compare
I'm closing this PR in favor of #52. Thank you. @stramel @wingleung |
@wingleung cc @addyosmani
I've created this PR to highlight potential updates on naming and docs in media capabilities hook.