@svta/common-media-library
Version:
A common library for media playback in JavaScript
29 lines • 1.49 kB
JavaScript
const isTypeSupported = (typeof MediaKeys !== 'undefined' && typeof MediaKeys.isTypeSupported === 'function') ? MediaKeys.isTypeSupported : undefined;
/**
* Filters and returns the supported key system configuration for a given system string.
*
* @param keySystem - Key system string such as 'com.widevine.alpha'
* @param configs - An array of key system configurations.
* @returns The first supported configuration or null if none are supported.
*
* @group DRM
* @beta
*/
export function getSupportedKeySystemConfiguration(keySystem, configs) {
if (!configs || typeof isTypeSupported === 'undefined') {
return { supportedAudio: [], supportedVideo: [] };
}
for (const config of configs) {
const audios = config.audioCapabilities || [];
const videos = config.videoCapabilities || [];
const supportedAudio = audios.filter(audio => { var _a; return isTypeSupported(keySystem, (_a = audio.contentType) !== null && _a !== void 0 ? _a : ''); });
const supportedVideo = videos.filter(video => { var _a; return isTypeSupported(keySystem, (_a = video.contentType) !== null && _a !== void 0 ? _a : ''); });
const hasAudio = supportedAudio.length > 0;
const hasVideo = supportedVideo.length > 0;
if (hasAudio || hasVideo) {
return { supportedAudio, supportedVideo };
}
}
return { supportedAudio: [], supportedVideo: [] };
}
//# sourceMappingURL=getSupportedKeySystemConfiguration.js.map