Skip to content

Commit

Permalink
Made demo properly re-connect to cast sessions.
Browse files Browse the repository at this point in the history
Note that this does not fully fix the problem; issue shaka-project#1948 means
that if the ui is configured more than once, we cannot cast at all.
Also, the cast receiver does not currently work; once a v2.5.1 version
is released that will no longer be an issue, but the v2.5.0 version
currently uploaded is missing goog.require calls.
I have manually verified that once those issues are fixed, though,
this will allow for the player to re-connect.

Issue shaka-project#1948

Change-Id: I26201cc696a61906fac3c320f9ac5e4b61fe1920
  • Loading branch information
theodab committed May 16, 2019
1 parent 35a3b8e commit 7aae7ed
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class ShakaDemoMain {
this.fullyLoaded_ = true;
this.remakeHash();

if (asset) {
if (asset && !this.selectedAsset) {
// If an asset has begun loading in the meantime (for example, due to
// re-joining an existing cast session), don't play this.
this.loadAsset(asset);
}
}
Expand Down Expand Up @@ -858,20 +860,31 @@ class ShakaDemoMain {
this.remakeHash();
}

/**
* Performs all visual operations that should be performed when a new asset
* begins playing. The video bar is un-hidden, the screen is scrolled, and so
* on.
*
* @private
*/
showPlayer_() {
const videoBar = document.getElementById('video-bar');
this.showNode_(videoBar);
this.closeError_();
this.video_.poster = ShakaDemoMain.mainPoster_;

// Scroll to the top of the page, so that if the page is scrolled down,
// the user won't need to manually scroll up to see the video.
videoBar.scrollIntoView({behavior: 'smooth', block: 'start'});
}

/**
* @param {ShakaDemoAssetInfo} asset
*/
async loadAsset(asset) {
try {
this.selectedAsset = asset;
const videoBar = document.getElementById('video-bar');
this.showNode_(videoBar);
this.closeError_();
this.video_.poster = ShakaDemoMain.mainPoster_;

// Scroll to the top of the page, so that if the page is scrolled down,
// the user won't need to manually scroll up to see the video.
videoBar.scrollIntoView({behavior: 'smooth', block: 'start'});
this.showPlayer_();

// The currently-selected asset changed, so update asset cards.
this.dispatchEventWithName_('shaka-main-selected-asset-changed');
Expand Down Expand Up @@ -1235,7 +1248,13 @@ class ShakaDemoMain {
* @private
*/
onCastStatusChange_(connected) {
// TODO: Handle.
if (connected && !this.selectedAsset) {
// You joined an existing session.
// The exact asset playing is unknown. Just have a selectedAsset, to show
// that this is playing something.
this.selectedAsset = ShakaDemoAssetInfo.makeBlankAsset();
this.showPlayer_();
}
}
}

Expand Down

0 comments on commit 7aae7ed

Please sign in to comment.