Skip to content

Commit

Permalink
silvermine#60: Add handle chromecast also from native
Browse files Browse the repository at this point in the history
Untill now, we only listed for changes in connected
state if menu was launched by user.
  • Loading branch information
yringler committed Mar 13, 2020
1 parent 7354c5d commit 8c4a959
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/js/chromecast/ChromecastSessionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ ChromecastSessionManager = Class.extend(/** @lends ChromecastSessionManager.prot
if (event.sessionState === cast.framework.SessionState.SESSION_ENDED) {
this.player.trigger('chromecastDisconnected');
this._reloadTech();
} else if (event.sessionState === cast.framework.SessionState.SESSION_STARTED) {
hasConnected = true;
this.player.trigger('chromecastConnected');
this._reloadTech();
}
},

Expand Down Expand Up @@ -135,27 +139,22 @@ ChromecastSessionManager = Class.extend(/** @lends ChromecastSessionManager.prot
* Video.js player does not have a source.
*/
openCastMenu: function() {
var onSessionSuccess;

if (!this.player.currentSource()) {
// Do not cast if there is no media item loaded in the player
return;
}
onSessionSuccess = function() {
hasConnected = true;
this.player.trigger('chromecastConnected');
this._reloadTech();
}.bind(this);

// It is the `requestSession` function call that actually causes the cast menu to
// open.
// The first parameter is the success handler. Success is now handled in
// _onSessionStateChange, so here is a noop.
// The second parameter to `.then` is an error handler. We use _.noop here
// because we handle errors in the ChromecastTech class and we do not want an
// error to bubble up to the console. This error handler is also triggered when
// the user closes out of the chromecast selector pop-up without choosing a
// casting destination.
this.getCastContext().requestSession()
.then(onSessionSuccess, _.noop);
.then(_.noop, _.noop);
},

/**
Expand Down

0 comments on commit 8c4a959

Please sign in to comment.