From 089e3ff254903a98c6aaad827236f95789ab4f8f Mon Sep 17 00:00:00 2001 From: theodab Date: Tue, 6 Dec 2022 17:28:18 -0800 Subject: [PATCH] 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. --- build/build.py | 11 +++ conditional/dummy_cast_proxy.js | 120 ++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 conditional/dummy_cast_proxy.js diff --git a/build/build.py b/build/build.py index 839672cc0..dfbe4220e 100755 --- a/build/build.py +++ b/build/build.py @@ -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' diff --git a/conditional/dummy_cast_proxy.js b/conditional/dummy_cast_proxy.js new file mode 100644 index 000000000..ebe9641e9 --- /dev/null +++ b/conditional/dummy_cast_proxy.js @@ -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(); + } +};