feat(ui): Add ability to build UI without cast (#4781)

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.
This commit is contained in:
theodab
2022-12-06 17:28:18 -08:00
committed by GitHub
parent 68f10a1969
commit 089e3ff254
2 changed files with 131 additions and 0 deletions
+11
View File
@@ -185,6 +185,13 @@ class Build(object):
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)
@@ -275,6 +282,10 @@ class Build(object):
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'
+120
View File
@@ -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();
}
};