Files
shaka-player/lib/media/media_source_capabilities.js
T
Andy(김규회) 05b09728c7 perf: Use Map.getOrInsert/getOrInsertComputed native methods (#9546)
Added polyfills for `Map.getOrInsert()` and
`Map.getOrInsertComputed()` from the TC39 upsert proposal and refactor
the codebase to use them.
These methods replace the common "check if key exists, then set default"
pattern with a single atomic operation. This improves code readability
and eliminates redundant map lookups throughout the player.

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
2026-01-13 10:57:25 +01:00

54 lines
1.7 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.media.Capabilities');
/**
* @summary
* This is for capturing all media source capabilities on current platform.
* And this is for static check and can not be constructed.
*/
shaka.media.Capabilities = class {
/**
* Cache browser engine call to improve performance on some poor platforms
*
* @param {string} type
* @return {boolean}
*/
static isTypeSupported(type) {
const supportMap = shaka.media.Capabilities.MediaSourceTypeSupportMap;
return supportMap.getOrInsertComputed(type, () => {
const mediaSource = window.ManagedMediaSource || window.MediaSource;
return mediaSource?.isTypeSupported(type) ?? false;
});
}
/**
* Determine support for MediaSource.setLiveSeekableRange and
* MediaSource.clearLiveSeekableRange, which can allow for a media element
* duration of Infinite by providing a non-infinite seekable range.
*
* @return {boolean}
*/
static isInfiniteLiveStreamDurationSupported() {
const mediaSource = window.ManagedMediaSource || window.MediaSource;
// eslint-disable-next-line no-restricted-syntax
if (mediaSource && mediaSource.prototype) {
// eslint-disable-next-line no-restricted-syntax
return !!mediaSource.prototype.setLiveSeekableRange &&
// eslint-disable-next-line no-restricted-syntax
!!mediaSource.prototype.clearLiveSeekableRange;
}
return false;
}
};
/**
* Public it for unit test, and developer could also check the support map.
* @type {!Map<string, boolean>}
*/
shaka.media.Capabilities.MediaSourceTypeSupportMap = new Map();