UNPKG

playable

Version:

Video player based on HTML5Video

77 lines 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var constants_1 = require("../../../../constants"); var adapters_resolver_1 = require("../../utils/adapters-resolver"); var detect_stream_type_1 = require("../../utils/detect-stream-type"); var AdaptersStrategy = /** @class */ (function () { function AdaptersStrategy(eventEmitter, video, playbackAdapters) { var _this = this; if (playbackAdapters === void 0) { playbackAdapters = []; } this._video = video; this._eventEmitter = eventEmitter; this._playableAdapters = []; this._availableAdapters = []; this._attachedAdapter = null; playbackAdapters.forEach(function (adapter) { return adapter.isSupported() && _this._availableAdapters.push(new adapter(eventEmitter)); }); } AdaptersStrategy.prototype._autoDetectSourceTypes = function (mediaSources) { var _this = this; return mediaSources.map(function (mediaSource) { if (typeof mediaSource === 'string') { var type = (0, detect_stream_type_1.getStreamType)(mediaSource); if (!type) { _this._eventEmitter.emitAsync(constants_1.VideoEvent.ERROR, { errorType: constants_1.Error.SRC_PARSE, streamSrc: mediaSource, }); } return { url: mediaSource, type: type }; } return mediaSource; }); }; AdaptersStrategy.prototype._resolvePlayableAdapters = function (src) { if (!src) { this._playableAdapters = []; return; } var mediaSources = [].concat(src); var mediaStreams = this._autoDetectSourceTypes(mediaSources); this._playableAdapters = (0, adapters_resolver_1.resolveAdapters)(mediaStreams, this._availableAdapters); }; AdaptersStrategy.prototype._connectAdapterToVideo = function () { if (this._playableAdapters.length > 0) { // Use the first PlayableStream for now // Later, we can use the others as fallback this._attachedAdapter = this._playableAdapters[0]; this._attachedAdapter.attach(this._video); } }; AdaptersStrategy.prototype._detachCurrentAdapter = function () { if (this._attachedAdapter) { this._attachedAdapter.detach(); this._attachedAdapter = null; } }; Object.defineProperty(AdaptersStrategy.prototype, "attachedAdapter", { get: function () { return this._attachedAdapter; }, enumerable: false, configurable: true }); AdaptersStrategy.prototype.connectAdapter = function (src) { this._detachCurrentAdapter(); this._resolvePlayableAdapters(src); this._connectAdapterToVideo(); }; AdaptersStrategy.prototype.destroy = function () { this._detachCurrentAdapter(); }; return AdaptersStrategy; }()); exports.default = AdaptersStrategy; //# sourceMappingURL=adapters-strategy.js.map