UNPKG

playable

Version:

Video player based on HTML5Video

279 lines 10.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var device_detection_1 = require("../../utils/device-detection"); var player_api_decorator_1 = (0, tslib_1.__importDefault)(require("../../core/player-api-decorator")); var desktop_1 = (0, tslib_1.__importDefault)(require("./desktop")); var ios_1 = (0, tslib_1.__importDefault)(require("./ios")); var constants_1 = require("../../constants"); var DEFAULT_CONFIG = { exitFullScreenOnEnd: true, enterFullScreenOnPlay: false, exitFullScreenOnPause: false, pauseVideoOnFullScreenExit: false, }; var FullScreenManager = /** @class */ (function () { function FullScreenManager(_a) { var eventEmitter = _a.eventEmitter, engine = _a.engine, rootContainer = _a.rootContainer, config = _a.config; this._exitFullScreenOnEnd = false; this._enterFullScreenOnPlay = false; this._exitFullScreenOnPause = false; this._pauseVideoOnFullScreenExit = false; this._eventEmitter = eventEmitter; this._engine = engine; if (config.disableFullScreen) { this._isEnabled = false; } else { this._isEnabled = true; var _config = (0, tslib_1.__assign)({}, DEFAULT_CONFIG); this._exitFullScreenOnEnd = _config.exitFullScreenOnEnd; this._enterFullScreenOnPlay = _config.enterFullScreenOnPlay; this._exitFullScreenOnPause = _config.exitFullScreenOnPause; this._pauseVideoOnFullScreenExit = _config.pauseVideoOnFullScreenExit; } this._onChange = this._onChange.bind(this); if ((0, device_detection_1.isIOS)()) { this._element = this._engine.getElement(); this._helper = new ios_1.default(this._engine.getElement(), this._onChange); } else { this._element = rootContainer.getElement(); this._helper = new desktop_1.default(rootContainer.getElement(), this._onChange); } this._bindEvents(); } FullScreenManager.prototype._onChange = function (event) { if (event.target !== this._element) { return; } if (!this._helper.isInFullScreen && this._pauseVideoOnFullScreenExit) { this._engine.pause(); } this._eventEmitter.emitAsync(constants_1.UIEvent.FULL_SCREEN_STATE_CHANGED, this._helper.isInFullScreen); }; FullScreenManager.prototype._bindEvents = function () { this._unbindEvents = this._eventEmitter.bindEvents([ [constants_1.VideoEvent.STATE_CHANGED, this._processNextStateFromEngine], [constants_1.VideoEvent.PLAY_REQUEST, this._enterOnPlayRequested], ], this); }; FullScreenManager.prototype._exitOnEnd = function () { if (this._exitFullScreenOnEnd && this.isInFullScreen) { this.exitFullScreen(); } }; FullScreenManager.prototype._enterOnPlayRequested = function () { if (this._enterFullScreenOnPlay && !this.isInFullScreen) { this.enterFullScreen(); } }; FullScreenManager.prototype._exitOnPauseRequested = function () { if (this._exitFullScreenOnPause && this.isInFullScreen) { this.exitFullScreen(); } }; FullScreenManager.prototype._processNextStateFromEngine = function (_a) { var nextState = _a.nextState; switch (nextState) { case constants_1.EngineState.ENDED: { this._exitOnEnd(); break; } case constants_1.EngineState.PAUSED: { this._exitOnPauseRequested(); break; } /* ignore coverage */ default: break; } }; /** * Allow player try to exit full screen on pause * @example * player.play(); * player.enableExitFullScreenOnPause(); * player.enterFullScreen(); * console.log(player.isInFullScreen) // true * player.pause(); * console.log(player.isInFullScreen) // false */ FullScreenManager.prototype.enableExitFullScreenOnPause = function () { this._exitFullScreenOnPause = true; }; /** * Disallow player to exit full screen on pause * @example * player.play(); * player.disableExitFullScreenOnPause(); * player.enterFullScreen(); * console.log(player.isInFullScreen) // true * player.pause(); * console.log(player.isInFullScreen) // true */ FullScreenManager.prototype.disableExitFullScreenOnPause = function () { this._exitFullScreenOnPause = false; }; /** * Allow player try to exit full screen on end * @example * player.play(); * player.enableExitFullScreenOnEnd(); * player.enterFullScreen(); * console.log(player.isInFullScreen) // true * console.log(player.isEnded); // true * console.log(player.isInFullScreen) // false */ FullScreenManager.prototype.enableExitFullScreenOnEnd = function () { this._exitFullScreenOnEnd = true; }; /** * Disallow player try to exit full screen on end * @example * player.play(); * player.disableExitFullScreenOnEnd(); * player.enterFullScreen(); * console.log(player.isInFullScreen) // true * console.log(player.isEnded); // true * console.log(player.isInFullScreen) // true */ FullScreenManager.prototype.disableExitFullScreenOnEnd = function () { this._exitFullScreenOnPause = false; }; /** * Allow player try to exit full screen on end * @example * player.enableEnterFullScreenOnPlay(); * console.log(player.isInFullScreen) // false * player.play(); * console.log(player.isInFullScreen) // true */ FullScreenManager.prototype.enableEnterFullScreenOnPlay = function () { this._enterFullScreenOnPlay = true; }; /** * Disallow player try to exit full screen on end * @example * player.disableEnterFullScreenOnPlay(); * console.log(player.isInFullScreen) // false * player.play(); * console.log(player.isInFullScreen) // false */ FullScreenManager.prototype.disableEnterFullScreenOnPlay = function () { this._enterFullScreenOnPlay = false; }; /** * Allow player try to exit full screen on end * @example * player.play(); * player.enablePauseVideoOnFullScreenExit(); * player.enterFullScreen(); * console.log(player.isInFullScreen) // true * player.pause(); * console.log(player.isInFullScreen) // false */ FullScreenManager.prototype.enablePauseVideoOnFullScreenExit = function () { this._pauseVideoOnFullScreenExit = true; }; /** * Disallow player try to exit full screen on end * @example * player.play(); * player.enablePauseVideoOnFullScreenExit(); * player.enterFullScreen(); * console.log(player.isInFullScreen) // true * player.pause(); * console.log(player.isInFullScreen) // true */ FullScreenManager.prototype.disablePauseVideoOnFullScreenExit = function () { this._pauseVideoOnFullScreenExit = false; }; /** * Player would try to enter fullscreen mode. * Behavior of fullscreen mode on different platforms may differ. * @example * player.enterFullScreen(); */ FullScreenManager.prototype.enterFullScreen = function () { if (!this.isEnabled) { return; } this._helper.request(); }; /** * Player would try to exit fullscreen mode. * @example * player.exitFullScreen(); */ FullScreenManager.prototype.exitFullScreen = function () { if (!this.isEnabled) { return; } this._helper.exit(); }; Object.defineProperty(FullScreenManager.prototype, "isInFullScreen", { /** * Return true if player is in full screen * @example * console.log(player.isInFullScreen); // false */ get: function () { if (!this.isEnabled) { return false; } return this._helper.isInFullScreen; }, enumerable: false, configurable: true }); Object.defineProperty(FullScreenManager.prototype, "isEnabled", { get: function () { return this._helper.isEnabled && this._isEnabled; }, enumerable: false, configurable: true }); FullScreenManager.prototype.destroy = function () { this._unbindEvents(); this._helper.destroy(); }; FullScreenManager.moduleName = 'fullScreenManager'; FullScreenManager.dependencies = ['eventEmitter', 'engine', 'rootContainer', 'config']; (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "enableExitFullScreenOnPause", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "disableExitFullScreenOnPause", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "enableExitFullScreenOnEnd", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "disableExitFullScreenOnEnd", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "enableEnterFullScreenOnPlay", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "disableEnterFullScreenOnPlay", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "enablePauseVideoOnFullScreenExit", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "disablePauseVideoOnFullScreenExit", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "enterFullScreen", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "exitFullScreen", null); (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], FullScreenManager.prototype, "isInFullScreen", null); return FullScreenManager; }()); exports.default = FullScreenManager; //# sourceMappingURL=full-screen-manager.js.map