Minor fixes

This commit is contained in:
Tamius Han 2019-09-03 23:49:22 +02:00
parent 59df28029f
commit 66bcc40fb4
4 changed files with 89 additions and 85 deletions

View File

@ -62,7 +62,7 @@ class CommsClient {
if (message.cmd === "set-ar") { if (message.cmd === "set-ar") {
this.pageInfo.setAr({type: message.arg, ratio: message.customArg}, message.playing); this.pageInfo.setAr({type: message.arg, ratio: message.customArg}, message.playing);
} else if (message.cmd === 'set-alignment') { } else if (message.cmd === 'set-alignment') {
this.pageInfo.setvideoAlignment(message.arg, message.playing); this.pageInfo.setVideoAlignment(message.arg, message.playing);
this.pageInfo.restoreAr(); this.pageInfo.restoreAr();
} else if (message.cmd === "set-stretch") { } else if (message.cmd === "set-stretch") {
this.pageInfo.setStretchMode(message.arg, message.playing); this.pageInfo.setStretchMode(message.arg, message.playing);

View File

@ -140,85 +140,89 @@ class PageInfo {
try{ try{
var vids = this.getVideos(window.location.host); var vids = this.getVideos(window.location.host);
if(!vids || vids.length == 0){ if(!vids || vids.length == 0){
this.hasVideos = false;
if(rescanReason == RescanReason.PERIODIC){
this.logger.log('info', 'videoRescan', "[PageInfo::rescan] Scheduling normal rescan.")
this.scheduleRescan(RescanReason.PERIODIC);
}
return;
}
// add new videos
this.hasVideos = false; this.hasVideos = false;
var videoExists = false;
if(rescanReason == RescanReason.PERIODIC){ var video, v;
this.logger.log('info', 'videoRescan', "[PageInfo::rescan] Scheduling normal rescan.")
this.scheduleRescan(RescanReason.PERIODIC);
}
return;
}
// add new videos for (video of vids) {
this.hasVideos = false; // če najdemo samo en video z višino in širino, to pomeni, da imamo na strani veljavne videe
var videoExists = false; // če trenutni video nima definiranih teh vrednostih, preskočimo vse nadaljnja preverjanja
var video, v; // <===[:::::::]===>
// if we find even a single video with width and height, that means the page has valid videos
// if video lacks either of the two properties, we skip all further checks cos pointless
if(video.offsetWidth && video.offsetHeight){
this.hasVideos = true;
for (video of vids) { if (this.readOnly) {
// če najdemo samo en video z višino in širino, to pomeni, da imamo na strani veljavne videe // in lite mode, we're done. This is all the info we want, but we want to actually start doing
// če trenutni video nima definiranih teh vrednostih, preskočimo vse nadaljnja preverjanja // things that interfere with the website. We still want to be runnig a rescan, tho.
// <===[:::::::]===>
// if we find even a single video with width and height, that means the page has valid videos
// if video lacks either of the two properties, we skip all further checks cos pointless
if(video.offsetWidth && video.offsetHeight){
this.hasVideos = true;
if (this.readOnly) { if(rescanReason == RescanReason.PERIODIC){
// in lite mode, we're done. This is all the info we want, but we want to actually start doing this.scheduleRescan(RescanReason.PERIODIC);
// things that interfere with the website. We still want to be runnig a rescan, tho. }
return;
if(rescanReason == RescanReason.PERIODIC){
this.scheduleRescan(RescanReason.PERIODIC);
} }
return;
}
} else {
continue;
}
videoExists = false;
for (v of this.videos) {
if (v.destroyed) {
continue; //TODO: if destroyed video is same as current video, copy aspect ratio settings to current video
}
if (v.video == video) {
videoExists = true;
break;
}
}
if (videoExists) {
continue;
} else {
this.logger.log('info', 'videoRescan', "[PageInfo::rescan] found new video candidate:", video, "NOTE:: Video initialization starts here:\n--------------------------------\n")
v = new VideoData(video, this.settings, this);
v.initArDetection();
this.videos.push(v);
this.logger.log('info', 'videoRescan', "END VIDEO INITIALIZATION\n\n\n-------------------------------------\nvideos[] is now this:", this.videos,"\n\n\n\n\n\n\n\n")
}
}
this.removeDestroyed();
// če smo ostali brez videev, potem odregistriraj stran.
// če nismo ostali brez videev, potem registriraj stran.
//
// if we're left withotu videos on the current page, we unregister the page.
// if we have videos, we call register.
if (this.comms) {
if (this.videos.length != oldVideoCount) { // only if number of videos changed, tho
if (this.videos.length > 0) {
this.comms.registerVideo({host: window.location.host, location: window.location});
} else { } else {
this.comms.unregisterVideo({host: window.location.host, location: window.location}); continue;
}
videoExists = false;
for (v of this.videos) {
if (v.destroyed) {
continue; //TODO: if destroyed video is same as current video, copy aspect ratio settings to current video
}
if (v.video == video) {
videoExists = true;
break;
}
}
if (videoExists) {
continue;
} else {
this.logger.log('info', 'videoRescan', "[PageInfo::rescan] found new video candidate:", video, "NOTE:: Video initialization starts here:\n--------------------------------\n")
try {
v = new VideoData(video, this.settings, this);
v.initArDetection();
this.videos.push(v);
} catch (e) {
this.logger.log('error', 'debug', "rescan error: failed to initialize videoData. Skipping this video.",e);
}
this.logger.log('info', 'videoRescan', "END VIDEO INITIALIZATION\n\n\n-------------------------------------\nvideos[] is now this:", this.videos,"\n\n\n\n\n\n\n\n")
}
}
this.removeDestroyed();
// če smo ostali brez videev, potem odregistriraj stran.
// če nismo ostali brez videev, potem registriraj stran.
//
// if we're left withotu videos on the current page, we unregister the page.
// if we have videos, we call register.
if (this.comms) {
if (this.videos.length != oldVideoCount) { // only if number of videos changed, tho
if (this.videos.length > 0) {
this.comms.registerVideo({host: window.location.host, location: window.location});
} else {
this.comms.unregisterVideo({host: window.location.host, location: window.location});
}
} }
} }
}
} catch(e) { } catch(e) {
// če pride do zajeba, potem lahko domnevamo da na strani ni nobenega videa. Uničimo vse objekte videoData // če pride do zajeba, potem lahko domnevamo da na strani ni nobenega videa. Uničimo vse objekte videoData
@ -275,8 +279,8 @@ class PageInfo {
var ths = this; var ths = this;
this.rescanTimer = setTimeout(function(){ this.urlCheckTimer = setTimeout(function(){
ths.rescanTimer = null; ths.urlCheckTimer = null;
ths.ghettoUrlCheck(); ths.ghettoUrlCheck();
ths = null; ths = null;
}, this.settings.active.pageInfo.timeouts.urlCheck) }, this.settings.active.pageInfo.timeouts.urlCheck)
@ -418,16 +422,16 @@ class PageInfo {
} }
} }
setvideoAlignment(videoAlignment, playingOnly) { setVideoAlignment(videoAlignment, playingOnly) {
if (playingOnly) { if (playingOnly) {
for(var vd of this.videos) { for(var vd of this.videos) {
if (vd.isPlaying()) { if (vd.isPlaying()) {
vd.setvideoAlignment(videoAlignment) vd.setVideoAlignment(videoAlignment)
} }
} }
} else { } else {
for(var vd of this.videos) { for(var vd of this.videos) {
vd.setvideoAlignment(videoAlignment) vd.setVideoAlignment(videoAlignment)
} }
} }
} }

View File

@ -6,6 +6,7 @@ import ArDetector from '../ar-detect/ArDetector';
class VideoData { class VideoData {
constructor(video, settings, pageInfo){ constructor(video, settings, pageInfo){
this.vdid = (Math.random()*100).toFixed();
this.logger = pageInfo.logger; this.logger = pageInfo.logger;
this.arSetupComplete = false; this.arSetupComplete = false;
this.video = video; this.video = video;
@ -14,7 +15,6 @@ class VideoData {
this.pageInfo = pageInfo; this.pageInfo = pageInfo;
this.extensionMode = pageInfo.extensionMode; this.extensionMode = pageInfo.extensionMode;
this.vdid = (Math.random()*100).toFixed();
this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`; this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`;
@ -244,8 +244,8 @@ class VideoData {
this.resizer.setPanMode(mode); this.resizer.setPanMode(mode);
} }
setvideoAlignment(videoAlignment) { setVideoAlignment(videoAlignment) {
this.resizer.setvideoAlignment(videoAlignment); this.resizer.setVideoAlignment(videoAlignment);
} }
restoreAr(){ restoreAr(){

View File

@ -15,6 +15,7 @@ if(Debug.debug) {
class Resizer { class Resizer {
constructor(videoData) { constructor(videoData) {
this.resizerId = (Math.random(99)*100).toFixed(0);
this.conf = videoData; this.conf = videoData;
this.logger = videoData.logger; this.logger = videoData.logger;
this.video = videoData.video; this.video = videoData.video;
@ -37,7 +38,6 @@ class Resizer {
this.videoAlignment = this.settings.getDefaultVideoAlignment(window.location.hostname); // this is initial video alignment this.videoAlignment = this.settings.getDefaultVideoAlignment(window.location.hostname); // this is initial video alignment
this.destroyed = false; this.destroyed = false;
this.resizerId = (Math.random(99)*100).toFixed(0);
if (this.settings.active.pan) { if (this.settings.active.pan) {
this.canPan = this.settings.active.miscSettings.mousePan.enabled; this.canPan = this.settings.active.miscSettings.mousePan.enabled;
@ -194,8 +194,8 @@ class Resizer {
this.conf.destroy(); this.conf.destroy();
} }
// // pause AR on basic stretch, unpause when using other mdoes // pause AR on basic stretch, unpause when using other modes
// fir sine reason unpause doesn't unpause. investigate that later // for sine reason unpause doesn't unpause. investigate that later
try { try {
if (this.stretcher.mode === Stretch.Basic) { if (this.stretcher.mode === Stretch.Basic) {
this.conf.arDetector.pause(); this.conf.arDetector.pause();
@ -218,7 +218,7 @@ class Resizer {
this.conf.destroy(); this.conf.destroy();
} }
if (stretchFactors.error === 'illegal_video_dimensions') { if (stretchFactors.error === 'illegal_video_dimensions') {
this.loggger.log('error', 'debug', `[Resizer::setAr] <rid:${this.resizerId}> Illegal video dimensions found. We will pause everything.`) this.logger.log('error', 'debug', `[Resizer::setAr] <rid:${this.resizerId}> Illegal video dimensions found. We will pause everything.`)
} }
return; return;
} }
@ -300,7 +300,7 @@ class Resizer {
this.restore(); this.restore();
} }
setvideoAlignment(videoAlignment) { setVideoAlignment(videoAlignment) {
this.videoAlignment = videoAlignment; this.videoAlignment = videoAlignment;
this.restore(); this.restore();
} }