import Debug from '../../conf/Debug'; import PlayerData from './PlayerData'; import Resizer from '../video-transform/Resizer'; import ArDetector from '../ar-detect/ArDetector'; import AspectRatio from '../../../common/enums/aspect-ratio.enum'; class VideoData { constructor(video, settings, pageInfo){ this.vdid = (Math.random()*100).toFixed(); this.logger = pageInfo.logger; this.arSetupComplete = false; this.video = video; this.destroyed = false; this.settings = settings; this.pageInfo = pageInfo; this.extensionMode = pageInfo.extensionMode; this.videoStatusOk = false; this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`; this.videoLoaded = false; this.videoDimensionsLoaded = true; this.dimensions = { width: this.video.offsetWidth, height: this.video.offsetHeight, }; this.setupStageOne(); } async onVideoLoaded() { if (!this.videoLoaded) { if (!this.video.videoWidth || !this.video.videoHeight) { return; // onVideoLoaded is a lie in this case } this.logger.log('info', 'init', '%c[VideoData::onVideoLoaded] ——————————— Initiating phase two of videoData setup ———————————', 'color: #0f9'); this.videoLoaded = true; this.videoDimensionsLoaded = true; try { await this.setupStageTwo(); this.logger.log('info', 'init', '%c[VideoData::onVideoLoaded] ——————————— videoData setup stage two complete ———————————', 'color: #0f9'); } catch (e) { this.logger.log('error', 'init', '%c[VideoData::onVideoLoaded] ——————————— Setup stage two failed. ———————————\n', 'color: #f00', e); } } else if (!this.videoDimensionsLoaded) { this.logger.log('info', 'debug', "%c[VideoData::restoreCrop] Recovering from illegal video dimensions. Resetting aspect ratio.", "background: #afd, color: #132"); this.restoreCrop(); this.videoDimensionsLoaded = true; } } videoUnloaded() { this.videoLoaded = false; } async injectBaseCss() { try { await this.pageInfo.injectCss(` .uw-ultrawidify-base-wide-screen { margin: 0px 0px 0px 0px !important; width: initial !important; align-self: start !important; justify-self: start !important; } `); } catch (e) { console.error('Failed to inject base css!', e); } } unsetBaseClass() { this.video.classList.remove('uw-ultrawidify-base-wide-screen'); } //#region