UNPKG

playable

Version:

Video player based on HTML5Video

145 lines 5.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var constants_1 = require("../../../constants"); var keyboard_interceptor_1 = (0, tslib_1.__importStar)(require("../../../utils/keyboard-interceptor")); var live_indicator_view_1 = (0, tslib_1.__importDefault)(require("./live-indicator.view")); var LiveIndicator = /** @class */ (function () { function LiveIndicator(_a) { var engine = _a.engine, eventEmitter = _a.eventEmitter, textMap = _a.textMap, tooltipService = _a.tooltipService; this._isHidden = true; this._isActive = false; this._isEnded = false; this._engine = engine; this._eventEmitter = eventEmitter; this._textMap = textMap; this._tooltipService = tooltipService; this._bindCallbacks(); this._initUI(); this._bindEvents(); this._initInterceptor(); } LiveIndicator.prototype.getElement = function () { return this.view.getElement(); }; LiveIndicator.prototype._initInterceptor = function () { var _a; var _this = this; this._interceptor = new keyboard_interceptor_1.default(this.getElement(), (_a = {}, _a[keyboard_interceptor_1.KEYCODES.SPACE_BAR] = function (e) { e.stopPropagation(); _this._eventEmitter.emitAsync(constants_1.UIEvent.KEYBOARD_KEYDOWN_INTERCEPTED); _this._syncWithLive(); }, _a[keyboard_interceptor_1.KEYCODES.ENTER] = function (e) { e.stopPropagation(); _this._eventEmitter.emitAsync(constants_1.UIEvent.KEYBOARD_KEYDOWN_INTERCEPTED); _this._syncWithLive(); }, _a)); }; Object.defineProperty(LiveIndicator.prototype, "isHidden", { get: function () { return this._isHidden; }, enumerable: false, configurable: true }); Object.defineProperty(LiveIndicator.prototype, "isActive", { get: function () { return this._isActive; }, enumerable: false, configurable: true }); LiveIndicator.prototype.show = function () { this._toggle(true); }; LiveIndicator.prototype.hide = function () { this._toggle(false); }; LiveIndicator.prototype._initUI = function () { this.view = new LiveIndicator.View({ callbacks: { onClick: this._syncWithLive, }, textMap: this._textMap, tooltipService: this._tooltipService, }); }; LiveIndicator.prototype._bindCallbacks = function () { this._syncWithLive = this._syncWithLive.bind(this); }; LiveIndicator.prototype._bindEvents = function () { var _this = this; this._unbindEvents = this._eventEmitter.bindEvents([ [constants_1.VideoEvent.LIVE_STATE_CHANGED, this._processStateChange], [ constants_1.UIEvent.PROGRESS_SYNC_BUTTON_MOUSE_ENTER, function () { _this.view.toggleActive(true); }, ], [ constants_1.UIEvent.PROGRESS_SYNC_BUTTON_MOUSE_LEAVE, function () { // NOTE: restore state before mouse enter _this.view.toggleActive(_this._isActive); }, ], ], this); }; LiveIndicator.prototype._processStateChange = function (_a) { var nextState = _a.nextState; switch (nextState) { case constants_1.LiveState.NONE: this._toggle(false); this._toggleActive(false); this._toggleEnded(false); break; case constants_1.LiveState.INITIAL: this._toggle(true); break; case constants_1.LiveState.SYNC: this._toggleActive(true); break; case constants_1.LiveState.NOT_SYNC: this._toggleActive(false); break; case constants_1.LiveState.ENDED: this._toggleActive(false); this._toggleEnded(true); break; default: break; } }; LiveIndicator.prototype._syncWithLive = function () { if (!this._isEnded) { this._engine.syncWithLive(); } }; LiveIndicator.prototype._toggle = function (shouldShow) { this._isHidden = !shouldShow; this.view.toggle(shouldShow); }; LiveIndicator.prototype._toggleActive = function (shouldActivate) { this._isActive = shouldActivate; this.view.toggleActive(shouldActivate); }; LiveIndicator.prototype._toggleEnded = function (isEnded) { this._isEnded = isEnded; this.view.toggleEnded(isEnded); }; LiveIndicator.prototype.destroy = function () { this._unbindEvents(); this._interceptor.destroy(); this.view.destroy(); }; LiveIndicator.moduleName = 'liveIndicator'; LiveIndicator.View = live_indicator_view_1.default; LiveIndicator.dependencies = ['engine', 'eventEmitter', 'textMap', 'tooltipService']; return LiveIndicator; }()); exports.default = LiveIndicator; //# sourceMappingURL=live-indicator.js.map