-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(ui): Add right-click context menu, statistics button #3548
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds a right-click context menu and statistics button to the UI.
theodab
requested changes
Jul 27, 2021
Improves performance by directly updating value elements.
Adds a boolean configuration value to enable the custom context menu, removing it from the control panel elements.
Logs the use of skipped stats in the configuration and fixes structure.
theodab
requested changes
Aug 3, 2021
Fixes the structure of the parsing functions and improves testing scalability.
theodab
reviewed
Aug 5, 2021
theodab
reviewed
Aug 5, 2021
theodab
reviewed
Aug 5, 2021
Besides these minor quibbles, I think your current code looks good to me! |
Fixes the naming of tests and sets a return for parsing functions.
theodab
approved these changes
Aug 5, 2021
All tests passed! |
Hello everyone! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The present pull request aims to provide a solution to #2607 (Add stats for nerds to UI (in the same way as youtube)) by adding a right-click context menu and the statistics button to the UI.
Example
How to preview
Initialize the client with a
config
that that assignstrue
to thecustomContextMenu
option, containsstatistics
in thecontextMenuElements
array and sets anstatisticsList
array with the desired statistics.Changelog
build/types/ui
Adds the
statistics_button.js
andcontext_menu.js
paths to the UI types file.docs/tutorials/ui-customization.md
A description of the
statistics
andcustomContextMenu
configuration options is provided together with an example on how to include them inui.configure()
.shaka-player.uncompiled.js
Adds the require for
StatisticsButton
andContextMenu
for the uncompiled version of the library.test/ui/ui_unit.js
Adds tests for both components.
On the second test for the statistics context menu, although there is a delay of 0.2, only a buffering time of 0.1 is expected (
expect(bufferingTime).toBeGreaterThanOrEqual(0.1);
), this is due to theshaka.util.Timer
on the button only ticking every 0.1. The equality margin could be needed in some cases (Shaka Bot onChrome 91.0.4472.114 (Linux x86_64)
) and is explained in #3494.ui/context_menu.js
A new context menu element is added to the UI. The structure to build the context menu is exactly the same as the currently existing overflow menu, replicating the use of the existing
registerElement()
,createChildren_()
andrelease()
functionalities for factories, children and release handling.ui/controls.js
Following the same structure of other boolean UI elements (like
addBigPlayButton
oraddBigPlayButton
), the context menuis added in the controls when
customContextMenu
is true.ui/enums.js
Adds two additional Material Design Icons to be used in the statistics button.
ui/externs/ui.js
The new
statisticsList
property is added, giving the option to select specific statistics for the button.The new
contextMenuElements
property is added, giving the option to select elements to appear inside the context menu. Currently, this array can only contain'statistics'
, as there are no other elements for the menu.The new
customContextMenu
boolean is added, giving the option to display a custom context menu.ui/less/container.less
A new
.shaka-context-menu
class is created to declare the styles of the context menu.A new
.shaka-statistics-container
class is created to declare the styles of the container that displays the statistics.ui/locales/en.json
The statistics button name is added only in
en.json
as an example.ui/locales/source.json
The statistics button name and description are added to the locales source.
ui/statistics_button.js
Using
shaka.util.Timer
,player.get_stats()
is called repeatedly when the statistics container is displayed.Statistics recovered from the Stats extern are assigned a specific unit category on
parseFrom_
, which connects to a function defined inparseTo_
that parses the current value to an easily readable output.generateComponent_(name)
receives the name of the statistic and creates a div with the name and parsed current value (i.e: width: 1080px) that is added to the statistics container ononTimerTick_()
.All of the
value
spans are stored inthis.displayedElements_
and are later updated directly to avoid performance loss.ui/ui.js
The default configuration of
statisticsList
is added, displaying almost all of the available statistics, with the exception ofstateHistory
andswitchHistory
. Additionally, they are displayed in an order that when later parsed in the container, visually groups together the statistics of the same unit category.The default
contextMenuElements
configuration includesstatistics
only, as it is the only button available in the context menu.The
customContextMenu
boolean is false by default to avoid affecting existing applications.Checklist