mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-15 16:06:41 +03:00
52f18df21b
This change allows polyfills to be installed individually e.g. shaka.polyfill.MediaCapabilities.install() instead of shaka.polyfill.installAll() Related to #2625
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.polyfill.StorageEstimate');
|
|
|
|
goog.require('shaka.polyfill');
|
|
|
|
|
|
/**
|
|
* @summary A polyfill to provide navigator.storage.estimate in old
|
|
* webkit browsers.
|
|
* See: https://developers.google.com/web/updates/2017/08/estimating-available-storage-space#the-present
|
|
* @export
|
|
*/
|
|
shaka.polyfill.StorageEstimate = class {
|
|
/**
|
|
* Install the polyfill if needed.
|
|
* @export
|
|
*/
|
|
static install() {
|
|
if (navigator.storage && navigator.storage.estimate) {
|
|
// No need.
|
|
return;
|
|
}
|
|
|
|
if (navigator.webkitTemporaryStorage &&
|
|
navigator.webkitTemporaryStorage.queryUsageAndQuota) {
|
|
if (!('storage' in navigator)) {
|
|
navigator.storage = /** @type {!StorageManager} */ ({});
|
|
}
|
|
navigator.storage.estimate =
|
|
shaka.polyfill.StorageEstimate.storageEstimate_;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @this {StorageManager}
|
|
* @return {!Promise}
|
|
* @private
|
|
*/
|
|
static storageEstimate_() {
|
|
return new Promise((resolve, reject) => {
|
|
navigator.webkitTemporaryStorage.queryUsageAndQuota(
|
|
(usage, quota) => {
|
|
resolve({usage: usage, quota: quota});
|
|
},
|
|
reject,
|
|
);
|
|
});
|
|
}
|
|
};
|
|
|
|
|
|
shaka.polyfill.register(shaka.polyfill.StorageEstimate.install);
|