Commit Graph

77 Commits

Author SHA1 Message Date
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
theodab b4ca4bf51c Adds an HTTP/s scheme plugin using Fetch
This plugin is preferred over the XHR plugin, if available.
This plugin requires AbortController, which is only present on
Firefox 57 and Edge 16, so this will not be active on every platform.

This also adds a simple mock for the Fetch API for use with Jasmine.

Closes #829

Change-Id: Ifb79d29334fbfcfd175afe0706da5a3d5e452e2f
2018-02-08 23:11:53 +00:00
theodab abeb0ead7f Make net engine returns error when out of retries
When changing networking engine to use AbortableOperation, we had an
accidental regression. Now, when it runs out of retries, it rejects
with an error of "undefined" instead of with the actual error that was
causing it to retry.
This changes networking engine to save the last error and return with
that. It also modifies the unit tests to catch this problem.

Closes #1278

Change-Id: I8af9a81d7a8ad58d195a8e9f1af622ddbc3592f2
2018-02-07 17:52:05 +00:00
Joey Parrish d26cb21583 Add OperationManager to simplify abortable cleanup
Issue #829

Change-Id: I07f29274227af8bd9abc8e907784557ed85c4552
2018-01-29 19:23:47 +00:00
Joey Parrish 2f55d2a3bd Use AbortableOperation in networking
This uses AbortableOperation in all networking, from the scheme
plugins all the way to the request interface.

This also updates all default scheme plugins, docs, and sample code.

Backward compatibility is provided for scheme plugins and the
request API in NetworkingEngine.  This compatibility will be
removed in v2.5.

Two cancelation-related tests have been disabled in
player_integration until the new abort interface has been adopted
in the manifest parsers.

Issue #829

Change-Id: I91c8e6efe97798d111e8ddca5655cddc1f6bcbf3
2018-01-29 19:23:47 +00:00
Aaron Vaage 4fdf60494a Change Comment Wording in Network Engine
Changed the wording of a comment in network engine so that it is
easier to read.

Change-Id: I17b7051aa5d70356398b16ce84e94fded051e623
2018-01-25 22:10:03 +00:00
Joey Parrish 374653abba [ES6] Use babel to preprocess tests
Once we start moving to ES6, uncompiled mode stops working on non-ES6
browsers (IE11 is the only one we test on).  We can disable uncompiled
mode in the demo, but we still want our tests to be uncompiled.  With
uncompiled library & tests, we can test units that are not exported
and even access private members that would otherwise be renamed.

For production/demo, Babel plays no role.  The Closure Compiler will
take in ES6 and spit out ES3 syntax (even older than ES5, so we can
at least run & fail a support check).

Babel will be used by Karma to preprocess all test and library code
before serving it from Karma.  This will allow us to use ES6 in both
the library and the tests, and still run uncompiled tests and test the
uncompiled library on ES5 browsers such as IE 11.

Issue #1157

Change-Id: Idd185d0e231d16b6df52babda777111e85890012
2018-01-05 20:10:42 +00:00
Michelle Zhuo d221339326 Remove empty lines in response header
Since IE/Edge returns the header with a leading new line('\n'), we need
to remove it from the response.

Closes #1172.

Change-Id: I133f9cfbada6486edc438f3dcbc37c7c78dbf36c
2017-12-12 18:03:01 +00:00
Theodore Abshire 7d23729c78 Add ability to cancel backoff early.
This adds the ability to supply an isCanceled() callback when making a
backoff object. If the callback is provided, the backoff will break the
timeout into a series of 200 MS timeouts, and check isCanceled() between
every segment.

This changes makes it so that, when canceling a load, you can quickly end
the current backoff. This will making canceling a load significantly faster,
especially if the player is on a late retry.

This still does not quite fix issue #1084 to my satisfaction; if the
manifest is currently downloading, the cancel will need to wait on that.
Canceling an in-progress manifest download will be yet another followup CL.

Issue #1084

Change-Id: I0a53310a9b521de375f2e128f63eaa133547c340
2017-11-06 13:57:58 -08:00
Theodore Abshire cbdf76d6aa Skip manifest load retries when destroying player
If the parser is failing to load a manifest, perhaps due to being offline,
and the player is destroyed mid-load, it will wait for all of the retries to
run out before canceling. This causes a significant wait time on destroy.
This change adds an optional isCanceled callback to the request method in
NetworkingEngine, allowing requests to be made that can be canceled via a
provided callback. This is then used to quickly skip past all of the
retries, when destroying the parser.

This doesn't stop any backoff in progress, so there still might be a delay of
a second or two (depending on networking settings, of course) if you destroy
during a backoff period. That will be changed in a followup CL.

Issue #1084

Change-Id: I0b99616ed4d5be078161122532ea271e84613170
2017-11-06 18:42:33 +00:00
theodab fefe93480d Allowed multiple plugins for one scheme
This modified the networking engine to store every plugin it is given
for a scheme, and adds a priority system to pick which of the plugins
to use.

Issue #829

Change-Id: I21a8a534383f2be898160d609d77efecfc2b684b
2017-11-03 22:38:55 +00:00
Tim Plummer 50a12d7afe Fix for 'unknown this' closure type error
Change-Id: I5f7040049cd985ffc809e363f0f0227bc32c95ec
2017-10-20 11:56:35 -07:00
Jacob Trimble 6069e76c4e Disallow ArrayBuffer.slice.
ArrayBuffer.slice isn't supported with two arguments on Tizen 2016.
This is a temporary fix that can be cherry-picked to v2.2.  A better
fix will be handled in a follow-up change.

Issue #1022

Change-Id: Iae6a0b2ef0cf17843f42f22f0ea0962a56e8be68
2017-09-25 17:28:19 +00:00
Joey Parrish 65166cf609 Delay and backoff streaming failure callback
Instead of calling the failure callback right away, use the delay and
backoff algorithm first.  This way, applications do not need to
implement their own delay, and should behave more responsibly toward
servers in case of failures.

Closes #976

Change-Id: Id896365a5ed0ffdd288ef1f59e8637d1e4e55b5b
2017-08-22 21:20:01 +00:00
Joey Parrish 9f43c15d80 Factor out backoff code in NetworkingEngine
This extracts the delay, backoff, and fuzzing code from
NetworkingEngine in a way that can be used by other classes that need
this same backoff/retry behavior.

Issue #976

Change-Id: I2a370fc996e6f8f507768559c44cf7855e16abe1
2017-08-22 21:19:00 +00:00
Jacob Trimble b5cbc01088 Don't retry for 401/403 HTTP codes.
Closes #620

Change-Id: I1df99cca6bb6a704b6ff055399298914d6e91e8f
2017-04-05 21:35:24 +00:00
Jacob Trimble f5cabead8e Don't retry network requests on CRITICAL errors.
Issue #620

Change-Id: I6b659acdccf5d893022f3474b45020482f543550
2017-04-05 19:51:13 +00:00
Jacob Trimble 575f2ad109 Add an indicator for critical errors.
This adds a severity field to Error objects.  This can be used to
detect whether an error is recoverable.  All the same errors are still
reported so the field can be ignored.

There are two possible values:
* RECOVERABLE means that the Player will try to recover from the error
* CRITICAL means the Player will be unable to continue and must call
  load() again

Closes #564

Change-Id: Ie2c5468340c13e7a288b99690ab65b7ecc0a6b29
2017-04-04 23:57:59 +00:00
Joey Parrish 0243671383 Expose data uri parsing to the HLS parser
Widevine HLS manifests have a data URI that needs to be parsed to
generate DrmInfo.  Rather than write another parser, factor the data
URI networking plugin to expose the parser to other classes.

Issue #279

Change-Id: I71f174b86cc3b0ae0e8dbc31701ea9d36cd157ee
2017-03-30 22:40:26 +00:00
Jacob Trimble 2356e5517a Clone request fields in NetworkingEngine.
Change-Id: I00275b9a857fc0c4b78b52a7c6e3c58035237127
2017-03-09 19:17:55 +00:00
Jacob Trimble 40bd34d8ac Add support for special cache header.
This allows network responses to have an X-Shaka-From-Cache header to
indicate that the response was somehow from a cache and should be
ignored for bandwidth calculations.  For example, this can be from a
service worker intercepting the request.

Change-Id: I4dfdf4211921b7205febb58f1e80967f0c4841cd
2017-03-03 19:53:17 +00:00
Chad Assareh 97cca1887b Return HTTP headers as part of the BAD_HTTP_STATUS error object.
Change-Id: I6b5a22b26fba8ace40f9cff00146e22b51c10041
2017-03-02 13:58:06 -08:00
Jacob Trimble 6f7d937d2f Add Response flag to ignore cache hits.
This adds a field to the network response that will indicate that the
response was from a cache and should be ignored for bandwidth
estimation.

Change-Id: I6b02e9d4fb3be02731bdf0a2a46bc5ce5f11e302
2017-02-16 21:17:25 +00:00
Joey Parrish fd1786b7a9 Add asynchronous filter example in the tutorials
This adds an example of using asynchronous filters for authentication.

Closes #610

Change-Id: Idf47558af4c399178ff3806f944d69909ee2fd7a
2017-02-07 16:18:27 -08:00
Joey Parrish 836bd9a177 Make filters, requests, and responses easier
By exporting StringUtils and Uint8ArrayUtils, we can simplify the
process of wrapping, unwrapping, and parsing requests and responses
in NetworkingEngine filters.

This makes it easier to write filters that deal with text-based
data, as it is no longer the job of the application developer to
deal with subtle conversions between string and ArrayBuffer.

We will also fill in requests with defaults if needed.  This allows
developers to omit fields when initiating extra requests at the
application level.

Closes #667

Change-Id: Ie6a0f23b4d46e7e458d996759eac6cd85a36b741
2017-02-08 00:09:08 +00:00
Joey Parrish 6cfd337680 Remove unnecessary triple-equals usage
Change-Id: Ibfd76f8b36926e41e9bf2fd26b5bea16d3bd8f2a
2017-02-06 22:20:09 +00:00
Theodore Abshire 8b2212c65d Enabled asynchronous response filters.
Also updated externs.

Issue #610

Change-Id: I4c9539442d6fb77781296ea1acf123b3653e3b40
2017-01-09 17:34:22 +00:00
Theodore Abshire 07c564b4a2 The http plugin now fails on 202 status codes.
Closes #645

Change-Id: Ie20d1de1e8eff30d7656886e2b85d0e39079774a
2017-01-06 21:37:59 +00:00
Theodore Abshire 07ce75273e Allowed network plugins to see the request type.
Closes #602
Change-Id: Ib86389956c4908d94184abe8775d497b09a5f90e
2017-01-06 21:23:09 +00:00
Theodore Abshire 9153f68ab3 Fixed a bug with removing pending requests.
In some cases, the networking engine could have attempted to
remove a pending request that did not exist, thus removing other
requests.

Change-Id: I08fb9c11c3dd153af7a148fcb591fe5c0c3634a1
2017-01-06 18:59:59 +00:00
Theodore Abshire abca628239 Added support for asynchronous request filters.
Closes #610
Change-Id: I10d407d6c858f6541e869b834877a2ebbc516694
2017-01-05 15:49:49 -08:00
Jacob Trimble b1711c346d Allow passing durations from scheme plugins.
This allows the networking plugins to pass the duration it took for
the request.  For example, if a plugin were pre-fetching the segment,
this allows the plugin to tell NetworkingEngine about how long it
really took to download.

Closes #621

Change-Id: Ie67e3f99389cf02d5b4a345bde06ccc418b6e91c
2016-12-20 20:17:43 +00:00
Joey Parrish d6616a0ca4 Fix quarantined NetworkingEngine tests
The test flake was caused by a leaked instance of Playhead interfering
with NetworkingEngine unit tests.  The quickest way to reproduce a
failure on the networking tests was to focus the unit tests for
Playhead and NetworkingEngine and run the suite on IE11.

Playhead tests tear down the Playhead object after each test.
However, one test created two Playheads, effectively leaking one.
That leaked Playhead would continue to poll the fake video element
after the test was complete.  Polling used setTimeout.

The NetworkingEngine unit tests would mock setTimeout and show that
the engine was calling it appropriately.  However, the leaked Playhead
would also call setTimeout during the NetworkingEngine test, which
would cause an expectation on the number of calls to fail.

The Playhead tests should clean up after themselves, but the
NetworkingEngine tests should not have to mock global setTimeout in
the first place.  This change not only fixes the Playhead tests, but
isolates NetworkingEngine's use of setTimeout to a private method
which can be mocked without affecting global state.

Change-Id: I94dd7f6c39c25f81c7e4122895ab5fae0feef2cb
2016-11-23 12:05:49 -08:00
Joey Parrish 18da8e04dc Export all plugins
This exports all plugins from the library, to make delegating and
subclassing easier for applications.

This also fixes a couple of issues with the generated documentation.

Closes #551

Change-Id: I23798f6117e1944d7ffc67bcb50ae36f3943710a
2016-11-14 23:58:09 +00:00
Joey Parrish 1d2929ab00 Add extra exports for the sake of generated externs
An upcoming compiler release will allow us to generate externs from
exports.  Because of that, we are adding some extra exports which are
otherwise not needed at runtime.

 - Export properties which implement an interface
 - Export classes which are referenced in external APIs
 - Export base classes of other exported classes

Change-Id: I78b3a4569b4b82b0a9d8993978faf268c2a791d9
2016-11-04 17:12:16 +00:00
Joey Parrish 5b6780bf39 Move filter and scheme plugin types to shakaExtern
If an external project wants to reference the filter or scheme plugin
typedefs, these should be in shakaExtern.

Change-Id: I7bf70d2efbf741c8b07a7b8502b3f52eff49dd9d
2016-11-04 17:12:16 +00:00
Lucas Gabriel Sánchez 403a141f2c Use data URI content-type for manifest type detection (#550)
* Fix when using Data URIs for the manifest
* update test/net/data_uri_plugin_unit.js to test Data URIs content-type header response
2016-10-19 09:50:07 -07:00
Andy Hochhaus 87a62d717e Add missing goog.require() dependencies 2016-06-25 15:45:15 -07:00
Timothy Drews ea94157f5c Set default request retry to 2.
Issue #390

Change-Id: I1458892f4317176f5aaac9665b6bedfd672a9a12
2016-06-23 16:36:09 +00:00
Joey Parrish c29fdf401b Shaka v2 Upgrade Guide
Also fixes docs export on some of our external structures.

Change-Id: Ia31f2ad46c6f07845c289c6ca2f206a6fd6cf341
2016-04-13 21:15:40 +00:00
Joey Parrish cb64d7646d Add response text to HTTP errors
Requested in #319

Change-Id: I2f52519d7a45769a0d2db3c038c9c04cf7fb59c1
2016-04-12 21:59:03 +00:00
Joey Parrish e70461221f Fix jsdoc output of non-constructor plugins
jsdoc was getting confused and generating, for example, a file called
"shaka.media.html#VttTextParser".  Moving the @namespace annotation to
the method itself fixes it.

Change-Id: If26cac698b19d1305c270e519b7ed50ed81492fe
2016-04-06 16:52:06 +00:00