UNPKG

playable

Version:

Video player based on HTML5Video

82 lines 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var HAVE_METADATA = 1; var isPictureInPictureRequested = false; var ChromePictureInPicture = /** @class */ (function () { function ChromePictureInPicture(elem, callback) { var _this = this; this._enterWhenHasMetaData = function () { _this._$elem.removeEventListener('loadedmetadata', _this._enterWhenHasMetaData); isPictureInPictureRequested = false; _this.request(); }; this.catchException = function () { if (_this._$elem && _this._$elem.readyState < HAVE_METADATA) { _this._$elem.addEventListener('loadedmetadata', _this._enterWhenHasMetaData); isPictureInPictureRequested = true; } }; this._$elem = elem; this._callback = callback; this._bindEvents(); } Object.defineProperty(ChromePictureInPicture.prototype, "isAPIExist", { get: function () { return Boolean('pictureInPictureEnabled' in document); }, enumerable: false, configurable: true }); Object.defineProperty(ChromePictureInPicture.prototype, "isAPIEnabled", { get: function () { return Boolean(document.pictureInPictureEnabled); }, enumerable: false, configurable: true }); Object.defineProperty(ChromePictureInPicture.prototype, "isInPictureInPicture", { get: function () { return Boolean(this._$elem && this._$elem === document.pictureInPictureElement); }, enumerable: false, configurable: true }); Object.defineProperty(ChromePictureInPicture.prototype, "isEnabled", { get: function () { return this.isAPIExist && this.isAPIEnabled; }, enumerable: false, configurable: true }); ChromePictureInPicture.prototype._bindEvents = function () { this._$elem.addEventListener('enterpictureinpicture', this._callback); this._$elem.addEventListener('leavepictureinpicture', this._callback); }; ChromePictureInPicture.prototype._unbindEvents = function () { this._$elem.removeEventListener('enterpictureinpicture', this._callback); this._$elem.removeEventListener('leavepictureinpicture', this._callback); this._$elem.removeEventListener('loadedmetadata', this._enterWhenHasMetaData); }; ChromePictureInPicture.prototype.request = function () { if (!this.isEnabled || this.isInPictureInPicture || isPictureInPictureRequested) { return false; } return this._$elem.requestPictureInPicture().catch(this.catchException); }; ChromePictureInPicture.prototype.exit = function () { if (!this.isEnabled || !this.isInPictureInPicture) { return false; } document.exitPictureInPicture(); }; ChromePictureInPicture.prototype.destroy = function () { this._unbindEvents(); this._$elem = null; }; return ChromePictureInPicture; }()); exports.default = ChromePictureInPicture; //# sourceMappingURL=chrome.js.map