mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-16 16:16:40 +03:00
970d7756ea
The goal is to simplify and abstract feature logic detection. Currently lots of places depend on various calls to `shaka.util.Platform` and mainteinance of this is hard & not easy to read. By introducing device API ideally rest of the player logic would look into device features instead of directly checking platform. Additionally we can more easily cache needed values, so we won't have to parse user agent several times anymore. --------- Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2025 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.factory_,
|
|
'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;
|
|
});
|