Skip to content

Commit

Permalink
feat(ui): Add ability to build UI without cast (shaka-project#4781)
Browse files Browse the repository at this point in the history
With this, if you build Shaka Player with "-@cast", the UI will contain
a dummy cast proxy that does not require the full cast system.
  • Loading branch information
theodab committed Dec 7, 2022
1 parent 68f10a1 commit 089e3ff
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
11 changes: 11 additions & 0 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def has_ui(self):
return True
return False

def has_cast(self):
"""Returns True if the cast system is in the build."""
for path in self.include:
if 'cast' in path.split(os.path.sep):
return True
return False

def generate_localizations(self, locales, force):
localizations = compiler.GenerateLocalizations(locales)
localizations.generate(force)
Expand Down Expand Up @@ -275,6 +282,10 @@ def build_library(self, name, locales, force, is_debug):
return False
if self.has_ui():
self.generate_localizations(locales, force)
# So that the UI will correctly build if the cast is disabled, add the
# dummy cast proxy.
if not self.has_cast():
self.include.add(os.path.abspath('conditional/dummy_cast_proxy.js'))

if is_debug:
name += '.debug'
Expand Down
120 changes: 120 additions & 0 deletions conditional/dummy_cast_proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

goog.provide('shaka.cast.CastProxy');

goog.require('shaka.Player');
goog.require('shaka.util.FakeEventTarget');
goog.require('shaka.util.IDestroyable');

/**
* @summary A dummy version of the cast proxy. Meant to allow Shaka Player to
* build the UI without the cast system.
*
* @implements {shaka.util.IDestroyable}
* @export
*/
shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
/**
* @param {!HTMLMediaElement} video
* @param {!shaka.Player} player
* @param {string} receiverAppId
* @param {boolean} androidReceiverCompatible
*/
constructor(video, player, receiverAppId, androidReceiverCompatible = false) {
super();

/** @private {!HTMLMediaElement} */
this.video_ = video;

/** @private {!shaka.Player} */
this.player_ = player;
}

/**
* @param {boolean=} forceDisconnect
* @override
* @export
*/
async destroy(forceDisconnect) {
await this.player_.destroy();
super.release();
}

/**
* @return {!HTMLMediaElement}
* @export
*/
getVideo() {
return this.video_;
}

/**
* @return {!shaka.Player}
* @export
*/
getPlayer() {
return this.player_;
}

/**
* @return {boolean}
* @export
*/
canCast() {
return false;
}

/**
* @return {boolean}
* @export
*/
isCasting() {
return false;
}

/**
* @return {string}
* @export
*/
receiverName() {
return 'dummy';
}

/**
* @return {!Promise}
* @export
*/
async cast() {
await Promise.resolve();
}

/**
* @param {Object} appData
* @export
*/
setAppData(appData) {}

/**
* @export
*/
suggestDisconnect() {}

/**
* @export
*/
forceDisconnect() {}


/**
* @param {string} newAppId
* @param {boolean=} newCastAndroidReceiver
* @export
*/
async changeReceiverId(newAppId, newCastAndroidReceiver = false) {
await Promise.resolve();
}
};

0 comments on commit 089e3ff

Please sign in to comment.