Skip to content

Commit

Permalink
Added new demo page.
Browse files Browse the repository at this point in the history
This is a complete replacement for the old demo page, made to be more
modern-looking and easier to maintain. It contains new features such as
remembering the URIs you provide for custom assets, and searching through
the default assets by feature.
This demo page is not quite ready for release yet, but it's getting close.

Change-Id: Iad01d1fc02c3cd238d73b9b9e02dbb4301cb6f2a
  • Loading branch information
theodab committed May 1, 2019
1 parent c0366cb commit efc2ed3
Show file tree
Hide file tree
Showing 66 changed files with 5,085 additions and 4,192 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ package-lock.json
dist/
docs/api/
coverage/
.DS_Store
22 changes: 14 additions & 8 deletions build/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
import os
import re

def compile_less(path_name, main_file_name, parsed_args):
match = re.compile(r'.*\.less$')
base = shakaBuildHelpers.get_source_base()
main_less_src = os.path.join(base, path_name, main_file_name + '.less')
all_less_srcs = shakaBuildHelpers.get_all_files(
os.path.join(base, path_name), match)
output = os.path.join(base, 'dist', main_file_name + '.css')

less = compiler.Less(main_less_src, all_less_srcs, output)
return less.compile(parsed_args.force)

def main(args):
parser = argparse.ArgumentParser(
description='User facing build script for building the Shaka'
Expand Down Expand Up @@ -98,14 +109,9 @@ def main(args):
if docs.main(docs_args) != 0:
return 1

match = re.compile(r'.*\.less$')
main_less_src = os.path.join(base, 'ui', 'controls.less')
all_less_srcs = shakaBuildHelpers.get_all_files(
os.path.join(base, 'ui'), match)
output = os.path.join(base, 'dist', 'controls.css')

less = compiler.Less(main_less_src, all_less_srcs, output)
if not less.compile(parsed_args.force):
if not compile_less('ui', 'controls', parsed_args):
return 1;
if not compile_less('demo', 'demo', parsed_args):
return 1

build_args_with_ui = ['--name', 'ui', '+@complete']
Expand Down
1 change: 1 addition & 0 deletions build/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def get(*path_components):
files = set(get('lib') + get('externs') + get('test') + get('ui') +
get('third_party', 'closure') +
get('third_party', 'language-mapping-list'))
files.add(os.path.join(base, 'demo', 'common', 'asset.js'))
files.add(os.path.join(base, 'demo', 'common', 'assets.js'))

localizations = compiler.GenerateLocalizations(None)
Expand Down
5 changes: 3 additions & 2 deletions build/conformance.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ requirement {
# Until we can get this rule updated for ES6 static methods
# (https://github.com/google/closure-compiler/issues/2880):
whitelist_regexp: 'test/test/util/canned_idb.js'
whitelist_regexp: 'test/assets/assets_integration.js'
}


Expand Down Expand Up @@ -214,13 +215,13 @@ requirement: {
type: BANNED_NAME
value: 'window.eval'
error_message: 'Using "eval" is not allowed'
whitelist_regexp: 'demo/common/demo_utils.js'
whitelist_regexp: 'demo/demo_utils.js'
}
requirement: {
type: BANNED_NAME
value: 'eval'
error_message: 'Using "eval" is not allowed'
whitelist_regexp: 'demo/common/demo_utils.js'
whitelist_regexp: 'demo/demo_utils.js'
}


Expand Down
1 change: 1 addition & 0 deletions build/gendeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'--root_with_prefix=third_party/language-mapping-list ' +
'../../../third_party/language-mapping-list',
'--root_with_prefix=dist ../../../dist',
'--root_with_prefix=demo ../../../demo',
]


Expand Down
2 changes: 1 addition & 1 deletion demo/app_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"sizes": "512x512",
"type": "image/png"
}],
"start_url": "./#compiled",
"start_url": "./#build=compiled",
"display": "standalone",
"background_color": "#FFFFFF",
"theme_color": "#2F3BA2"
Expand Down
253 changes: 253 additions & 0 deletions demo/asset_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/**
* Creates and contains an MDL card that presents info about the given asset.
* @final
*/
class AssetCard {
/**
* @param {!Element} parentDiv
* @param {!ShakaDemoAssetInfo} asset
* @param {boolean} isFeatured True if this card should use the "featured"
* style, which use the asset's short name and have descriptions.
*/
constructor(parentDiv, asset, isFeatured) {
/** @private {!Element} */
this.card_ = document.createElement('div');
/** @private {!ShakaDemoAssetInfo} */
this.asset_ = asset;
/** @private {!Element} */
this.actions_ = document.createElement('div');
/** @private {!Element} */
this.featureIconsContainer_ = document.createElement('div');
/** @private {!Element} */
this.progressBar_ = document.createElement('progress');

// Lay out the card.
this.card_.classList.add('mdl-card-wide');
this.card_.classList.add('mdl-card');
this.card_.classList.add('mdl-shadow--2dp');
this.card_.classList.add('asset-card');

const titleDiv = document.createElement('div');
titleDiv.classList.add('mdl-card__title');
this.card_.appendChild(titleDiv);
const titleText = document.createElement('h2');
titleText.classList.add('mdl-card__title-text');
titleText.textContent = asset.shortName || asset.name;
titleDiv.appendChild(titleText);

if (asset.iconUri) {
const img = document.createElement('IMG');
img.src = asset.iconUri;
this.card_.appendChild(img);
}

if (asset.description && isFeatured) {
const supportingText = document.createElement('div');
supportingText.classList.add('mdl-card__supporting-text');
supportingText.textContent = asset.description;
this.card_.appendChild(supportingText);
}

this.card_.appendChild(this.featureIconsContainer_);
this.addFeatureIcons_(asset);

this.actions_.classList.add('mdl-card__actions');
this.actions_.classList.add('mdl-card--border');
this.card_.appendChild(this.actions_);

const progressContainer = document.createElement('div');
this.progressBar_.classList.add('hidden');
this.progressBar_.setAttribute('max', 1);
this.progressBar_.setAttribute('value', asset.storedProgress);
progressContainer.appendChild(this.progressBar_);
this.card_.appendChild(progressContainer);

parentDiv.appendChild(this.card_);
}

/**
* @param {string} icon
* @param {string} title
* @private
*/
addFeatureIcon_(icon, title) {
const iconDiv = document.createElement('div');
iconDiv.classList.add('feature-icon');
iconDiv.setAttribute('icon', icon);
this.featureIconsContainer_.appendChild(iconDiv);

ShakaDemoTooltips.make(this.featureIconsContainer_, iconDiv, title);
}

/**
* @param {!ShakaDemoAssetInfo} asset
* @private
*/
addFeatureIcons_(asset) {
const Feature = shakaAssets.Feature;
const KeySystem = shakaAssets.KeySystem;

const icons = new Map()
.set(Feature.SUBTITLES, 'subtitles')
.set(Feature.CAPTIONS, 'closed_caption')
.set(Feature.LIVE, 'live')
.set(Feature.TRICK_MODE, 'trick_mode')
.set(Feature.HIGH_DEFINITION, 'high_definition')
.set(Feature.ULTRA_HIGH_DEFINITION, 'ultra_high_definition')
.set(Feature.SURROUND, 'surround_sound')
.set(Feature.MULTIPLE_LANGUAGES, 'multiple_languages')
.set(Feature.AUDIO_ONLY, 'audio_only');

for (const feature of asset.features) {
const icon = icons.get(feature);
if (icon) {
this.addFeatureIcon_(icon, feature);
}
}

for (let drm of asset.drm) {
switch (drm) {
case KeySystem.WIDEVINE:
this.addFeatureIcon_('widevine', 'Widevine DRM');
break;
case KeySystem.CLEAR_KEY:
this.addFeatureIcon_('clear_key', 'Clear Key DRM');
break;
case KeySystem.PLAYREADY:
this.addFeatureIcon_('playready', 'PlayReady DRM');
break;
}
}
}

/**
* Modify an asset to make it clear that it is unsupported.
* @param {?string} unsupportedReason
*/
markAsUnsupported(unsupportedReason) {
this.card_.classList.add('asset-card-unsupported');
this.makeUnsupportedButton_('Not Available', unsupportedReason);
}

/**
* Make a button that represents the lack of a working button.
* @param {string} buttonName
* @param {?string} unsupportedReason
* @private
*/
makeUnsupportedButton_(buttonName, unsupportedReason) {
const button = this.addButton(buttonName, () => {});
button.setAttribute('disabled', '');

// Place the tooltip into the parent container of the card, so that the
// tooltip won't be clipped by other asset cards.
// Also, tooltips don't work on disabled buttons (on some platforms), so
// the button itself has to be "uprooted" and placed in a synthetic div
// specifically to attach the tooltip to.
const tooltipContainer = this.card_.parentElement;
if (tooltipContainer && unsupportedReason) {
const attachPoint = document.createElement('div');
if (button.parentElement) {
button.parentElement.removeChild(button);
}
attachPoint.classList.add('tooltip-attach-point');
attachPoint.appendChild(button);
this.actions_.appendChild(attachPoint);
ShakaDemoTooltips.make(tooltipContainer, attachPoint, unsupportedReason);
}
}

/**
* Select this card if the card's asset matches |asset|.
* Used to simplify the implementation of "shaka-main-selected-asset-changed"
* handlers.
* @param {!ShakaDemoAssetInfo} asset
*/
selectByAsset(asset) {
this.card_.classList.remove('selected');
if (this.asset_ == asset) {
this.card_.classList.add('selected');
}
}

/**
* Adds a button to the bottom of the card that controls storage behavior.
* This is a separate function because it involves a significant amount of
* custom behavior, such as the download bar.
*/
addStoreButton() {
const unsupportedReason = shakaDemoMain.getAssetUnsupportedReason(
this.asset_, /* needOffline= */ true);
if (unsupportedReason || !this.asset_.storeCallback) {
// This can't be stored.
this.makeUnsupportedButton_('Download', unsupportedReason);
return;
}
if (this.asset_.isStored()) {
this.addButton('Delete', async () => {
await this.asset_.unstoreCallback();
});
} else {
this.addButton('Download', async () => {
await this.asset_.storeCallback();
});
}
}

/** Updates the progress bar on the card. */
updateProgress() {
if (this.asset_.storedProgress < 1) {
this.progressBar_.classList.remove('hidden');
for (const button of this.actions_.childNodes) {
button.disabled = true;
}
} else {
this.progressBar_.classList.add('hidden');
for (const button of this.actions_.childNodes) {
button.disabled = false;
}
}
this.progressBar_.setAttribute('value', this.asset_.storedProgress);
}

/**
* Adds a button to the bottom of the card that will call |onClick| when
* clicked. For example, a play or delete button.
* @param {string} name
* @param {function()} onclick
* @return {!Element}
*/
addButton(name, onclick) {
const button = document.createElement('button');
button.classList.add('mdl-button');
button.classList.add('mdl-button--colored');
button.classList.add('mdl-js-button');
button.classList.add('mdl-js-ripple-effect');
button.textContent = name;
button.addEventListener('click', () => {
if (!button.hasAttribute('disabled')) {
onclick();
}
});
this.actions_.appendChild(button);
return button;
}
}
Loading

0 comments on commit efc2ed3

Please sign in to comment.