Force fallback mode, always.

This commit is contained in:
Tamius Han 2019-09-21 23:50:06 +02:00
parent 469c607568
commit 7b73a42e5c
2 changed files with 52 additions and 1 deletions

View File

@ -86,6 +86,7 @@ class PlayerData {
if (this.invalid) {
return;
}
const ths = this;
this.observer = new MutationObserver((m,o) => this.onPlayerDimensionsChanged(m,o,ths));
@ -96,7 +97,21 @@ class PlayerData {
};
this.observer.observe(this.element, observerConf);
// legacy mode still exists, but acts as a fallback for observers and is triggered less
// frequently in order to avoid too many pointless checks
this.legacyChangeDetection();
}
async legacyChangeDetection() {
while (!this.halted) {
await this.sleep(1000);
if (this.checkPlayerSizeChange()) {
this.videoData.restore();
}
}
}
stopChangeDetection(){
this.observer.disconnect();
}

View File

@ -36,6 +36,11 @@ class VideoData {
return;
}
this.dimensions = {
width: this.video.offsetWidth,
height: this.video.offsetHeight,
};
this.resizer = new Resizer(this);
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
// player dimensions need to be in:
@ -56,7 +61,7 @@ class VideoData {
async fallbackChangeDetection() {
while (!this.destroyed && !this.invalid) {
await this.sleep(1000);
await this.sleep(500);
this.validateVideoOffsets();
}
}
@ -368,6 +373,37 @@ class VideoData {
isPlaying() {
return this.video && this.video.currentTime > 0 && !this.video.paused && !this.video.ended;
}
checkVideoSizeChange(){
const videoWidth = this.video.offsetWidth;
const videoHeight = this.video.offsetHeight;
// this 'if' is just here for debugging — real code starts later. It's safe to collapse and
// ignore the contents of this if (unless we need to change how logging works)
if (this.logger.canLog('debug')){
if(! this.video) {
this.logger.log('info', 'videoDetect', "[VideoDetect] player element isn't defined");
}
if ( this.video && this.dimensions &&
( this.dimensions.width != videoWidth ||
this.dimensions.height != videoHeight )
) {
this.logger.log('info', 'debug', "[VideoDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions.width, this.dimensions.height, "new dimensions:", this.video.offsetWidth, this.video.offsetHeight);
}
}
// if size doesn't match, update & return true
if (!this.dimensions
|| this.dimensions.width != videoWidth
|| this.dimensions.height != videoHeight ){
this.dimensions = {
width: videoWidth,
height: videoHeight,
};
return true;
}
return false;
}
}
export default VideoData;