playable
Version:
Video player based on HTML5Video
118 lines • 4.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DELAYED_SHOW_TIMEOUT = void 0;
var tslib_1 = require("tslib");
var constants_1 = require("../../../constants");
var loader_view_1 = (0, tslib_1.__importDefault)(require("./loader.view"));
exports.DELAYED_SHOW_TIMEOUT = 100;
var Loader = /** @class */ (function () {
function Loader(_a) {
var config = _a.config, eventEmitter = _a.eventEmitter, engine = _a.engine, rootContainer = _a.rootContainer;
this._eventEmitter = eventEmitter;
this.isHidden = false;
this._engine = engine;
this._bindCallbacks();
this._initUI();
this._bindEvents();
this._hideContent();
rootContainer.appendComponentElement(this.getElement());
if (config.hideMainUI) {
this.hide();
}
}
Loader.prototype.getElement = function () {
return this.view.getElement();
};
Loader.prototype._bindCallbacks = function () {
this._showContent = this._showContent.bind(this);
this._hideContent = this._hideContent.bind(this);
};
Loader.prototype._bindEvents = function () {
this._unbindEvents = this._eventEmitter.bindEvents([
[constants_1.VideoEvent.STATE_CHANGED, this._checkForWaitingState],
[constants_1.VideoEvent.UPLOAD_SUSPEND, this.hide],
], this);
};
Loader.prototype._checkForWaitingState = function (_a) {
var nextState = _a.nextState;
switch (nextState) {
case constants_1.EngineState.SEEK_IN_PROGRESS:
this.startDelayedShow();
break;
case constants_1.EngineState.WAITING:
this.startDelayedShow();
break;
case constants_1.EngineState.LOAD_STARTED:
if (this._engine.isPreloadActive) {
this._showContent();
}
break;
case constants_1.EngineState.READY_TO_PLAY:
this.stopDelayedShow();
this._hideContent();
break;
case constants_1.EngineState.PLAYING:
this.stopDelayedShow();
this._hideContent();
break;
case constants_1.EngineState.PAUSED:
this.stopDelayedShow();
this._hideContent();
break;
/* ignore coverage */
default:
break;
}
};
Loader.prototype._initUI = function () {
this.view = new Loader.View();
};
Loader.prototype._showContent = function () {
if (this.isHidden) {
this._eventEmitter.emitAsync(constants_1.UIEvent.LOADER_SHOW);
this.view.showContent();
this.isHidden = false;
}
};
Loader.prototype._hideContent = function () {
if (!this.isHidden) {
this._eventEmitter.emitAsync(constants_1.UIEvent.LOADER_HIDE);
this.view.hideContent();
this.isHidden = true;
}
};
Loader.prototype.hide = function () {
this.view.hide();
};
Loader.prototype.show = function () {
this.view.show();
};
Loader.prototype.startDelayedShow = function () {
if (this.isDelayedShowScheduled) {
this.stopDelayedShow();
}
this._delayedShowTimeout = window.setTimeout(this._showContent, exports.DELAYED_SHOW_TIMEOUT);
};
Loader.prototype.stopDelayedShow = function () {
window.clearTimeout(this._delayedShowTimeout);
this._delayedShowTimeout = null;
};
Object.defineProperty(Loader.prototype, "isDelayedShowScheduled", {
get: function () {
return Boolean(this._delayedShowTimeout);
},
enumerable: false,
configurable: true
});
Loader.prototype.destroy = function () {
this._unbindEvents();
this.stopDelayedShow();
this.view.destroy();
};
Loader.moduleName = 'loader';
Loader.View = loader_view_1.default;
Loader.dependencies = ['engine', 'eventEmitter', 'config', 'rootContainer'];
return Loader;
}());
exports.default = Loader;
//# sourceMappingURL=loader.js.map