UNPKG

playable

Version:

Video player based on HTML5Video

164 lines (163 loc) 6.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var constants_1 = require("../../../../../constants"); var video_data_1 = require("../../../../../utils/video-data"); var environment_detection_1 = require("../../../../../utils/environment-detection"); var NATIVE_ERROR_CODES = { ABORTED: 1, NETWORK: 2, DECODE: 3, SRC_NOT_SUPPORTED: 4, }; function getNativeAdapterCreator(streamType, deliveryPriority) { var NativeAdapter = /** @class */ (function () { function NativeAdapter(eventEmitter) { this.mediaStreams = null; this.eventEmitter = eventEmitter; this.currentLevel = 0; this._bindCallbacks(); } NativeAdapter.isSupported = function () { return environment_detection_1.NativeEnvironmentSupport[streamType]; }; Object.defineProperty(NativeAdapter.prototype, "currentUrl", { get: function () { return this.mediaStreams[this.currentLevel].url; }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "syncWithLiveTime", { get: function () { // TODO: implement syncWithLiveTime for `native` return undefined; }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "isDynamicContent", { get: function () { return !isFinite(this.video.duration); }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "isDynamicContentEnded", { get: function () { // TODO: implement isDynamicContentEnded return false; }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "isSyncWithLive", { get: function () { // TODO: implement isSyncWithLive for `native` return false; }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "isSeekAvailable", { get: function () { return true; //Need to find better solution /* if (this.isDynamicContent) { return false; } return Boolean(this.output.seekable.length); */ }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "mediaStreamDeliveryPriority", { get: function () { return deliveryPriority; }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "mediaStreamType", { get: function () { return streamType; }, enumerable: false, configurable: true }); Object.defineProperty(NativeAdapter.prototype, "debugInfo", { get: function () { if (this.video) { var _a = this.video, buffered = _a.buffered, currentTime = _a.currentTime; var overallBufferLength = (0, video_data_1.geOverallBufferLength)(buffered); var nearestBufferSegInfo = (0, video_data_1.getNearestBufferSegmentInfo)(buffered, currentTime); return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, this.mediaStreams[0]), { deliveryPriority: this.mediaStreamDeliveryPriority, overallBufferLength: overallBufferLength, nearestBufferSegInfo: nearestBufferSegInfo }); } return {}; }, enumerable: false, configurable: true }); NativeAdapter.prototype._bindCallbacks = function () { this._broadcastError = this._broadcastError.bind(this); }; NativeAdapter.prototype.canPlay = function (mediaType) { return mediaType === streamType; }; NativeAdapter.prototype.setMediaStreams = function (mediaStreams) { this.mediaStreams = mediaStreams; }; NativeAdapter.prototype._logError = function (error, errorEvent) { this.eventEmitter.emitAsync(constants_1.VideoEvent.ERROR, { errorType: error, streamType: streamType, streamProvider: 'native', errorInstance: errorEvent, }); }; NativeAdapter.prototype._broadcastError = function () { var error = this.video.error; // take error from event? if (!error) { this._logError(constants_1.Error.UNKNOWN, null); return; } switch (error.code) { case NATIVE_ERROR_CODES.ABORTED: //No need for broadcasting break; case NATIVE_ERROR_CODES.NETWORK: this._logError(constants_1.Error.CONTENT_LOAD, error); break; case NATIVE_ERROR_CODES.DECODE: this._logError(constants_1.Error.MEDIA, error); break; case NATIVE_ERROR_CODES.SRC_NOT_SUPPORTED: /* Our url checks would not allow not supported formats, so only case would be when video tag couldn't retriev any info from endpoit */ this._logError(constants_1.Error.CONTENT_LOAD, error); break; default: this._logError(constants_1.Error.UNKNOWN, error); break; } }; NativeAdapter.prototype.attach = function (videoElement) { this.video = videoElement; this.video.addEventListener('error', this._broadcastError); this.video.src = this.mediaStreams[this.currentLevel].url; }; NativeAdapter.prototype.detach = function () { this.video.removeEventListener('error', this._broadcastError); this.video.removeAttribute('src'); this.video = null; }; return NativeAdapter; }()); return NativeAdapter; } exports.default = getNativeAdapterCreator; //# sourceMappingURL=native.js.map