Commit Graph

37 Commits

Author SHA1 Message Date
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 2f6ed0eb77 Recover from timed-out Cast connection
When a mobile device goes idle, the Cast connection can be terminated
without explicitly closing it.  When this happens, the Cast session is
unusable and throws exceptions.

This changes CastSender to correctly detect and recover from such a
problem by disconnecting explicitly and dispatching an Error to the
application.

This also fixes the disconnection process so that playback can be
correctly resumed on the local device.

Closes #2446

Change-Id: I59f51a1e911199eee22693e7db4ab39855de0298
2020-04-13 18:30:43 +00:00
Theodore Abshire 8e69a011fa Fix bug with changing cast app id to empty string
If that method was called with an app id that was an empty
string, it would destroy the cast receiver, and then not make a
new one.
This lead to the ChromeCast callbacks all pointing to a destroyed
cast sender, which would then spew out errors whenever session
availability changed.
Normally, changing the app id to empty string doesn't make sense,
but it can happen if someone configures the UI thoughtlessly.
This changes the API callbacks provided to be static, and only
forward the calls to live senders.

Change-Id: I88593532791b3448be3ebdf7ef4df4d38c1bc6e4
2020-02-13 20:40:55 +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
Sandra Lokshina 5aefcc7fc1 Clear up the fix for enabling Chromecast.
Change-Id: Ib39f1d7a73890e5174724f05cb0d2ba465a470e6
2019-07-17 19:58:20 +00:00
Jacob Trimble e2fa4626b5 Decrease time it takes to run tests.
- Reduce times for "short delays".
- Remove backoff delay from networking tests.
- Avoid hard-coding delays in the library.
- Move Storage tests to integration tests since they use indexedDB (and
  take over 200ms each to run).

This reduces the time it takes to run unit tests (with --quick) from
50 seconds to about 6 seconds.  Now all but one unit test finish <100ms.

Change-Id: I88461472a87c4cf750a36d07d07422818e069a4d
2019-06-12 20:53:08 +00:00
Joey Parrish 8569b1a2c7 Fix CastSender test flake
"CastSender init installs a callback if the cast API is not available"
would fail sometimes with an upgrade to Jasmine 3 (5/500 times).  The
failure had to do with the use of a global initialization callback.
It is not clear why upgrading Jasmine caused this issue to become more
apparent.

The test expected that the callback would not exist until an instance
had been created.  However, the callback, being global, might still be
around from another instance.  The callback would only be removed
after a successful initialization, so if an instance were created by
another test suite (such as the UI), and destroyed before being
initialized (a normal thing in a test environment with no cast API),
then the global callback would still exist when the CastSender tests
were run.

The best solution seems to be:
 - Decouple the global callback from any particular instance of
   CastSender, and use it to initialize any living instances of
   CastSender when invoked
 - Remove expectations on the prior existence of the global callback
   when the test begins
 - Don't rely on the global callback in the unit tests, since
   integration tests at the top level can overwrite the global
   callback when they load the compiled build

After the fix, the test passed in 500/500 complete test runs.

Change-Id: Id5f5775cf0860d5dfbd6aeb87fa11fd2f2a1297e
2019-06-03 16:53:36 +00:00
Jacob Trimble 43e798870f Misc ES6 conversions.
Issue #1157

Change-Id: Ia25a6cae84575f003980e9694b2769f2976e1342
2019-06-03 15:31:57 +00:00
Michelle Zhuo 7dc95710f0 Update CastSender and CastUtils to ES6
Issue #1157

Change-Id: I6d72a7cb5c8b1e4cb783d53a5465b8e4bb1b7063
2019-05-31 17:30:31 +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
Jacob Trimble 0dd64074b9 Only allow one statement per line.
With the new style rule, we cannot have two statements on the same line.
So we can no longer have an "if" on a single line and we cannot have
an arrow function with a body on the same line as when it is used.
This is mostly a manual change.

Change-Id: I2285202dd5ecbad764308bc725e6d317ff2ee7f0
2019-05-13 22:11:50 +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
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
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
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
Theodore Abshire 5ae80cc67d Typo fixes and rewording in comments, part 4
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: I5904ec91b96417a9ac5e19cb4f7b07a084f26ac8
2018-03-21 17:25:03 +00:00
Theodore Abshire dc17969822 Typo fixes and rewording in comments, part 1
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: I048b430e4c0bea2ccb9aec572d5e9ec6b606a87a
2018-03-14 17:59:26 +00: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 61fc107be3 Convert 'var' to 'let'/'const' (1 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: I8f857a24e4c1ad336177d23dfed4f4a29d3262d2
2018-02-13 13:40:02 -08: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
theodab 8ed316d3c2 Reduced frequency of some getters on cast updates
Not all values need to be updated twice a second. This change modifies
the list of player getters so that each value also includes an update
frequency, and only updates that property once in that many updates.
This acts as a configurable way to ensure that some properties update
in different amounts, without having to have multiple update timers or
compose multiple update messages in the same timeframe.

Change-Id: I90e75e3e73f6c633d91b1799307ec2b15587327b
2017-12-14 21:02:48 +00:00
theodab e63b4abd3b Store and re-use session_ in CastSender.
The cast sender API doesn't seem to be able to re-use an existing session
unless you reload the page. This stores the old session, so that it can be
re-used without reloading the page.

In order to enable this, CastProxy.destroy no longer leaves the current session;
I figure if you want to leave the session, you'll call forceDisconnect.
That part I am not fully sure about; perhaps it would be better to have a
separate optional argument about whether or not to leave, or make it a part of
the forceDisconnect argument.

Issue #768

Change-Id: Ie648372cea4b106ff85df3d0dcc563fca5d10d8c
2017-10-05 16:53:49 +00:00
theodab 84bfdd3a5d Remove listeners before destroying CastSender.
Beforehand, calling chrome.cast.session_.destroy() would typically cause an
error, as the message or update listener was called after the the CastSender
was destroyed.
This removes those listeners before destroying.

Issue #768

Change-Id: I7889adce7b829c3f24dac7a178c9be26e2fdc887
2017-10-02 19:46:13 +00:00
theodab f42edbe966 Changed hasReceivers_ into a class variable.
If you call chrome.cast.initialize a second time, it does not error but it
also does not fire off receiverStatusChanged in order to signal the
initial receiver status. This can result in problems if the CastProxy is
destroyed and then re-created; specifically, it will erroneously claim to be
unable to cast until the receiver status next changes.

This makes hasReceivers_ into a class variable, so that a new sender will use
the hasReceivers_ of previous ones.

The original bug report was kind of confusing, so I cannot say for sure if
this actually solves their problem or not. Hopefully it does.

Issue #768

Change-Id: I7839ed99a8c48c69567bbcaeb1f9b6728265d63b
2017-08-30 23:20:16 +00:00
theodab 95d2855b8f Fixed a problem with live-only getters on cast
Beforehand, the Chromecast would poll getPlayheadTimeAsDate and
getPresentationStartTimeAsDate for every update message, which are live-only
getters, even on VOD.
This would cause a lot of error messages in the debug output of the receiver;
we didn't notice this before because we mostly run the receiver in compiled
mode.
This also allowed users to poll those attributes for VODs without any error
messages when casting, since the results of the last update were cached.

This change adds a list of getters that require live; such getters are not added
to state update messages, and are set up with asserts in the sender.
This should solve the problem and slim down our update messages a bit at the
same time.

Change-Id: Ifc0b445def2d85b22fcb9af160dec2205d1faace
2017-08-28 17:57:58 +00:00
theodab 1a68b2b72f Show pause icon if casting to playing ChromeCast
Previously, if you connected to a ChromeCast that is currently playing, the
local interface would continue to show play icons as though the video was
paused.
This makes it so that the cast proxy sends out synthetic play or pause events
after the first state update after joining an existing session.

Change-Id: I1eb4c23f7b58225d361d353aacf0743def2f576c
2017-08-25 04:40:51 +00:00
Sandra Lokshina 843f020008 Chromecast: add support for Media Playback messages.
Media Playback messages are used by generic Chromecast controllers
(Google Home app and the likes). Supporting them is required by
the Chromecast SDK.

Closes #722.

Change-Id: I3c98fb9d63da81b59c2cc82a3e790332fc9bb56e
2017-04-11 19:00:54 +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 894c56d3c9 Remove suppression of "unnecessaryCasts"
This no longer seems to be needed.

Change-Id: I8f9ed03f97b235d4652930745d4416f6c8f77445
2016-11-04 19:40:55 +00:00
Joey Parrish 5c4c8f4c1f Offer an API to force disconnect Chromecast
Closes #523

Change-Id: I2a213855479dc23797468757808c05a368d907c6
2016-10-18 18:37:06 +00:00
Sandra Lokshina b335c5a9e3 Delegate disconnecting from chromecast to Chrome.
Show 'stop casting' dialog on chromecast control click when casting.
If user chooses to stop, delegate disconnecting to Chrome.

Related to #261

Change-Id: I3072a3723e0d0d526039946fb45713e20349e54c
2016-09-02 21:00:22 +00:00
Sandra Lokshina 359d2c7299 Add support for casting from the cast button built into Chrome.
Closes #261

Change-Id: I1eb8d673d202d913444746f5adc079fede2f605a
2016-09-01 22:11:56 +00:00
Andy Hochhaus 6a00ee8a31 Add missing goog.require 2016-07-23 14:42:38 -07:00
Joey Parrish 2dbadb15cc Show Cast receiver device name
Issue #261

Change-Id: Ia91178810c5ad4d353b9c96e396fda2ba4bfcff2
2016-07-06 20:57:43 +00:00
Joey Parrish 0c8f74493c v2 Chromecast support
This introduces Chromecast support directly in the v2 library, as well
as in the demo app.

See the included design doc for details.

Issue #261

Change-Id: I26a707e7fa6bd829c3ebc70e4c9345ec25eed000
2016-07-06 11:47:04 -07:00