playable
Version:
Video player based on HTML5Video
80 lines • 3.11 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.INLINE_MODE = exports.PICTURE_IN_PICTURE_MODE = void 0;
var HAVE_METADATA = 1;
exports.PICTURE_IN_PICTURE_MODE = 'picture-in-picture';
exports.INLINE_MODE = 'inline';
var isPictureInPictureRequested = false;
var SafariPictureInPicture = /** @class */ (function () {
function SafariPictureInPicture(elem, callback) {
var _this = this;
this._enterWhenHasMetaData = function () {
_this._$elem.removeEventListener('loadedmetadata', _this._enterWhenHasMetaData);
isPictureInPictureRequested = false;
_this.request();
};
this._$elem = elem;
this._callback = callback;
this._bindEvents();
}
Object.defineProperty(SafariPictureInPicture.prototype, "isAPIExist", {
get: function () {
return Boolean(this._$elem &&
typeof this._$elem.webkitSetPresentationMode === 'function');
},
enumerable: false,
configurable: true
});
Object.defineProperty(SafariPictureInPicture.prototype, "isInPictureInPicture", {
get: function () {
return Boolean(this._$elem &&
this._$elem.webkitPresentationMode === exports.PICTURE_IN_PICTURE_MODE);
},
enumerable: false,
configurable: true
});
Object.defineProperty(SafariPictureInPicture.prototype, "isEnabled", {
get: function () {
return this.isAPIExist;
},
enumerable: false,
configurable: true
});
SafariPictureInPicture.prototype._bindEvents = function () {
this._$elem.addEventListener('webkitpresentationmodechanged', this._callback);
};
SafariPictureInPicture.prototype._unbindEvents = function () {
this._$elem.removeEventListener('webkitpresentationmodechanged', this._callback);
this._$elem.removeEventListener('loadedmetadata', this._enterWhenHasMetaData);
};
SafariPictureInPicture.prototype.request = function () {
if (!this.isEnabled ||
this.isInPictureInPicture ||
isPictureInPictureRequested) {
return false;
}
try {
//NOT FIRING EXEPTION IF NOT TRIGGERED BY USER GESTURE
this._$elem.webkitSetPresentationMode(exports.PICTURE_IN_PICTURE_MODE);
}
catch (e) {
if (this._$elem.readyState < HAVE_METADATA) {
this._$elem.addEventListener('loadedmetadata', this._enterWhenHasMetaData);
isPictureInPictureRequested = true;
}
}
};
SafariPictureInPicture.prototype.exit = function () {
if (!this.isEnabled || !this.isInPictureInPicture) {
return false;
}
this._$elem.webkitSetPresentationMode(exports.INLINE_MODE);
};
SafariPictureInPicture.prototype.destroy = function () {
this._unbindEvents();
this._$elem = null;
};
return SafariPictureInPicture;
}());
exports.default = SafariPictureInPicture;
//# sourceMappingURL=safari.js.map