vidstack
Version:
Build awesome media experiences on the web.
77 lines (74 loc) • 2.19 kB
JavaScript
import { listenEvent, DOMEvent } from 'maverick.js/std';
import { X as canUseVideoPresentation } from '../../../media-core.js';
class VideoPresentation {
constructor(_video, _media) {
this._video = _video;
this._media = _media;
this._mode = "inline";
listenEvent(this._video, "webkitpresentationmodechanged", this._onModeChange.bind(this));
}
get _supported() {
return canUseVideoPresentation(this._video);
}
async _setPresentationMode(mode) {
if (this._mode === mode)
return;
this._video.webkitSetPresentationMode(mode);
}
_onModeChange() {
const prevMode = this._mode;
this._mode = this._video.webkitPresentationMode;
{
this._media.logger?.infoGroup("presentation mode change").labelledLog("Mode", this._mode).labelledLog("Event", event).dispatch();
}
this._media.player?.dispatchEvent(
new DOMEvent("video-presentation-change", {
detail: this._mode,
trigger: event
})
);
["fullscreen", "picture-in-picture"].forEach((type) => {
if (this._mode === type || prevMode === type) {
this._media.delegate._dispatch(`${type}-change`, {
detail: this._mode === type,
trigger: event
});
}
});
}
}
class FullscreenPresentationAdapter {
constructor(_presentation) {
this._presentation = _presentation;
}
get active() {
return this._presentation._mode === "fullscreen";
}
get supported() {
return this._presentation._supported;
}
async enter() {
this._presentation._setPresentationMode("fullscreen");
}
async exit() {
this._presentation._setPresentationMode("inline");
}
}
class PIPPresentationAdapter {
constructor(_presentation) {
this._presentation = _presentation;
}
get active() {
return this._presentation._mode === "picture-in-picture";
}
get supported() {
return this._presentation._supported;
}
async enter() {
this._presentation._setPresentationMode("picture-in-picture");
}
async exit() {
this._presentation._setPresentationMode("inline");
}
}
export { FullscreenPresentationAdapter as F, PIPPresentationAdapter as P, VideoPresentation as V };