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

Editor: Support VideoPress post-editor preview #2267

Closed
wants to merge 22 commits into from

Conversation

mjuhasz
Copy link
Contributor

@mjuhasz mjuhasz commented Jan 11, 2016

Closes: #1730

This pull request enables previewing of VideoPress videos in the post editor.

There is currently no VideoPress preview offered in the post editor on WordPress.com. When adding a VideoPress video to a post, only the shortcode text is shown in the editor post content. Only after saving and previewing the post can a user see how the post will look like.

Before:

screen shot 2016-01-18 at 10 50 45 am

After:

screen shot 2016-01-18 at 10 52 47 am

Testing instructions:
Scenario 1 - adding media from your library:
  1. Navigate to the Calypso post editor.
  2. Select a site, if prompted.
  3. Create a new post.
  4. Click on Add Media, select a video from your library, then click Insert.
  5. Note that a video player is displayed in the editor.
  6. Confirm that you can start playing the video and adjust the volume.
  7. Confirm that by having the video player in focus (e.g. after clicking at its top bar) a remove button shows up with which the video can be removed.

Strictly speaking Scenario 1 resolves issue #1730, nevertheless the following use cases should also work:

Scenario 2 - adding media by pasting a shortcode:

Same as Scenario 1, except Step 4: Insert the following shortcode text into the editor: [wpvideo kUJmAcSf]

Scenario 3 - using shortcode attributes:

Same as Scenario 1, except:

Step 4: Insert the following shortcode text into the editor: [wpvideo kUJmAcSf at=90 ]
Step 5: Note that a video player is displayed in the editor and its start time is 1m30s.

Remark: not all shortcode attributes are fully supported at this time for preview.

@mjuhasz mjuhasz force-pushed the add/wpvideo-preview-by-direct-iframe branch from a39341a to 1a91394 Compare January 17, 2016 19:42
@mjuhasz mjuhasz added the [Feature] Post/Page Editor The editor for editing posts and pages. label Jan 17, 2016
@mjuhasz mjuhasz self-assigned this Jan 18, 2016
@mjuhasz mjuhasz changed the title Editor: Support VideoPress post-editor preview (#2) Editor: Support VideoPress post-editor preview Jan 18, 2016
@mjuhasz
Copy link
Contributor Author

mjuhasz commented Jan 18, 2016

A few outstanding issues/remarks:

  • default attributes are not left out from the url - they do not do any harm but they could be filtered out if we have definite defaults
  • video width/height and aspect ratio are given some default value but ideally they would be queried from VideoPress. In Jetpack's VideoPress_Video class there is a remote call to get these attributes. Similar logic could be replicated in the wpview plugin.
  • width shortcode attribute is ignored right now because a tinymce css entry overrides it: the VideoPress iframe is a descendant of a div with class wpview-wrap so it gets 100% width. We did not have this issue when the shortcode was rendered because there was an extra iframe around the VideoPress one.
  • some attributes are not parsed: permalink - it does not seem to take effect; freedom and flashonly - the player embedded in the VideoPress iframe is used

const namedAttrs = shortcode.attrs.named;
const defaultWidth = 640;
const defaultHeight = defaultWidth * 9 / 16;
return {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using Object.assign (or similarly, _.assign or _.defaults) can be a handy way to clearly identify the default values, while still allowing override if value is known:

return Object.assign( {
    w: defaultWidth,
    h: defaultHeight,
    at: 0,
    defaultLangCode: false
}, {
    videopress_guid: shortcode.attrs.numeric[0],
    w: parseInt( namedAttrs.w, 10 ),
    h: parseInt( namedAttrs.h, 10 ),
    autoplay: namedAttrs.autoplay === 'true',
    hd: namedAttrs.hd === 'true',
    loop: namedAttrs.loop === 'true',
    at: parseInt( namedAttrs.at, 10 ),
    defaultLangCode: namedAttrs.defaultlangcode
} );

Might be a negligible performance difference, though the clarity benefits should outweigh this. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very handy, indeed! It makes the intent of the code much clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very handy, indeed! It makes the intent of the code much clearer.

Actually, this will not work as expected, as the presence of the key in the second argument will override the default value, regardless of whether the value is truthy.

For example, try entering this in your browser console (assuming your browser supports Object.assign):

Object.assign( { a: 1 }, { a: undefined } );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the end I used lodash's _.defaults. I also had to substitute NaN for undefined to get the expected behavior (i.e. used the default if one exists for unspecified attributes).

@aduth
Copy link
Contributor

aduth commented Jan 18, 2016

Result of running eslint client/components/tinymce/plugins/wpcom-view/wpvideo-view.jsx:

/Users/andrew/Documents/Code/wp-calypso/client/components/tinymce/plugins/wpcom-view/wpvideo-view.jsx
  43:36  warning  There must be a space inside this paren               space-in-parens
  49:25  warning  Infix operators must be spaced                        space-infix-ops
  50:52  warning  Unexpected space before function parentheses          space-before-function-paren
  51:44  warning  Unexpected space before function parentheses          space-before-function-paren
  52:6   warning  Expected indentation of 4 tab characters but found 5  indent
  53:5   warning  Expected indentation of 3 tab characters but found 4  indent
  55:5   warning  There must be a space inside this paren               space-in-parens
  55:10  warning  There must be a space inside this paren               space-in-parens
  55:18  warning  Unexpected space before function parentheses          space-before-function-paren
  57:5   warning  There must be a space inside this paren               space-in-parens
  57:11  warning  There must be a space inside this paren               space-in-parens
  57:15  warning  There must be a space inside this paren               space-in-parens

✖ 12 problems (0 errors, 12 warnings)

You might consider installing a linting plugin for your editor for these issues to be more evident:

https://github.com/Automattic/wp-calypso/blob/master/docs/coding-guidelines/javascript.md#eslint

@mjuhasz mjuhasz force-pushed the add/wpvideo-preview-by-direct-iframe branch 4 times, most recently from 8b30730 to 8c65d3a Compare January 25, 2016 12:44
@mjuhasz mjuhasz force-pushed the add/wpvideo-preview-by-direct-iframe branch 6 times, most recently from fe07fa8 to c45610d Compare January 27, 2016 13:10
@mjuhasz mjuhasz added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Status] In Progress labels Jan 31, 2016
width: 100%;
}

.wpview-wrap iframe {
display: block;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixed whitespace (this should be tabs, not spaces).

Additionally, you may consider leveraging nesting for the pseudo-class :not selector (reference), i.e.

.wpview-wrap iframe {
    display: block;

    &:not( .wpview-type-video ) {
        width: 100%;
    }
}

Also note spaces between parens (reference).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@aduth
Copy link
Contributor

aduth commented Feb 5, 2016

I wonder if we could reuse some of the embed view logic to simplify this, as the oEmbed endpoint markup already returns the video's known dimensions and includes the resizing script automatically.

Example: https://public-api.wordpress.com/oembed/1.0/?url=https%3A%2F%2Fvideopress.com%2Fv%2FkUJmAcSf%3Fat%3D90&for=wordpress

defaultLangCode: namedAttrs.defaultlangcode
};

return omit( attrs, ( v, k ) => defaultAttrValues[k] === v );
Copy link
Contributor

Choose a reason for hiding this comment

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

Many of the variable names in these files are obscure acronyms, which we try to avoid, as they're much more difficult to understand at a glance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the variable names more descriptive.

Attribute names are cryptic because those are the names expected in the query string and I want to avoid mapping them back and forth.

@mjuhasz mjuhasz force-pushed the add/wpvideo-preview-by-direct-iframe branch from f3fe8e9 to f77b87b Compare February 7, 2016 14:13
@mjuhasz mjuhasz force-pushed the add/wpvideo-preview-by-direct-iframe branch from f103161 to 3a30ac3 Compare March 5, 2016 10:10
@mjuhasz
Copy link
Contributor Author

mjuhasz commented Mar 5, 2016

The branch is rebased and test are up to the new standard.

Can you elaborate on how I could reproduce the multiple requests you saw?

If I load a draft with video with debug messages enabled (localStorage.setItem( 'debug', '*' );)

  1. render is called in WpVideoView which in turn renders <QueryVideo>.
  2. Right after that a wpcom:send-request sendRequest("/videos/kUJmAcSf" ) request is sent out.
  3. WpVideoView gets re-rendered after wpcom-proxy-request got 200 status code for URL: "/videos/kUJmAcSf"

No other wpcom request is sent out for "/videos/kUJmAcSf" according to the console log.

@mjuhasz mjuhasz added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Mar 5, 2016
@aduth
Copy link
Contributor

aduth commented Mar 7, 2016

@mjuhasz : I should have paid attention to the "Initiator" column in the network tab:

Initiator

I'm guessing that these requests originate from the VideoPress script. Pretty unfortunate that the additional requests are made, but not sure we can do much about it under the current approach.

@apeatling
Copy link
Member

@aduth @mjuhasz This has been a long time now, and seems like a great improvement. Can we get this one in? Otherwise we should close this.

@apeatling apeatling added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 2, 2016
@aduth
Copy link
Contributor

aduth commented Jun 2, 2016

@mjuhasz : Do you recall if there were any blockers to merging this? We'll want to rebase, but I'd be happy to help move this one forward, especially given the issues encountered in #3832 in using the shortcode iframe for rendering.

@mjuhasz
Copy link
Contributor Author

mjuhasz commented Jun 2, 2016

@aduth VideoPress.js issues multiple requests for the same endpoint when loading a post which includes a video. Your former assessment still holds true:

Pretty unfortunate that the additional requests are made, but not sure we can do much about it under the current approach.

@lancewillett lancewillett deleted the add/wpvideo-preview-by-direct-iframe branch September 2, 2016 16:17
@lancewillett lancewillett restored the add/wpvideo-preview-by-direct-iframe branch September 8, 2016 18:28
@lancewillett
Copy link
Contributor

Re-opening since it'd be great to get #1730 support for improving our video offering, especially as it's a part of a paid plan.

@lancewillett lancewillett reopened this Sep 8, 2016
@lancewillett lancewillett added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Sep 8, 2016
@aduth
Copy link
Contributor

aduth commented Sep 29, 2016

Closed in favor of #8342

@aduth aduth closed this Sep 29, 2016
@aduth aduth deleted the add/wpvideo-preview-by-direct-iframe branch September 29, 2016 20:24
@lancewillett lancewillett removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Post/Page Editor The editor for editing posts and pages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editor: implement VideoPress in-editor previews
4 participants