Further migrations to runlevel
This commit is contained in:
parent
a466f77b6e
commit
abeded1d03
@ -73,7 +73,7 @@ class PlayerData {
|
||||
//#endregion
|
||||
|
||||
//#region flags
|
||||
runLevel: RunLevel;
|
||||
runLevel: RunLevel = RunLevel.Off;
|
||||
enabled: boolean;
|
||||
invalid: boolean = false;
|
||||
private periodicallyRefreshPlayerElement: boolean = false;
|
||||
@ -221,20 +221,7 @@ class PlayerData {
|
||||
//#endregion
|
||||
|
||||
/**
|
||||
* Enables ultrawidify for this video by adding the relevant classes
|
||||
* to the video and player element.
|
||||
*/
|
||||
enable() {
|
||||
console.log('enabling UI')
|
||||
this.enabled = true;
|
||||
this.element.classList.add(this.playerCssClass);
|
||||
this.startChangeDetection();
|
||||
this.videoData.enable({fromPlayer: true});
|
||||
this.ui.enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extension runLevel
|
||||
* Sets extension runLevel and sets or unsets appropriate css classes as necessary
|
||||
* @param runLevel
|
||||
* @returns
|
||||
*/
|
||||
@ -264,22 +251,6 @@ class PlayerData {
|
||||
this.runLevel = runLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables ultrawidify for this video by removing the relevant classes
|
||||
* from the video and player elements.
|
||||
*
|
||||
* NOTE: it is very important to keep change detection active while disabled,
|
||||
* because otherwise ultrawidify will otherwise remain inactive after
|
||||
* switching (back to) full screen.
|
||||
*/
|
||||
disable() {
|
||||
console.log('disabling UI')
|
||||
this.enabled = false;
|
||||
this.element.classList.remove(this.playerCssClass);
|
||||
this.videoData.disable({fromPlayer: true});
|
||||
this.ui.disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects whether player element is in theater mode or not.
|
||||
* If theater mode changed, emits event.
|
||||
@ -354,26 +325,14 @@ class PlayerData {
|
||||
// Check if extension is allowed to run in current combination of theater + full screen
|
||||
const canEnable = this.siteSettings.isEnabledForEnvironment(this.isFullscreen, this.isTheaterMode) === ExtensionMode.Enabled;
|
||||
|
||||
// TODO: if canEnable is 'true' and runLevel is OFF, we should
|
||||
// call restoreAr function of resizer and let it figure out the necessary run level.
|
||||
// Function that restores the last user-set AR may also need to be written.
|
||||
|
||||
// Enable/disable
|
||||
if (canEnable) {
|
||||
if (!this.enabled) {
|
||||
// we should really check other constraints first before enabling
|
||||
this.enable();
|
||||
this.handleDimensionChanges(currentPlayerDimensions, this.dimensions);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// if canEnable comes out negative, there's no amount of constraints that will
|
||||
// cause PlayerData to be enabled.
|
||||
if (this.enabled) {
|
||||
this.handleDimensionChanges(currentPlayerDimensions, this.dimensions);
|
||||
this.disable();
|
||||
}
|
||||
return;
|
||||
if (this.runLevel === RunLevel.Off && canEnable) {
|
||||
this.eventBus.send('restore-ar', null);
|
||||
// must be called after
|
||||
this.handleDimensionChanges(currentPlayerDimensions, this.dimensions);
|
||||
} else if (!canEnable && this.runLevel !== RunLevel.Off) {
|
||||
// must be called before
|
||||
this.handleDimensionChanges(currentPlayerDimensions, this.dimensions);
|
||||
this.setRunLevel(RunLevel.Off);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class VideoData {
|
||||
//#region flags
|
||||
arSetupComplete: boolean = false;
|
||||
enabled: boolean;
|
||||
runLevel: RunLevel;
|
||||
runLevel: RunLevel = RunLevel.Off;
|
||||
destroyed: boolean = false;
|
||||
invalid: boolean = false;
|
||||
videoStatusOk: boolean = false;
|
||||
@ -85,6 +85,18 @@ class VideoData {
|
||||
}
|
||||
}
|
||||
|
||||
private eventBusCommands = {
|
||||
'get-drm-status': [{
|
||||
function: () => {
|
||||
this.hasDrm = hasDrm(this.video);
|
||||
this.eventBus.send('uw-config-broadcast', {type: 'drm-status', hasDrm: this.hasDrm});
|
||||
}
|
||||
}],
|
||||
'set-run-level': [{
|
||||
function: (runLevel: RunLevel) => this.setRunLevel(runLevel)
|
||||
}]
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new VideoData object
|
||||
* @param video
|
||||
@ -120,11 +132,12 @@ class VideoData {
|
||||
|
||||
if (pageInfo.eventBus) {
|
||||
this.eventBus.setUpstreamBus(pageInfo.eventBus);
|
||||
this.eventBus.subscribe('get-drm-status', {function: () => {
|
||||
this.hasDrm = hasDrm(this.video);
|
||||
this.eventBus.send('uw-config-broadcast', {type: 'drm-status', hasDrm: this.hasDrm});
|
||||
}});
|
||||
// this.eventBus.subscribe('')
|
||||
|
||||
for (const action in this.eventBusCommands) {
|
||||
for (const command of this.eventBusCommands[action]) {
|
||||
this.eventBus.subscribe(action, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setupEventListeners();
|
||||
@ -251,10 +264,6 @@ class VideoData {
|
||||
this.injectBaseCss();
|
||||
this.pageInfo.initMouseActionHandler(this);
|
||||
|
||||
// aspect ratio autodetection cannot be properly initialized at this time,
|
||||
// so we'll avoid doing that
|
||||
this.enable();
|
||||
|
||||
// start fallback video/player size detection
|
||||
this.fallbackChangeDetection();
|
||||
}
|
||||
@ -344,9 +353,10 @@ class VideoData {
|
||||
this.video.removeEventListener('ontimeupdate', this.onTimeUpdate);
|
||||
}
|
||||
|
||||
this.disable();
|
||||
this.eventBus.send('set-run-level', RunLevel.Off);
|
||||
this.destroyed = true;
|
||||
this.eventBus?.unsetUpstreamBus();
|
||||
|
||||
try {
|
||||
this.arDetector.stop();
|
||||
this.arDetector.destroy();
|
||||
@ -367,32 +377,18 @@ class VideoData {
|
||||
}
|
||||
//#endregion
|
||||
|
||||
/**
|
||||
* Enables ultrawidify in general.
|
||||
* @param options
|
||||
*/
|
||||
enable(options?: {fromPlayer?: boolean}) {
|
||||
this.enabled = true;
|
||||
|
||||
// NOTE — since base class for our <video> element depends on player aspect ratio,
|
||||
// we handle it in PlayerData class.
|
||||
this.video.classList.add(this.baseCssName);
|
||||
this.video.classList.add(this.userCssClassName); // this also needs to be applied BEFORE we initialize resizer! — O RLY? NEEDS TO BE CHECKED
|
||||
|
||||
if (!options?.fromPlayer) {
|
||||
this.player?.enable();
|
||||
}
|
||||
// this.restoreCrop();
|
||||
}
|
||||
|
||||
|
||||
setRunLevel(runLevel: RunLevel, options?: {fromPlayer?: boolean}) {
|
||||
console.log('setting new runlevel for videodata. current:', this.runLevel, 'new', runLevel)
|
||||
if (this.runLevel === runLevel) {
|
||||
return; // also no need to propagate to the player
|
||||
}
|
||||
|
||||
console.log('setting run level ...')
|
||||
|
||||
// Run level decreases towards 'off'
|
||||
if (this.runLevel > runLevel) {
|
||||
console.log('decreasing css.')
|
||||
if (runLevel < RunLevel.CustomCSSActive) {
|
||||
this.video.classList.remove(this.baseCssName);
|
||||
this.video.classList.remove(this.userCssClassName);
|
||||
@ -428,9 +424,6 @@ class VideoData {
|
||||
this.video.classList.remove(this.baseCssName);
|
||||
this.video.classList.remove(this.userCssClassName);
|
||||
|
||||
if (!options?.fromPlayer) {
|
||||
this.player?.disable();
|
||||
}
|
||||
}
|
||||
|
||||
//#region video status
|
||||
|
@ -911,8 +911,6 @@ class Resizer {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.videoData.disable();
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user