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

fix: make sure hotkeys are not triggered outside the player or in form fields within the player #5969

Merged
merged 13 commits into from
May 30, 2019

Conversation

misteroneill
Copy link
Member

@misteroneill misteroneill commented Apr 29, 2019

Description

We saw some issues with the recently-added hotkeys feature.

  1. The use of document-level keydown listeners caused players to respond to events they should not have when focus was not in the player.
  2. Those keydown events which do reach the player are considered possible hotkey triggers. However, there are sometimes elements added to the player - such as in modals - that should not trigger hotkeys.

Specific Changes proposed

  • Rename any handleKeyPress method to handleKeyDown because that's more accurate. Define handleKeyPress as a Component method that delegates to handleKeyDown so that any existing uses of it should not break.
  • Do not bind/unbind listeners on focus/blur and stop listening for keydown events on the document. It's better to just listen for keydown events on the components themselves.
  • Add exceptions for certain elements by their tagName.
  • Call stopPropagation() in key places to prevent double keydown handling.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Change has been verified in an actual browser (Chome, Firefox, IE)
    • Unit Tests updated or fixed
    • Docs/guides updated
  • Reviewed by Two Core Contributors

src/js/player.js Outdated

this.handleHotkeys(event);
// Bail out if the user is focused on an interactive form element.
if (activeTag && hotkeysDisallowed.indexOf(activeTag) !== -1) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this would prevent hotkeys from working in any of the control bar buttons, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, I did try that, but I'll verify.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. I must have added this filtering before actually verifying it! D'oh!

Copy link
Member

Choose a reason for hiding this comment

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

I guess you can verify if the element is contained in the control bar and then skip this check

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, buttons are generally only activated on Space/Enter, which we pass through to the browser anyway. Other keys (e.g. m, f, k, etc) are unlikely to affect a button. Seems safe to allow buttons and blacklist them if it becomes an issue for whatever reason.

Copy link
Member

Choose a reason for hiding this comment

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

Potentially, though, you can also define buttons as an input tag. It may be worth doing the control bar check regardless of which elements we disallow.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, true. The control bar check seems dirty, though. I'll ponder it.

@misteroneill
Copy link
Member Author

I realized that userActions does not appear to have tests. I will rectify that in this PR.

Copy link
Member

@OwenEdwards OwenEdwards left a comment

Choose a reason for hiding this comment

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

This all LGTM, and also seems to address/fix #5774. The only thing is, I don't have an example of where it was causing problems, to see how the behavior compares after the fix, but I suppose you do?

And thanks for adding a userActions test! This feature could definitely use some automatic testing!

@misteroneill
Copy link
Member Author

Glad to hear it. It's fairly easy to reproduce if you use a page with a Video.js player embedded. If you hit the big play button then move focus into a text field or something, you can activate hotkeys when typing into the field.

@misteroneill misteroneill force-pushed the fix/hotkeys-focus branch 2 times, most recently from 3553538 to cba07fc Compare May 6, 2019 20:20
@misteroneill
Copy link
Member Author

misteroneill commented May 6, 2019

For some reason the tests are failing on BrowserStack. Will have to investigate tomorrow.

@gkatsev
Copy link
Member

gkatsev commented May 17, 2019

Clicking on the BPB or the poster initially no longer enables hotkeys.

@misteroneill misteroneill changed the base branch from master to 7.5.x May 28, 2019 15:27
@gkatsev gkatsev merged commit d251e97 into 7.5.x May 30, 2019
@gkatsev gkatsev deleted the fix/hotkeys-focus branch May 30, 2019 15:16
gkatsev pushed a commit to gkatsev/video.js that referenced this pull request Jun 10, 2019
jasiekmiko pushed a commit to Softwire/video.js that referenced this pull request Jul 10, 2019
Change comprises of commenting out event.stopPropagation calls added in
a recent bug fix. The following comment was added in affected places:

Videojs 7.5.5 has added event stopPropagation throughout its components to fix some hotkeys behaviour, such as reacting to hotkeys insie of forms inside the player.
This broke our keyhandling implemenation, preventing any remote key presses from being handled. See more here:
- videojs@79eadac
- videojs#5969
The reasons to stop propagation don't seem to apply to our usecase, so it should be safe to leave this commented out.
If this causes problems in the future, the alternative solution would perhaps be to use rewrite our key handling to go through the hotkeys system:
https://github.com/videojs/video.js/blob/cf6e0e824814f3ccb061b057a9aa5eff3b54ba6e/docs/guides/options.md#useractionshotkeys
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