Commit Graph

38 Commits

Author SHA1 Message Date
Joey Parrish c9bd9a5dc9 fix: Correct license headers in demo app
Though not part of the library, this corrects/normalizes the license
headers in the demo app to be consistent with those in the library.

Issue #2638

Change-Id: I4546c4c6970d72ff71a37489fd582623bd6e2ca3
2020-06-09 16:07:06 -07:00
Joey Parrish 741424eef6 fix: Correct IMA SDK URLs in service worker and docs
The IMA SDK URLs in the service worker were http, and should have been
https.  This caused an issue when deploying v3.0.0 to appspot.

The IMA SDK URLs in the demo specified no protocol, but that is not
necessary, since https works in all contexts.

The IMA SDK URLs in the docs also specified no protocol, and one of
them was incorrect.

This corrects the mistaken URLs and makes them universally https.

Change-Id: I53dbf25ddb16ec882fcf3c070bcebed726277be1
2020-06-08 20:38:49 -07:00
Joey Parrish aba5e2583c Rename v2.6 to v3.0 and v2.7 to v3.1
We have decided to bump the major version number instead of the minor
number, based primarily on the fact that this release breaks
compatibility with our previous manifest structure.

Change-Id: I67e4c8267c6e103cfc7278e09daac186ae5cbbc6
2020-05-29 17:50:22 +00:00
Joey Parrish 97b4f3d47d Update service worker cache name
In preparation for v2.6, update the service worker cache.  Old caches
will be dropped, which should clean up any extraneous resources cached
by the v2.5 version.

Change-Id: Ief45857ba6033d65e4b267463f0a12a670b71535
2020-03-10 14:51:18 -07:00
Joey Parrish d224fc46a5 Activate service worker updates right away
Instead of waiting for all active pages to be closed and the old
service worker shut down, activate the new service worker right away
as soon as it is installed.

Change-Id: Ia49b6f44d026a934f46cb5cf2a86dc9de9274b0c
2020-03-10 14:51:18 -07:00
Joey Parrish e235a4fcbe Complain about missing resources for compiled-mode PWA
If the demo app is running in compiled mode, the PWA service worker
will now complain about any local resources that are requested by the
app but not marked for caching.  This helps catch missing resources in
the service worker's resource lists.

Change-Id: Ia7f65f8ca6679e5c4ba29a1474a42aa97f33278b
2020-03-10 14:51:18 -07:00
Joey Parrish ebfde6422d Don't cache everything from the demo origin in service worker
Before this change, location.origin appeared in a list of cacheable
URL prefixes in the service worker.  This was a lazy way of making
sure that all node modules, translations, etc. would be cached without
being explicitly listed.  But it also meant that we could wind up
caching the uncompiled sources, which can complicate debugging if they
are inadvertently pulled from cache on reload.

This change adds the missing local resources that can't be listed
explicitly (translations, logos) by using absolute URL prefixes.

Change-Id: I4963516ec392e7607f86bc891bcdcf46c141951d
2020-03-10 14:51:10 -07:00
Joey Parrish 3d3a2c7fb9 Convert relative URL list to absolute in service worker
The URLs of critical and optional resources will now be converted to
absolute URLs.  This will allow the exact URL matching against those
lists to work, which will let me subsequently remove location.origin
from the list of cacheable URL prefixes.  (In a follow-up commit.)

Change-Id: I886d11435c96944f9b50ebf937dd329357f5c257
2020-03-10 14:50:29 -07:00
Joey Parrish f76624545e Fix exact URL lookup for PWA cache
Some of the request URLs in service worker fetch events contain has
parameters, which breaks our exact URL lookups for critical and
optional resources.  This fixes the lookups by removing hash
parameters.

Change-Id: I56b22a2faa42e2f3c28bd82fae4e8feedc83d408
2020-03-10 14:50:26 -07:00
Joey Parrish 25f28f8301 Add missing node modules and IMA SDK to PWA cache
Change-Id: I20d45fd729c487c55b88e695a213cd3955b54241
2020-03-10 14:50:10 -07:00
Joey Parrish 5387bf6f46 Fix missing await in service worker
Without the "await" on timeout, try/catch would not catch a timeout
error, leading to request failures in some cases.

This bug is present in v2.5.x as well as the master branch.

Change-Id: I3a0c8cd46265d41bade8117edd3cb92ac597d4fd
2020-03-10 14:50:00 -07:00
Joey Parrish 64896d70b0 Use shorter license header
This reflects changes in Google's policy on JavaScript license
headers, which should be smaller to avoid increasing the size of the
binary unnecessarily.

This also updates the company name from "Google, Inc" to "Google LLC".

Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
2019-11-22 18:18:36 +00:00
Joey Parrish a06965dbb4 Update path to dialog polyfill
When we upgraded the node modules, we missed the fact that this path
changed.  This broke the demo app on Firefox, but not on Chrome, where
the polyfill is not needed.

Closes #1947

Change-Id: If889c46f840df7e3ee4aa67ab5026f0cebec2a41
2019-05-16 16:52:36 +00:00
Jacob Trimble f130dffcef Enable eslint indentation rule.
This is a fully automated change.  The linter will fail because the
extra indentation caused line-length errors.  These won't be fixed
automatically.  They are fixed in a follow-up to make this one fully
automated.

Change-Id: I4d8cf9c998985add2bcd24a81c8d65495668c4f3
2019-05-13 22:31:09 +00:00
Joey Parrish d66d6c4255 Upgrade mux.js and use minified version
The new mux.js release fixes support for a minified build, so we
should use that from now on.

videojs/mux.js#173

Change-Id: I08cff8d33a520fe753c5490a4719cba3bb27f19e
2019-05-13 14:24:41 -07:00
Joey Parrish 23c79955a7 Fix inlining of external CSS
Importing in less is not enough.  It will not necessarily inline what
is imported by default.  The "inline" option, however, will force the
CSS file to be inlined.  Without this, some of the `@import`
statements are put directly into the output file, triggering
additional network requests at runtime.  This also adds the "css"
option, which forces less to treat these inputs as CSS and not as
LESS.

Finally, we import MDL for the demo app as a node dependency instead
of loading it from another origin.

This improves the demo's Lighthouse scores of "First Contentful Paint"
by 27% and "First Meaningful Paint" by 14%.

Change-Id: I28e627d3df494e3c4893d31b6bf818f09e8153e9
2019-05-13 17:43:40 +00:00
Joey Parrish 34585af993 Inline external CSS for quicker load
This reduces the number of resources we have to load by using LESS to
import them into the compiled CSS bundle.

This also gets rid of a flash of unstyled content in compiled mode by
always including the compiled CSS in HTML directly, regardless of
mode.  If the app is running in uncompiled mode, LESS is still loaded
and can override the compiled styles.

Change-Id: I8cde25c15c281029a129225fc85a8baee767f424
2019-05-09 19:05:17 +00:00
Jacob Trimble 47daf49f31 Use arrow functions for callbacks.
This is an automated change to convert use of "function" functions
to arrow functions.  This doesn't change all uses of bind() that
could be converted.  This also doesn't remove all "function" functions.

Change-Id: I40ac7d086bcef947a1be083359c8fd1d4499a9c3
2019-05-09 16:40:46 +00:00
Joey Parrish c02cd2e8c6 Switch back to unminified mux.js
It turns out that due to a mux.js bug, the minified version is unusable.
See videojs/mux.js#173

Change-Id: I8d028e3f2b01789b6c0f99df736b29ee2d7b0c4f
2019-05-02 14:48:50 -07:00
Joey Parrish 269b53b7a0 Improve lighthouse score
- Use a minified mux.js and awesomplete.js
 - Add rel=noopener to offsite target=_blank links for security
 - Improve contrast on selected nav button and footer text
 - Add empty alt attributes to asset images, since these are
   not necessary to understand the page

Change-Id: I253c7354243aaa0fe98e1f075dae304ddad4a3e2
2019-05-01 17:25:45 -07:00
Joey Parrish d7e2501c5c Use no-cors mode for all service worker resources
Some of the resources we load from other origins must be loaded as
opaque resources that can't be read by the application.  In fact, it
turns out that there are no app resources that need to be read by the
app.  So we should load everything in no-cors mode as opaque
resources.  This fixes failures loading and caching MDL resources.

Change-Id: I25ec4228285e3149746d906e6461ac04aeedc7e1
2019-05-01 23:23:08 +00:00
Joey Parrish e8d95a474c Fix service worker resource list for the new demo
- Don't cache Roboto Condensed, which is no longer used
 - Add back style sheet to load the Roboto font, which is used
 - Cache dialog and datalist polyfills used by the demo app

Change-Id: I0e347748a9830d95db0e4ba6bbfda7033edd3ac1
2019-05-01 23:23:08 +00:00
Joey Parrish 598d330d52 Fix service worker cache response for other origin
The service worker should not only be deciding what to cache, but what
to pull from cache.  A recent refactor to this file overlooked this,
which caused resources from other origins not to be available offline,
even though they were cached.

Change-Id: I62d7c2f96827e778a991b06d0bd222c4f0cb336b
2019-05-01 23:23:08 +00:00
Theodore Abshire efc2ed3df1 Added new demo page.
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
2019-05-01 19:58:18 +00:00
Joey Parrish 0d5d952c0a Don't handle non-app resources in service worker
It seems that once you start handling a request in the service worker,
CORS restrictions are applied differently.  So we shouldn't handle
requests that aren't application resources to be cached.

This cleans up the service worker and makes sure that we only handle
the requests we are supposed to.  This avoid CORS errors reported in
a few old issues, as well as those seen in more recent Safari native
HLS work.

Issue #997
Closes #1256
Closes #1392

Change-Id: I0dff4a1f4f2a47b5f76a13625b673f717ebbd0ba
2019-04-30 17:04:55 +00:00
Joey Parrish 0147a78f9a Add localization lazy-loading to the demo app
The demo app will now respond to events from the localization system
to lazy-load missing localization data at runtime.  This will enable
the demo app to display a localized UI in non-compile-time-default
locales.

This required several changes to the compiled build to add missing
export annotations and quoted strings on event fields.

Issue #1688

Change-Id: I1e756d8ce7861bf822ec0e7d4090f143a201d422
2019-04-10 18:13:23 +00:00
Joey Parrish 349759f089 Fix controls CSS URL in service worker
The service worker was fetching an out-of-date URL for the controls
CSS.  This updates the URL so that we are caching the correct files
for use offline.

Change-Id: I842a7f696e08e7d1b6505d24b7b9c763fb4f5a75
2019-02-19 13:30:06 -08:00
Sandra Lokshina 6b1ca2d229 Initial release of Shaka Player UI
Other contributors:
 - @joeyparrish
 - @michellezhuogg
 - @TheModMaker
 - @theodab
 - @vaage

Change-Id: If6df33d9ab5035d1ead4402004f7de37ee8470f4
2018-11-16 14:40:37 -08:00
Joey Parrish 7091275cbf Replace indexOf with includes, startsWith
This replaces almost every instance of indexOf on both String and
Array.  There are very few places where we really wanted an index.
Mostly, indexOf was used to check for inclusion.

Change-Id: I08e299768b6ffdb4bfc30b39b5d82a058c6d1b56
2018-09-14 19:10:56 +00:00
Joey Parrish fd0449d8f7 Re-enable some disabled style rules
This re-enables the following style rules:
  - "block-spacing"
  - "brace-style"
  - "comma-dangle"
  - "comma-spacing"
  - "new-cap"
  - "no-multi-spaces"
  - "no-multiple-empty-lines"
  - "one-var"
  - "padded-blocks"
  - "prefer-rest-params"

Change-Id: I15d616e8d5b88b273ded6128b4f9ad86bdb26bd1
2018-07-09 19:44:56 +00:00
Joey Parrish 66abf9cb27 Remove all protocol-relative URIs
According to @beaufortfrancois, we should no longer be using protocol-
relative URIs.  He quotes this passage from Paul Irish:

> Now that SSL is encouraged for everyone and doesn’t have performance
> concerns, this technique is now an anti-pattern. If the asset you
> need is available on SSL, then always use the https:// asset.

> Allowing the snippet to request over HTTP opens the door for attacks
> like the recent Github Man-on-the-side attack. It’s always safe to
> request HTTPS assets even if your site is on HTTP, however the
> reverse is not true.

Source: https://www.paulirish.com/2010/the-protocol-relative-url/

This change was begun with the following command:
  git grep -l "'//" | xargs sed -i "s@'//@'https://@g"

Some changes made by that command were false-positives, which I then
reverted manually.  Others required additional cleanup to meet style
rules.

I've also just discovered that the "max-len" rule in eslint's Google
style config exempts URIs, so there's no need to disable the max-len
rule on URIs in the assets list.  These have been removed in the asset
list where unnecessary.

Finally, testing these updated URIs led to the discovery that two of
our third-party demo assets are no longer available.  One URI needed
to be updated.  The other had no obvious replacement, so it was
removed.

Closes #1390

Change-Id: I2fe23faec04f1904c1741236b364d5089900092a
2018-04-09 18:06:18 +00:00
Theodore Abshire 987dc9e77c Typo fixes and rewording in comments, part Final
This makes a large number of small typo fixes. It also rewords a
number of comments and JSDoc descriptions, and does some
formatting standardization.

This doesn't fix every single issue, but it fixes a lot. Notably,
there were some formatting issues I declined to standardize due to
ambivalence on what the proper standardization would be; for example,
when and where empty lines should show up in JSDoc.

Change-Id: I93d0f3faedb8a42423b6971f6499d651b20492d1
2018-03-21 19:45:22 +00:00
Jacob Trimble 064089152b Remove spacing around object definitions.
This is an automated fix to be inline with Google style guides, this
was created with eslint's --fix option.

Change-Id: I860eecbc8152603e730aa17a1393f16d26b3b6fc
2018-02-21 13:35:00 -08:00
Jacob Trimble 2a130473dc Convert 'var' to 'let'/'const' (9 of 9).
This is part of a change to convert all usages of 'var' with either
'let' or 'const'.  This takes a conservative approach for 'const' where
it will only be used for aliases and storing the "original" values in
tests.

Change-Id: I270c70f6cda733ca6121d0761b4c1c162104d379
2018-02-20 11:30:04 -08:00
Joey Parrish a63352c8f3 [ES6] Enable stricter checks in eslint
This digests and organizes many of the automatic settings in eslint,
and changes several of them to be more strict.  This also fixes the
following errors:
  - array-callback-return
  - no-catch-shadow
  - no-multi-spaces
  - no-new
  - no-throw-literal
  - no-useless-call
  - no-useless-concat
  - no-useless-return

Several checks have been organized into a group of checks we should
use, but need more time to implement and fix.  Some other checks have
been delegated to the Closure compiler, which can more precisely
whitelist exceptions.

Issue #1157

Change-Id: I8fe4966959e08050f8159e6a1fee161e7d71177e
2018-01-17 21:56:41 +00:00
Joey Parrish 5afd3465ae Cache mux.js in the service worker
Issue #1078

Change-Id: I778cd499ac4856c9a07dd75984c9a27ae871b3f3
2017-10-23 14:44:11 -07:00
Joey Parrish 5fb2bdc4b0 [PWA] Prefer serving fonts from the cache
Web fonts should change must less often than other resources.

Issue #905

Change-Id: Id5a6a64bc997d2ac255222643973bfee2ec0e4ec
2017-10-02 11:19:10 -07:00
Joey Parrish 802a674c13 [PWA] Add a service worker
This adds a service worker, which will cache application resources to
make the application itself available offline in browsers which
support service workers.

Issue #876

Change-Id: I13096b2d4b9236d2a3f220af6b1dfce43d7a0004
2017-10-02 11:19:10 -07:00