UNPKG

rx-player

Version:
74 lines (73 loc) 2.93 kB
"use strict"; /** * Copyright 2015 CANAL+ Group * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = probeDecodingInfos; var types_1 = require("../types"); /** * Check if the required APIs are available. * @returns {Promise} */ function isMediaCapabilitiesAPIAvailable() { return new Promise(function (resolve) { if (!("mediaCapabilities" in navigator)) { throw new Error("MediaCapabilitiesProber >>> API_CALL: " + "MediaCapabilities API not available"); } if (!("decodingInfo" in navigator.mediaCapabilities)) { throw new Error("MediaCapabilitiesProber >>> API_CALL: " + "Decoding Info not available"); } resolve(); }); } /** * @param {Object} config * @returns {Promise} */ function probeDecodingInfos(config) { return isMediaCapabilitiesAPIAvailable().then(function () { var hasVideoConfig = config.type !== undefined && config.type.length > 0 && config.video !== undefined && config.video.bitrate !== undefined && config.video.contentType !== undefined && config.video.contentType.length > 0 && config.video.framerate !== undefined && config.video.framerate.length > 0 && config.video.height !== undefined && config.video.width !== undefined; var hasAudioConfig = config.type !== undefined && config.type.length > 0 && config.audio !== undefined && config.audio.bitrate !== undefined && config.audio.channels !== undefined && config.audio.channels.length > 0 && config.audio.contentType !== undefined && config.audio.contentType.length > 0 && config.audio.samplerate !== undefined; if (!hasVideoConfig && !hasAudioConfig) { throw new Error("MediaCapabilitiesProber >>> API_CALL: " + "Not enough arguments for calling mediaCapabilites."); } return navigator.mediaCapabilities .decodingInfo(config) .then(function (result) { return [result.supported ? types_1.ProberStatus.Supported : types_1.ProberStatus.NotSupported]; }) .catch(function () { return [types_1.ProberStatus.NotSupported]; }); }); }