playable
Version:
Video player based on HTML5Video
118 lines • 5.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var player_api_decorator_1 = (0, tslib_1.__importDefault)(require("../../../../core/player-api-decorator"));
var constants_1 = require("../../../../constants");
var keyboard_interceptor_1 = (0, tslib_1.__importStar)(require("../../../../utils/keyboard-interceptor"));
var chromecast_view_1 = (0, tslib_1.__importDefault)(require("./chromecast.view"));
var chromecast_manager_1 = require("../../../chromecast-manager/chromecast-manager");
var ChromecastButton = /** @class */ (function () {
function ChromecastButton(_a) {
var eventEmitter = _a.eventEmitter, textMap = _a.textMap, tooltipService = _a.tooltipService, theme = _a.theme, chromecastManager = _a.chromecastManager, bottomBlock = _a.bottomBlock;
this._eventEmitter = eventEmitter;
this._textMap = textMap;
this._theme = theme;
this._tooltipService = tooltipService;
this._chromecastManager = chromecastManager;
this._bottomBlock = bottomBlock;
this._bindCallbacks();
this._initUI();
this._initInterceptor();
this._bindEvents();
this._connectToPanel();
}
ChromecastButton.prototype.getElement = function () {
return this.view.getElement();
};
ChromecastButton.prototype._connectToPanel = function () {
this._bottomBlock.addControl(ChromecastButton.moduleName, this.getElement());
};
ChromecastButton.prototype._bindCallbacks = function () {
this._triggerCallback = this._triggerCallback.bind(this);
};
ChromecastButton.prototype._initUI = function () {
var config = {
callbacks: {
onButtonClick: this._triggerCallback,
},
textMap: this._textMap,
tooltipService: this._tooltipService,
theme: this._theme,
};
this.view = new ChromecastButton.View(config);
this.hide();
};
ChromecastButton.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.UI_EVENTS.KEYBOARD_KEYDOWN_INTERCEPTED);
_this._triggerCallback();
},
_a[keyboard_interceptor_1.KEYCODES.ENTER] = function (e) {
e.stopPropagation();
_this._eventEmitter.emitAsync(constants_1.UI_EVENTS.KEYBOARD_KEYDOWN_INTERCEPTED);
_this._triggerCallback();
},
_a));
};
ChromecastButton.prototype._bindEvents = function () {
var _this = this;
var show = this.show.bind(this);
var hide = this.hide.bind(this);
var setStateToCast = function () { return _this.view.setCastingState(true); };
var resetStateFromCast = function () { return _this.view.setCastingState(true); };
this._unbindEvents = this._eventEmitter.bindEvents([
[chromecast_manager_1.ChromecastEvents.CHROMECAST_NOT_CONNECTED, show],
[chromecast_manager_1.ChromecastEvents.CHROMECAST_CONNECTING, show],
[chromecast_manager_1.ChromecastEvents.CHROMECAST_CONNECTED, show],
[chromecast_manager_1.ChromecastEvents.CHROMECAST_NO_DEVICES_AVAILABLE, hide],
[chromecast_manager_1.ChromecastEvents.CHROMECAST_CASTS_STARTED, setStateToCast],
[chromecast_manager_1.ChromecastEvents.CHROMECAST_CASTS_RESUMED, setStateToCast],
[chromecast_manager_1.ChromecastEvents.CHROMECAST_CASTS_STOPED, resetStateFromCast],
]);
};
ChromecastButton.prototype._destroyInterceptor = function () {
this._interceptor.destroy();
};
ChromecastButton.prototype._triggerCallback = function () {
if (this._callback) {
this._callback();
}
};
ChromecastButton.prototype.setChromecastButtonCallback = function (callback) {
this._callback = callback;
};
ChromecastButton.prototype.hide = function () {
this.isHidden = true;
this.view.hide();
};
ChromecastButton.prototype.show = function () {
this.isHidden = false;
this.view.show();
};
ChromecastButton.prototype.destroy = function () {
this._destroyInterceptor();
this.view.destroy();
this._unbindEvents();
this._chromecastManager.destroy();
};
ChromecastButton.moduleName = 'chromecastButton';
ChromecastButton.View = chromecast_view_1.default;
ChromecastButton.dependencies = [
'eventEmitter',
'textMap',
'tooltipService',
'theme',
'chromecastManager',
'bottomBlock',
];
(0, tslib_1.__decorate)([
(0, player_api_decorator_1.default)()
], ChromecastButton.prototype, "setChromecastButtonCallback", null);
return ChromecastButton;
}());
exports.default = ChromecastButton;
//# sourceMappingURL=chromecast.js.map