Commit Graph

29 Commits

Author SHA1 Message Date
Joey Parrish 4ae3a080d6 refactor: Add utility to keep unused parameters (#4233)
Many times in our default configuration, we need to create an empty
default implementation of a callback.  The compiler wants to strip
out unused parameters from these functions, but this breaks our
runtime-type-checking for functions in configure().  We need a way to
keep the full function signature in default config callbacks in
compiled mode.

This adds a new utility: ConfigUtils.referenceParametersAndReturn().

It references the input parameters so the compiler doesn't remove them
from the calling function, and returns whatever value is specified.
The utility function is marked with `@noinline`, so the compiler won't
tamper with it.

Default config callbacks that use this utility will still bear the
complete function signature even in compiled mode.

The caller should look something like this:

```js
  const callback = (a, b, c, d) => {
    return referenceParametersAndReturn(
        [a, b, c, d],
        a);  // Can be anything, doesn't need to be one of the parameters
  };
```

See also https://github.com/shaka-project/shaka-player/pull/4231#discussion_r874710385
2022-05-17 11:19:20 -07:00
Jacob Trimble dc8b007d56 cleanup: Add missing requires.
This is a port of the internal changes: cr/321495405, cr/321592702,
and cr/321594488.

Change-Id: If6a4c4266ed10a70b01442974dbd19329bb5122e
2020-07-16 10:59:49 -07:00
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00
Joey Parrish 39eb6cfcbf Always log config errors
This makes the config-rejection logs always-on in compiled mode, to
help application developers notice problems during upgrade.

Found while fixing #2383

Change-Id: I131a1bf8197da394a743e9a121348178d38e5948
2020-02-14 15:13:03 -08:00
Joey Parrish e82b13b311 Fix acceptance of async functions in configuration
The config merging code was rejecting async functions, because the
.constructor field of a function is the "Function" constructor, but
the .constructor field of an async function is the "AsyncFunction"
constructor (not exposed as a global).  This led to the async function
being rejected because it was misdetected as a different type of
"object" than the default value.

The fix is to exclude functions from this constructor-based
type-checking.

Note that the compiler will turn async default values into synchronous
functions in the compiled build, so an async default will appear as a
synchronous function in the compiled build and an async function in
the uncompiled demo.

A synchronous function from the app will always be okay, even if the
library expects async, because "await" will still work.  But if the
library expects a synchronous function, the app should not supply an
async function, because that will return a Promise instead of the
expected type.

This adds a test to show that it is okay to pass a synchronous
function to an async config field, which is important for backward
compatibility as we make trackSelectionCallback async (#2383).
However, because the compiler causes us to lose the native async-ness
of our default values, we can't reject async for sync fields or write
a test for that scenario.

Found while fixing #2383

Change-Id: I62891441ce75bfc887ea13c24212a2ee78f90af4
2020-02-14 15:13:03 -08: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
Theodore Abshire 9af7baac8e Fix minor formatting issue in config utils.
Change-Id: I940cc28bf4a9a8edcf31a8ffaaa77a48e222d8f2
2019-06-06 19:56:03 +00:00
Theodore Abshire f666974f8c Store base configuration in demo.
In some previous change, the drm configuration method was changed to
reset the player's configuration first, to remove any previous asset
drm configuration.
However, this also removed any user-originating configuration.
This changes the demo to store a record of the configuration from the
perspective of the user, and re-applies that instead to "reset" the
configuration.

Closes #1976

Change-Id: Ia1a659bd037cfd347e5bf763d7145e1523fca56a
2019-06-05 20:49:56 +00:00
Sandra Lokshina afa82e2692 Convert array, config and dataViewReader utils to es6.
Issue #1157

Change-Id: I3f57077939f1e8b044dc8af3c826b98e2e1003e1
2019-05-24 20:58:07 +00:00
Jacob Trimble d5780d401b Fix line length issues for indent fix.
Change-Id: I87d75fd88000f8f9bff7b9f1bf5667ba28f6dd60
2019-05-13 22:31:20 +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 ab6f9cfd3d Allow short-form config for UI and offline
With this change, offline and UI config can use the same two-argument
short form that the Player config interface offers.

Change-Id: I5f40ef58da76f3aab1d7178fe7d6e82097352b9a
2019-05-09 19:34:01 +00:00
Jacob Trimble c81389741f Prefer const over let.
A coming update to the Google eslint config will require using "const"
over "let".  This makes that one change to isolate the big changes.

Change-Id: I7d0974c3ae15c53cc45a6b07bf9f6586e2d34aca
2019-05-08 09:22:10 -07: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
Jacob Trimble 6f639ed456 Fix resetConfiguration keeping shared config.
Before, resetConfiguration would break the getSharedConfiguration,
which would break the connection between Storage and Player.

Change-Id: I497bcb390031c815ed006848619d0a055ce8cdde
2018-10-02 13:23:49 -07:00
Joey Parrish 49c7c0c94c Fix advanced DRM settings pollution across key systems
When merging config objects, we accidentally used the same object
reference for multiple key systems.  This caused settings meant for
one to affect another.

The clone util had to be updated to handle Uint8Arrays, which may be
present in DRM configs.

Closes #1524

Change-Id: I66c8dc114573605471b1eeb38e890bbd4d29e2d4
2018-08-29 17:14:37 +00:00
Theodore Abshire f6a1c6e4aa Moved cloneObject to new util file
cloneObject used to be part of config_utils.js.
This meant that a number of classes that didn't actually use
config objects required ConfigUtils.
This moves cloneObject into the new ObjectUtils, to clarify that.

Change-Id: I92d630eba8798b3e2671dcce95b61f44282b05e7
2018-08-07 13:15:06 -07:00
Jacob Trimble a6f360759c Continue configuration merging on errors.
Closes #1470

Change-Id: I402c9370f8a3f3ddc2629daeaf9ffe8ce86d0903
2018-06-21 13:52:44 -07:00
Jacob Trimble 3d877d7ac5 Return false if player configuration is invalid.
If the value passed to |player.configure| has errors in it, the method
will now return false.  This allows the app to programmatically detect
errors in the config object.

Change-Id: I7236f565320e8fd39afcb3224b7901c601d211ba
2018-04-20 11:46:38 -07:00
Jacob Trimble 624acc66b8 Add curly braces to all blocks.
Google style guide requires adding curly braces to all block statements
even if it is only has one line.  This fixes it by using eslint's
--fix flag followed by running clang-format to reformat the change.

Change-Id: Idc086c2aa8c02df5ef8b2140a11bfb9128eeb4bd
2018-02-21 11:23:34 -08:00
Jacob Trimble f70436540c Convert 'var' to 'let'/'const' (3 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: I10f5c38a8b06b5797c6eec7492829084114514c9
2018-02-14 00:47:03 +00:00
Jacob Trimble c52884afed Fix 'var' scoping problems.
A follow-up fix changes all 'var' definitions to 'let'.  This fixes
issues caused by it.  One major change is adding brackets to case
statements.  Each case statement is considered in the same scope, so
defining variables in them actually are the same variable.  By adding
brackes to the cases, each case gets its own scope.

Change-Id: I99b1298223786f4df415594a2e64eb31d72b2053
2018-02-13 21:32:57 +00:00
Jacob Trimble 3d259125c5 Use a custom cloneObject implementation.
Tizen 2016 throws when trying to use JSON to clone cyclic objects.  To
avoid this and to remove a hack to clone objects, this replaces it with
an explicit clone implementation.

Closes #935

Change-Id: Ia057e3f6853b813dd89fe33c291b558b71534726
2017-09-26 20:30:59 +00:00
Joey Parrish e8af210dab Clean up config merging, type check certs
- cleans up config merging now that abr.manager has been removed
   from the config
 - uses thing.constructor == Object instead of
   typeof(thing) == 'object', for better detection of anonymous
   objects
 - adds a default (empty) server certificate for type-checking
 - treats empty certs the same as null (no cert provided)

Fixes #784

Change-Id: Ie833a1b3bf484d5f12f3ebf6d513ed51740bdc44
2017-06-05 03:21:48 +00:00
Joey Parrish f992851925 Don't recurse on serverCertificate in config merge
Treating serverCertificate as an Object and recursing causes an
exception the second time you set the serverCertificate config.

As a quick fix that can be cherry-picked for v2.1.x, do not recurse
on serverCertificate.  This has the side-effect of not type-checking
the serverCertificate field on input.

A more detailed fix will be made later, for inclusion in v2.2.

Issue #784

Change-Id: I84c05ee3dd370a4b83e9ce2337d2326ec36532c2
2017-05-08 23:46:38 +00:00
Jacob Trimble 87c7d5d665 Add framework for events on the media timeline.
This add the groundwork for event regions that occur while playing.
When the playhead enters (or plays through) a specified region it will
fire enter/exit events for it.  They are not fired when seeking over.

Issue #462

Change-Id: I9e280796bd012ad74d0319aa2056c6f6aa28890d
2017-01-20 22:19:33 +00:00
Andy Hochhaus 87a62d717e Add missing goog.require() dependencies 2016-06-25 15:45:15 -07:00
Jacob Trimble 8251fbaa19 Player.configure will ignore function argument count.
Before, Player.configure would check the number of arguments for
the functions being set and reject those with an incorrect count.
However, this does not work with jasmine spies.  So instead allow
it but log a warning.

Change-Id: I0f03ae9a22bf6a6e427c2a26a6f055dcaa40b3ec
2016-05-17 15:28:22 -07:00
Jacob Trimble acfb7c6d41 Moved code out of Player into utility files.
This moves a bunch of code out of Player into different files.  This
is needed to allow the new Storage class to have the same behavior
as Player.  This also reduces the size of player.js.

This moves the following code:
* Determining the manifest parser to use.
* Period filtering.
* Application track restrictions.
* Configuration object merging.
* Choosing initial stream sets.
* Track creation.

Change-Id: I84d68d39b487447d6f8d61a145cd034a88165739
2016-05-04 17:18:15 +00:00