Files
ShakaPlayer/lib/device/device_factory.js
Álvaro Velad Galván 4f62ce8b24 build: Reduce bundle size by deduplicating license headers (#10182)
Ensure generated bundles contain a single license header instead of
repeating the same notice across bundled modules.

Normalize all copyright years to 2016 and remove
duplicate license headers from generated bundles.

This reduces the final bundle size while preserving license information
in the distributed artifacts.
2026-06-05 12:43:28 +02:00

65 lines
1.8 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.device.DeviceFactory');
goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.util.Lazy');
goog.requireType('shaka.device.IDevice');
shaka.device.DeviceFactory = class {
/**
* @param {?function(): shaka.device.IDevice} deviceFactory
*/
static registerDeviceFactory(deviceFactory) {
goog.asserts.assert(!shaka.device.DeviceFactory.factory_,
'Device Factory should NOT be defined');
shaka.device.DeviceFactory.factory_ = deviceFactory;
}
/**
* @param {?function(): shaka.device.IDevice} deviceFactory
*/
static registerDefaultDeviceFactory(deviceFactory) {
goog.asserts.assert(!shaka.device.DeviceFactory.defaultFactory_,
'Default device Factory should NOT be defined');
shaka.device.DeviceFactory.defaultFactory_ = deviceFactory;
}
/**
* @return {shaka.device.IDevice}
*/
static getDevice() {
goog.asserts.assert(shaka.device.DeviceFactory.factory_ ||
shaka.device.DeviceFactory.defaultFactory_,
'Device Factory should be defined');
return shaka.device.DeviceFactory.device_.value();
}
};
/** @private {?function(): shaka.device.IDevice} */
shaka.device.DeviceFactory.factory_ = null;
/** @private {?function(): shaka.device.IDevice} */
shaka.device.DeviceFactory.defaultFactory_ = null;
/** @private {!shaka.util.Lazy<shaka.device.IDevice>} */
shaka.device.DeviceFactory.device_ = new shaka.util.Lazy(() => {
let device = undefined;
if (shaka.device.DeviceFactory.factory_) {
device = shaka.device.DeviceFactory.factory_();
}
if (!device && shaka.device.DeviceFactory.defaultFactory_) {
device = shaka.device.DeviceFactory.defaultFactory_();
}
if (device) {
shaka.log.info(device.toString());
}
return device;
});