Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update public Player API to improve usability #53

Merged
merged 3 commits into from
Feb 9, 2023
Merged

Conversation

dhleong
Copy link
Owner

@dhleong dhleong commented Feb 9, 2023

In particular:

  • All calls to PlayerBuilder.build() now return distinct Player instances; previously, the array of apps/devices were shared across all instances created by a single PlayerBuilder. This is unexpected and bizarre behavior that no longer occurs.
  • The Player type is now properly exported for use in client code
  • PlayerBuilder.buildQueryOnly() can be used to ignore the requirement that Player instances must have at least one target Device attached, for when you don't care about playback.
  • Player.buildUpon() and PlayerBuilder.clone() methods can be used to simplify factory use cases, where eg configured apps will be shared across Player instances, but the target devices will change per request.

`buildQueryOnly()` lets us construct Player instances that we intend to
use only for query purposes without having to provide a bogus
ChromecastDevice just to satisfy the requirements to `build()`. The
return type of this new method reflects that it does not have the
ability to `play()` anything.

In addition, we now provide `Player.buildUpon` to construct a new
`PlayerBuilder` with the same starting params as the Player,
facilitating a factory-like approach where you eg: reuse configured apps
then `buildUpon().addDevice(...).build()` to play on a specified device
per-request.
Calling `Builder.build()` twice should yield equivalent but unconnected
Player instances—in other words, we should be able to call `build()`,
subsequently `addDevice`, then `build()` again, and the two created
Player instances should *not* have the same set of devices configured.
@dhleong dhleong merged commit 3c207bf into main Feb 9, 2023
@dhleong dhleong deleted the modernize-player-api branch February 9, 2023 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant