-
Notifications
You must be signed in to change notification settings - Fork 798
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
Add Video Tracks Support to VideoPress Block #21578
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
…n this context - it is only available in recent Gutenberg releases. h/t @jgcaruso
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 code looks good and works as described! All add/delete scenarios worked as expected and UI updates all appear to occur correctly.
Might be worth getting a second set of eyes on it since it is so large, but the new portions of tracks-editor.js
looked OK to me.
@@ -80,6 +81,8 @@ const VideoPressEdit = CoreVideoEdit => | |||
const { guid } = this.props.attributes; | |||
if ( ! guid ) { | |||
await this.setGuid(); | |||
} else { | |||
this.setTracks( guid ); |
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.
It looks like setTracks
always gets called inside setGuid
, is this second call still necessary?
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 so, as I'd like it to still fetch the tracks even if the guid
is in the attributes - in case tracks were added in a separate block for the same video.
projects/plugins/jetpack/extensions/blocks/videopress/editor.scss
Outdated
Show resolved
Hide resolved
$grid-unit-05: 0.5 * $grid-unit; // 4px | ||
$grid-unit-10: 1 * $grid-unit; // 8px | ||
$grid-unit-15: 1.5 * $grid-unit; // 12px |
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.
nit: whitespace doesn't match
Cleaned up some whitespace issues.
projects/plugins/jetpack/extensions/blocks/videopress/editor.scss
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/videopress/editor.scss
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/videopress/tracks-editor.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/videopress/tracks-editor.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/videopress/tracks-editor.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/videopress/tracks-editor.js
Outdated
Show resolved
Hide resolved
…n for easier readability in render()
* Translators help comment added to `Kind` string. * Change a string to use `sprintf` for easier translation.
The new code changes look good, and manual testing continues to work as expected! Leaving unapproved to wait for a 2nd team reviewer, but otherwise I'm happy with it. |
Just noting here that we're investigating an issue where the tracks don't save via the new API endpoint in production. If you still want to test this functionality, it should work if you sandbox |
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.
Tested well with a sandboxed public-api. Some wee things to address, other than that good to go.
@@ -80,6 +81,8 @@ const VideoPressEdit = CoreVideoEdit => | |||
const { guid } = this.props.attributes; | |||
if ( ! guid ) { | |||
await this.setGuid(); |
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.
is there a chance that this call will throw? Should we wrap in a try/catch?
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.
From looking at setGuid
, I think it doesn't throw, but it does fall back
to the core block if something goes wrong. So I think safe to leave as-is.
return; | ||
} | ||
|
||
await apiFetch( { |
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.
Does this throw if the request fails? In async/await the catch portion becomes an exception we should probably handle.
url: `https://public-api.wordpress.com/rest/v1.1/videos/${ guid }`, | ||
credentials: 'omit', | ||
global: true, | ||
} ).then( videoInfo => { |
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.
if we use async/await then the then()
part is not needed, we can instead do const videoInfo = await apiFetch(...);
On the other hand, since this code seems pretty Promise-based, we can just go all in and: 1. get rid of await 2. add catch/finally to the 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.
Updated in bb30f90! I don't think we need to take any action in a catch
or finally
in this case. If we don't get the video info back, then we simply won't set the tracks data.
This is fixed now, test away! 😉 |
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.
tested well, both on sandbox and prod!
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 looks good to me! 🚢
Great news! One last step: head over to your WordPress.com diff, D69242-code, and commit it. Thank you! |
Deployed to wp.com: r235597-wpcom |
# By Jeremy Herve (5) and others # Via GitHub * master: (26 commits) Colors: update Primary green reference to match latest brand book (#21741) JS Connection: Moves registerSite logic to the store (#21732) Search: Add essential scaffolding for package (#21814) Search: avoid registering the widget when the module is not active (#21588) Add Video Tracks Support to VideoPress Block (#21578) Add deprecated to VideoPress block (#21802) Admin Menu: Make API tests compatible with WPCOM (#21850) External Media: Short-circuit requests earlier in the stack (#21854) Add Busy State to License Activation Flow Button (#21861) Fixed an issue with screen resolutions of under 783px that caused the content to not be properly displayed when the nav-unification is expanded on wp-admin. (#21869) E2E tests: migrate from Jest to Playwright runner (#21848) Update reCAPTCHA constants to match Google's Verbage (#12289) JITM: Sideload Jetpack Boost functionality (#21860) Connection: properly add GET-parameters for the `fetchAuthorizationUrl` API call (#21750) License Flow: Assorted Styling Improvements (#21859) JITM: Sideload Jetpack Backup (#21719) Widget Visibility: Apply widget filtering to customizer preview (#21505) jetpack: Avoid generating unused JS for static-site-generator assets (#21789) Nav Unification: Support absolute URLs in upsell nudges (#21821) RePublicize: Enable the block editor UI by default (#21855) ... # Conflicts: # projects/plugins/boost/tests/e2e/lib/env/prerequisites.js # projects/plugins/boost/tests/e2e/lib/setupTests.js
Adds support for uploading .vtt files to add captions/subtitles to a VideoPress video. Because of the way VideoPress is embedded with iframes, we need to host and serve the .vtt files from wp.com to avoid CORS issues.
When a track is selected, it will get uploaded to wp.com and attached to the video. The video player will fetch the tracks data from the API video endpoint and load the tracks into the UI. Most of this code is from the core video block's tracks component, with some tweaks added to support the management of the tracks via the API.
Screenshot:
Testing instructions:
English
,en
, andsubtitles
.Source language
field can't be larger than 5 characters. You should see an error message at the bottom of the component.Does this pull request change what data or activity we track or use?
No.