Commit Graph

118 Commits

Author SHA1 Message Date
Jacob Trimble 011749e95f Standardize argument comments.
This changes the eslint rule to enforce a strict pattern for the
argument comments.  The comment must appear before the argument and
must be /* foo= */.  This still ignores line comments.

Change-Id: I3afb01c65e1088eda13facb3aeeaa7595a2f5aee
2020-01-06 19:40:52 +00: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 79e2e68853 Fix export of fetch plugin
Without this, custom scheme plugins can't delegate to this standard
one.

Issue #2205
Issue #2213

Change-Id: I13e9762e75ba9afe9fd7f804404ffb1d2e684435
2019-10-23 20:23:26 +00:00
Joey Parrish 9e92167910 Treat URL schemes as case-insensitive
According to RFC 3986, URL schemes should be case-insensitive.  Our
scheme plugin map is registered with exclusively-lowercase scheme
names, so we should convert the input scheme to lowercase before
looking up the plugin.

Closes #2173

Change-Id: I78218c18d3df154aabd101a9ef5fd3156d0c57a8
2019-10-04 10:32:58 -07:00
Theodore Abshire a84fd65d9e Added "report bug" button to demo.
Change-Id: I27e25f8b88effc596e2f836ec263f9ae9d2b5fc0
2019-09-04 22:51:03 +00:00
Jacob Trimble a2bcf7278d Move some utilities to BufferUtils.
Change-Id: Ifb3c4348cc912640b99ff53f7cac59a63480c68e
2019-08-20 22:07:35 +00:00
Jacob Trimble 596c80a949 Refactor handling of ArrayBuffer.
This changes the network API to use BufferSource instead of ArrayBuffer,
which allows plugins to return a "view" on a buffer instead of the
whole buffer.  This also adds some utilities for changing between
views and buffers.

Lastly this forbids the use of the "buffer" property of TypedArrays
since it doesn't work with partial "views".  This audits and fixes the
usages of the "buffer" property to ensure correct usage.

It should be noted that both MSE and EME accept a BufferSource as input,
so we don't need to convert a "view" into an ArrayBuffer before passing
to it.

Change-Id: Iaa417773f8ce5304424e43c7372ce10ebf540d2a
2019-08-20 20:17:33 +00:00
Jacob Trimble b12075093e Add sessionId field to network request.
This allows a request/response filter to determine which EME session
made the request.  This also changes the session ID of FairPlay sessions
so they are available too.

Issue #1951

Change-Id: I1a07abae6faf4a87fad7b5d4290a00b25e83da8e
2019-08-05 16:52:11 +00:00
Chris Fillmore d846e58af6 Add originalUri as a property on shaka.extern.Response (#1972)
This property tracks the original request uri, which would be
useful to know in the event of a redirect.

Fixes #1971
2019-06-01 13:30:41 -07:00
Joey Parrish 393b0ecea7 Fix HTTP test failures
This makes progress callbacks into a required parameter on all network
scheme plugins.  This does not mean that every plugin must make use of
the callback, but every caller must supply the callback.

In production, NetworkingEngine already supplies this callback
universally, so our HTTP plugins make use of it whenever progress data
is available.

Our tests, however, did not always supply this callback, leading to
test failures.  These failures were more likely to show up in Jasmine
3 than Jasmine 2 for some reason, which caused us to downgrade back to
Jasmine 2 recently.

By making the callback required, we can clean up this inconsistency
between test and production and give the HTTP plugins what they expect
in all cases.

Issue #1949

Change-Id: I8a6e1904e73cf7ca6ae8f3964261c339f404854d
2019-05-22 15:42:06 +00:00
Jacob Trimble 74918b90ec Convert networking files to ES6.
Issue #1157

Change-Id: Iae83b88881b351c97e8ec020625167f5f700f97e
2019-05-20 17:10:06 +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
Theodore Abshire 273698d607 Fix exception on network retry.
The numBytesRemainingObj parameter in |NetworkingEngine.send_| was
optional, but in some circumstances we were assuming that it was set.
This just changes the parameter to be non-optional.
In fact, the parameter now being non-optional revealed an error that
caused the numBytesRemainingObj to be lost on network retry.

Fixes #1930

Change-Id: I74f24309f859f975f51e20455739b806ed3f4ecd
2019-05-09 22:19:56 +00:00
Jacob Trimble ded2b84313 Require consistent return values.
This enables the eslint rule that requires all functions to consistently
either return a value or not return a value.

Change-Id: I98b579f3689c3b6c74968116824231bb792bd9dd
2019-05-09 20:34:47 +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 189902bdb3 Eliminate free calls of static methods
This was caught by a newer compiler release.  These were missed in the
last audit we did before releasing v2.5.0.

Change-Id: I4abd29e965c95b56eb83c61294f8a7dbaacae990
2019-05-08 15:01:02 -07: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
Joey Parrish 33f3c07fba Minor style fix in NetworkingEngine
Change-Id: I18afa94204a2f784203fba74c69e8b4c812596fc
2019-05-07 19:36:40 +00:00
Jacob Trimble cc838ff23f Fix uncaught Promise rejection errors when aborting.
We get an error from ReadableStream when we abort a request.  This
causes uncaught rejection error logs in Chrome.  This ignores the
error and stops the logs.

Change-Id: I0f339e73564ac42b28ea8b7d0bf12ffb8c2ec9cc
2019-05-03 23:02:42 +00:00
Michelle Zhuo 40f9113bb2 Abort requests when network downgrading
When the network becomes slow, we check if stopping the current request
and download the content with lower resolution is faster. If so, abort
the current request and start a new one.

Issue #1051

Change-Id: I588e524469432e362361d1cfbde6cd45c2009959
2019-05-01 20:18:16 +00:00
Aaron Vaage 71fb7a03ec Use Timer/DelayedTick instead of setTimeout
This CL limits the use of |setTimeout| by wrapping it in our own timer
class. The timer class makes it easier to track and cancel time-based
events.

To ensure that|setTimeout| is not used outside of our timer classes, the
conformance rules have been updated to only allow |setTimeout| to be
used by our timer classes.

Since |setTimeout| is very similar to |setInterval|, the conformance
rules for |setInternal| rules were updates to reflect more of the logic
behind why we don't want to use |setTimeout| and |setInterval| directly.

Change-Id: Iff5da32a61b515dd2016837fa74a34c04b6c5fd2
2019-03-12 18:52:32 +00:00
Aaron Vaage 1b90e0f4c1 Integrate Deprecation Tool With Library
This integrates the deprecation tool with our library and updates
all the deprecated warnings to use our new tool.

As some features needed to be removed in 2.5, this change removes them
since their deprecation checks would make us fail.

Change-Id: I28310bbe9df6839719f4763a96026d5968bdcea6
2018-12-12 00:26:50 +00:00
Aaron Vaage 5612a0f855 Use Sets For Filters in Networking Engine
If we use sets for filters in networking engine we get some
pretty good additions:
  1. Someone can't double-register their listener (by accident)
  2. We don't need ArrayUtils to remove listeners.

Change-Id: I5115b9488d43f0bcd64fcc1a11133d5a49ad3d3a
2018-10-22 21:08:34 +00:00
Theodore Abshire 6d57cdb83c Make Fetch plugin require USABLE ReadableStream
On Edge, window.ReadableStream exists, but attempting to call it
results in an error.
This changes the support check for Fetch to try actually creating a
ReadableStream before it OKs using Fetch.

Change-Id: Iab6ea2c459fe536ac51796808cb56c4c54dd4312
2018-09-26 15:43:29 -07:00
Theodore Abshire 809d86d2ee Make Http Fetch plugin require ReadableStream
In a recent CL, the Http Fetch plugin was modified to make use of
ReadableStream. However, ReadableStream isn't available on every
platform. This change modifies the Fetch plugin to not be used if
ReadableStream isn't defined.
This also adds a basic mock ReadableStream for tests.

Change-Id: I7554298779040ce0cef1b8ad55c3ee113f932954
2018-09-26 10:40:59 -07:00
Theodore Abshire cef4ae98b9 Added progress events for Fetch plugin.
Also adds support for the relevant methods to the fetch mocks.

Closes #1504

Change-Id: I1a94148810262ecab675aea7dca7e1a3aaf8800a
2018-09-25 18:28:16 +00:00
Aaron Vaage 8e90b840f7 Remove Use of MapUtils.forEach in shaka.net
Removed the only use of MapUtils.forEach in shaka.net as part of
using Maps over Objects.

Change-Id: Ia3fe98757bb7bfe4a46564db11fa31aeee7cff6a
2018-09-14 21:42:35 +00:00
Michelle Zhuo d6720cc7a6 Add Progress Event Handler for XHR plugin
This is part 1 of conditionally aborting requests when network
downgrading.
1. Add progress event handler for Http XHR Plugin, to get more frequent
updates for network bandwidth estimate and suggest streams based on
that.
2. When the plugin doesn't support progress event, call
onProgressUpdated function after every segment is downloaded.
3. Replace onSegmentDownloaded with onProgressUpdated function in
player.js and network_engine.js.
4. Since XHR Plugin supports progress event while Fetch doesn't, change
the config to prefer XHR over Fetch API.

Issue #1051.

Change-Id: Icf6775dd3520fb2e359b13d29e3b39d3792fe865
2018-09-07 16:10:41 -07:00
Jacob Trimble 66bdd49bb0 Add support for 'individualization-request'.
There is now a separate server URL for 'individualization-request'
messages; if it isn't given, it will fallback to the license server.
There is also a new field in the Request object so a request filter
can act differently based on the message type.

Closes #1565

Change-Id: I970a8651ef05ec533d9fd41841cb52021e3c0489
2018-09-05 22:01:52 +00:00
Joey Parrish e100553fa0 Add missing @private annotations
Issue #1553

Change-Id: I36cb50cbec9ee816a82274ebc83dfae2ba095214
2018-08-21 10:19:24 -07:00
Theodore Abshire d32d951dde Added 'retry' event to networking engine
This makes NetworkingEngine a FakeEventTarget, and gives it a 'retry'
event which is fired when there is a recoverable error that results in
a retry.

Closes #1529

Change-Id: I0c15ed20f4d6abf971d280263c6d62841daf440e
2018-08-15 20:31:02 +00:00
Chris Fillmore 07fa82436f Refactor HttpFetchPlugin to clarify error outcomes (#1532)
Previously, HttpFetchPlugin would treat any non-Shaka error as
HTTP_ERROR when there were potentially other circumstances which
could have produced a non-Shaka error.

This change catches errors from fetch sooner, so that there is no
need to do a fuzzy check for error.severity. It also clears the
request timeout regardless of whether fetch throws or not.

Closes #1519
2018-08-14 11:46:55 -07: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 59eb930aa3 Make XHR header parsing more readable.
Change-Id: Ieb1ef739dcf8e6f6ed7e3fd81e2ac271dc13a2c2
2018-08-02 14:47:45 -07:00
Patrick Cruikshank e312c3a40b Add new request type TIMING for clock sync requests (#1489)
Fixes #1488
2018-07-16 09:38:52 -07: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
Jacob Trimble 759eef9685 Change goo.gl links to bit.ly.
https://goo.gl is being turned-down, so we can't use it for new URLS.
So we have consistent short links, this converts them to be
https://bit.ly.

Change-Id: I07a86cba807b67157664893341f648023918d0de
2018-06-22 20:20:00 +00:00
Michelle Zhuo 535de4db84 Refactor: Remove underscore from parameter names
Change-Id: Ie9e6fb59763f454f245175f23c6444f919ba8135
2018-05-08 19:21:51 +00:00
Aaron Vaage bf0d107630 Add Missing "."
Add missing "." after "Array", "Object", and "Promise".

Change-Id: I86f6bd6ea38ce6531b71d22923622ccda07fc6aa
2018-04-11 21:36:44 +00:00
Sandra Lokshina 8065bd54a8 Change namespace from shakaExterns to shaka.externs
Change-Id: I16432351e2a266aa8fd175669aa27c44bfdffeae
2018-04-11 17:26:26 +00:00
Joey Parrish 18b171f5ee Add missing quotes on exported enum
Change-Id: I61a92a389ed0d79e5de8db19f461596f269f1502
2018-04-03 14:58:16 -07:00
Theodore Abshire f58afd21da Typo fixes and rewording in comments, part 5
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: Ibcaf21382bd78b91e589122983dd14e001bfdad5
2018-03-21 17:25:13 +00:00
Joey Parrish f48f7fd9c4 Clean up uncaught Promise rejections
- Translate uncaught Promise rejections into test failures
   (Chrome only until the event is more widely implemented)

 - Clean up uncaught Promise rejection caused by exceptions thrown
   after destroy() in:
   - CastProxy
   - CastReceiver
   - NetworkingEngine
   - StreamingEngine

 - Clean up uncaught Promise rejection caused by test cases in:
   - CancelableChain unit tests
   - DrmEngine unit tests
   - StreamingEngine unit and integration tests
   - Player unit and integration tests

 - Speed up rejection in NetworkingEngine when we should not retry

 - Add --delay-tests to test.py, to aid in debugging uncaught
   Promise rejections and other types of async test pollution

Closes #1323

Change-Id: I5a8f5702a22430929babeb071bf6650c52c5ad17
2018-02-28 22:56:12 +00:00
Chris Fillmore 40e7524ed9 Catch BAD_HTTP_STATUS error thrown by makeResponse in xhr.onload (#1303)
Catch BAD_HTTP_STATUS error thrown by makeResponse in xhr.onload

Also wrap mock XHR event handlers in try-catch blocks in
http_plugin_unit to avoid regression.

Resolves #1302
2018-02-27 13:14:44 -08: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 0154dbc4d4 Convert 'var' to 'let'/'const' (6 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: I475eba0a477d13cd9201c88ad44899d521ad8991
2018-02-20 11:28:02 -08:00
Chris Fillmore 4ac1a40578 Provide RequestType in error data from HttpPlugin. (#1254)
Closes #1253
2018-02-12 10:01:58 -08:00
Chris Fillmore 5ed7b5b212 Move Fetch API support detection into public method. (#1296)
The motivation for this change is to allow the client app to
share Shaka's support detection.

This should enable #1075.
2018-02-12 10:00:54 -08:00
Theodore Abshire 35d8838ed3 Change null body to undefined in Fetch
Fetch requests with a method of GET or HEADER cannot have a body, or
else the request will fail. Normally we had no problems with this, but
it turns out that Edge counts a body of 'null' as being defined.
This changes the Fetch scheme plugin so that it will replace null with
undefined for the body in the init data.

This also makes it so that HTTP_ERROR errors emitted by the http
plugin will include the original error, to aid in debugging future
issues.

Change-Id: I0531656dada25f97ef610d4285c225d57d7ef262
2018-02-09 22:21:27 +00:00