UNPKG

rx-player

Version:
177 lines (176 loc) 8.26 kB
"use strict"; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatErrorForSender = formatErrorForSender; exports.synchronizeSegmentSinksOnObservation = synchronizeSegmentSinksOnObservation; exports.updateCodecSupportInWorkerMode = updateCodecSupportInWorkerMode; exports.extractExternalPlugins = extractExternalPlugins; var browser_compatibility_types_1 = require("../../compat/browser_compatibility_types"); var errors_1 = require("../../errors"); var manifest_1 = require("../../manifest"); var is_null_or_undefined_1 = require("../../utils/is_null_or_undefined"); /** * Format an error, which may be of any form, into an Object than can easily be * serialized - e.g. to be communicated through a postMessage-like API. * @param {*} error - The error to serialized * @returns {Object} - A serialization-safe error format */ function formatErrorForSender(error) { var formattedError = (0, errors_1.formatError)(error, { defaultCode: "NONE", defaultReason: "An unknown error stopped content playback.", }); return formattedError.serialize(); } /** * Synchronize SegmentSinks with what has been buffered. * @param {Object} observation - The just-received playback observation, * including what has been buffered on lower-level buffers * @param {Object} segmentSinksStore - Interface allowing to interact * with `SegmentSink`s, so their inventory can be updated accordingly. */ function synchronizeSegmentSinksOnObservation(observation, segmentSinksStore) { // Synchronize SegmentSinks with what has been buffered. ["video", "audio", "text"].forEach(function (tType) { var _a; var segmentSinkStatus = segmentSinksStore.getStatus(tType); if (segmentSinkStatus.type === "initialized") { segmentSinkStatus.value.synchronizeInventory((_a = observation.buffered[tType]) !== null && _a !== void 0 ? _a : []); } }); } /** * Set Representation.isCodecSupportedInWebWorker to true or false * If the codec is supported in the current context. * If MSE in worker is not available, the attribute is not set. */ function updateCodecSupportInWorkerMode(manifestToUpdate) { var e_1, _a, e_2, _b, e_3, _c; var _d, _e; if ((0, is_null_or_undefined_1.default)(browser_compatibility_types_1.default.MediaSource_)) { return; } var codecsMap = new Map(); try { for (var _f = __values(manifestToUpdate.periods), _g = _f.next(); !_g.done; _g = _f.next()) { var period = _g.value; var checkedAdaptations = __spreadArray(__spreadArray([], __read(((_d = period.adaptations.video) !== null && _d !== void 0 ? _d : [])), false), __read(((_e = period.adaptations.audio) !== null && _e !== void 0 ? _e : [])), false); try { for (var checkedAdaptations_1 = (e_2 = void 0, __values(checkedAdaptations)), checkedAdaptations_1_1 = checkedAdaptations_1.next(); !checkedAdaptations_1_1.done; checkedAdaptations_1_1 = checkedAdaptations_1.next()) { var adaptation = checkedAdaptations_1_1.value; try { for (var _h = (e_3 = void 0, __values(adaptation.representations)), _j = _h.next(); !_j.done; _j = _h.next()) { var representation = _j.value; var codec = representation.getMimeTypeString(); if (codecsMap.has(codec)) { representation.isCodecSupportedInWebWorker = codecsMap.get(codec); } else { var supported = browser_compatibility_types_1.default.MediaSource_.isTypeSupported(codec); representation.isCodecSupportedInWebWorker = supported; codecsMap.set(codec, supported); } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_j && !_j.done && (_c = _h.return)) _c.call(_h); } finally { if (e_3) throw e_3.error; } } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (checkedAdaptations_1_1 && !checkedAdaptations_1_1.done && (_b = checkedAdaptations_1.return)) _b.call(checkedAdaptations_1); } finally { if (e_2) throw e_2.error; } } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_g && !_g.done && (_a = _f.return)) _a.call(_f); } finally { if (e_1) throw e_1.error; } } } /** * Some functions may be defined by the API, we call those "plugins". * This function parses and extract the actual function from the different * ways an application can provide it to us. * @param {Object} input - The API input * @param {Object} corePlugins - Context on what identified functions are * defined right now. * @returns {Function} */ function extractExternalPlugins(input, corePlugins) { var _a, _b, _c, _d, _e, _f, _g; var manifestLoader; var segmentLoader; var representationFilter; if (typeof ((_a = input.representationFilter) === null || _a === void 0 ? void 0 : _a.fn) === "function") { representationFilter = input.representationFilter.fn; } else if (typeof ((_b = input.representationFilter) === null || _b === void 0 ? void 0 : _b.eval) === "string") { representationFilter = (0, manifest_1.createRepresentationFilterFromFnString)(input.representationFilter.eval); } else if (typeof ((_c = input.representationFilter) === null || _c === void 0 ? void 0 : _c.workerId) === "string") { representationFilter = corePlugins.representationFilters.get(input.representationFilter.workerId); } if (typeof ((_d = input.manifestLoader) === null || _d === void 0 ? void 0 : _d.fn) === "function") { manifestLoader = input.manifestLoader.fn; } else if (typeof ((_e = input.manifestLoader) === null || _e === void 0 ? void 0 : _e.workerId) === "string") { manifestLoader = corePlugins.manifestLoaders.get(input.manifestLoader.workerId); } if (typeof ((_f = input.segmentLoader) === null || _f === void 0 ? void 0 : _f.fn) === "function") { segmentLoader = input.segmentLoader.fn; } else if (typeof ((_g = input.segmentLoader) === null || _g === void 0 ? void 0 : _g.workerId) === "string") { segmentLoader = corePlugins.segmentLoaders.get(input.segmentLoader.workerId); } return { manifestLoader: manifestLoader, segmentLoader: segmentLoader, representationFilter: representationFilter, }; }