Replace consoles in ext with custom logger
This commit is contained in:
parent
f0fa6aa9a8
commit
338afad417
@ -2,6 +2,46 @@
|
|||||||
// version: {ExtensionConf object, but only properties that get overwritten}
|
// version: {ExtensionConf object, but only properties that get overwritten}
|
||||||
|
|
||||||
const ExtensionConfPatch = {
|
const ExtensionConfPatch = {
|
||||||
|
'4.3.0': {
|
||||||
|
sites: {
|
||||||
|
"old.reddit.com" : {
|
||||||
|
type: 'testing',
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
querySelectors: '.media-preview-content'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: '',
|
||||||
|
},
|
||||||
|
"www.reddit.com" : {
|
||||||
|
type: 'testing',
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
querySelectors: '.media-preview-content'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: '',
|
||||||
|
},
|
||||||
|
"www.youtube.com" : {
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
querySelectors: "#movie_player, #player",
|
||||||
|
additionalCss: "",
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
playerNodeCss: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"www.netflix.com" : {
|
||||||
|
arPersistance: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
'4.2.1': {
|
'4.2.1': {
|
||||||
sites: {
|
sites: {
|
||||||
"old.reddit.com" : {
|
"old.reddit.com" : {
|
||||||
|
@ -915,6 +915,7 @@ whatsNewChecked: true,
|
|||||||
stretch: Stretch.Default,
|
stretch: Stretch.Default,
|
||||||
videoAlignment: VideoAlignment.Default,
|
videoAlignment: VideoAlignment.Default,
|
||||||
keyboardShortcutsEnabled: ExtensionMode.Default,
|
keyboardShortcutsEnabled: ExtensionMode.Default,
|
||||||
|
arPersistence: true, // persist aspect ratio between different videos
|
||||||
autoarPreventConditions: { // prevents autoar on following conditions
|
autoarPreventConditions: { // prevents autoar on following conditions
|
||||||
videoStyleString: { // if video style string thing does anything of what follows
|
videoStyleString: { // if video style string thing does anything of what follows
|
||||||
containsProperty: { // if video style string has any of these properties (listed as keys)
|
containsProperty: { // if video style string has any of these properties (listed as keys)
|
||||||
|
@ -4,18 +4,17 @@ import ExtensionMode from '../../common/enums/extension-mode.enum';
|
|||||||
|
|
||||||
class ActionHandler {
|
class ActionHandler {
|
||||||
|
|
||||||
constructor(pageInfo) {
|
constructor(pageInfo, logger) {
|
||||||
this.pageInfo = pageInfo;
|
this.pageInfo = pageInfo;
|
||||||
this.settings = pageInfo.settings;
|
this.settings = pageInfo.settings;
|
||||||
|
|
||||||
this.inputs = ['input', 'select', 'button', 'textarea'];
|
this.inputs = ['input', 'select', 'button', 'textarea'];
|
||||||
this.keyboardLocalDisabled = false;
|
this.keyboardLocalDisabled = false;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[ActionHandler::init] starting init");
|
||||||
console.log("[ActionHandler::init] starting init");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.keyUpActions = [];
|
this.keyUpActions = [];
|
||||||
this.keyDownActions = [];
|
this.keyDownActions = [];
|
||||||
@ -105,15 +104,13 @@ class ActionHandler {
|
|||||||
document.addEventListener('keyup', (event) => ths.handleKeyup(event) );
|
document.addEventListener('keyup', (event) => ths.handleKeyup(event) );
|
||||||
|
|
||||||
this.pageInfo.setActionHandler(this);
|
this.pageInfo.setActionHandler(this);
|
||||||
if (Debug.debug) {
|
|
||||||
console.log("[ActionHandler::init] initialization complete");
|
this.logger.log('info', 'debug', "[ActionHandler::init] initialization complete");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerHandleMouse(videoData) {
|
registerHandleMouse(videoData) {
|
||||||
if (Debug.debug && Debug.mousemove) {
|
this.logger.log('info', ['actionHandler', 'mousemove'], "[ActionHandler::registerHandleMouse] registering handle mouse for videodata:", videoData)
|
||||||
console.log("[ActionHandler::registerHandleMouse] registering handle mouse for videodata:", videoData)
|
|
||||||
}
|
|
||||||
var ths = this;
|
var ths = this;
|
||||||
if (videoData.player && videoData.player.element) {
|
if (videoData.player && videoData.player.element) {
|
||||||
videoData.player.element.addEventListener('mousemove', (event) => ths.handleMouseMove(event, videoData));
|
videoData.player.element.addEventListener('mousemove', (event) => ths.handleMouseMove(event, videoData));
|
||||||
@ -133,10 +130,10 @@ class ActionHandler {
|
|||||||
preventAction() {
|
preventAction() {
|
||||||
var activeElement = document.activeElement;
|
var activeElement = document.activeElement;
|
||||||
|
|
||||||
if(Debug.debug && Debug.keyboard) {
|
if(this.logger.canLog('keyboard')) {
|
||||||
Debug.debug = false; // temp disable to avoid recursing;
|
this.logger.pause(); // temp disable to avoid recursing;
|
||||||
|
|
||||||
console.log("[ActionHandler::preventAction] Testing whether we're in a textbox or something. Detailed rundown of conditions:\n" +
|
this.logger.log('info', 'keyboard', "[ActionHandler::preventAction] Testing whether we're in a textbox or something. Detailed rundown of conditions:\n" +
|
||||||
"is full screen? (yes->allow):", PlayerData.isFullScreen(),
|
"is full screen? (yes->allow):", PlayerData.isFullScreen(),
|
||||||
"\nis tag one of defined inputs? (yes->prevent):", this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1,
|
"\nis tag one of defined inputs? (yes->prevent):", this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1,
|
||||||
"\nis role = textbox? (yes -> prevent):", activeElement.getAttribute("role") === "textbox",
|
"\nis role = textbox? (yes -> prevent):", activeElement.getAttribute("role") === "textbox",
|
||||||
@ -151,7 +148,7 @@ class ActionHandler {
|
|||||||
"insta-fail inputs:", this.inputs
|
"insta-fail inputs:", this.inputs
|
||||||
);
|
);
|
||||||
|
|
||||||
Debug.debug = true; // undisable
|
this.logger.resume(); // undisable
|
||||||
}
|
}
|
||||||
|
|
||||||
// lately youtube has allowed you to read and write comments while watching video in
|
// lately youtube has allowed you to read and write comments while watching video in
|
||||||
@ -187,15 +184,11 @@ class ActionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
execAction(actions, event, videoData) {
|
execAction(actions, event, videoData) {
|
||||||
if(Debug.debug && Debug.keyboard ){
|
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event);
|
||||||
console.log("%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var action of actions) {
|
for (var action of actions) {
|
||||||
if (this.isActionMatch(action.shortcut, event)) {
|
if (this.isActionMatch(action.shortcut, event)) {
|
||||||
if(Debug.debug && Debug.keyboard ){
|
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] found an action associated with keypress/event: ", "color: #ff0", action);
|
||||||
console.log("%c[ActionHandler::execAction] found an action associated with keypress/event: ", "color: #ff0", action);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var cmd of action.cmd) {
|
for (var cmd of action.cmd) {
|
||||||
if (action.scope === 'page') {
|
if (action.scope === 'page') {
|
||||||
@ -243,14 +236,10 @@ class ActionHandler {
|
|||||||
|
|
||||||
|
|
||||||
handleKeyup(event) {
|
handleKeyup(event) {
|
||||||
if(Debug.debug && Debug.keyboard ){
|
this.logger.log('info', 'keyboard', "%c[ActionHandler::handleKeyup] we pressed a key: ", "color: #ff0", event.key , " | keyup: ", event.keyup, "event:", event);
|
||||||
console.log("%c[ActionHandler::handleKeyup] we pressed a key: ", "color: #ff0", event.key , " | keyup: ", event.keyup, "event:", event);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.preventAction()) {
|
if (this.preventAction()) {
|
||||||
if (Debug.debug && Debug.keyboard) {
|
this.logger.log('info', 'keyboard', "[ActionHandler::handleKeyup] we are in a text box or something. Doing nothing.");
|
||||||
console.log("[ActionHandler::handleKeyup] we are in a text box or something. Doing nothing.");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,9 +252,7 @@ class ActionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.preventAction()) {
|
if (this.preventAction()) {
|
||||||
if (Debug.debug && Debug.keyboard) {
|
this.logger.log('info', 'keyboard', "[ActionHandler::handleKeydown] we are in a text box or something. Doing nothing.");
|
||||||
console.log("[ActionHandler::handleKeydown] we are in a text box or something. Doing nothing.");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,9 +260,7 @@ class ActionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleMouseMove(event, videoData) {
|
handleMouseMove(event, videoData) {
|
||||||
if (Debug.debug && Debug.mousemove) {
|
this.logger.log('info', 'keyboard', "[ActionHandler::handleMouseMove] mouse move is being handled.\nevent:", event, "\nvideo data:", videoData);
|
||||||
console.log("[ActionHandler::handleMouseMove] mouse move is being handled.\nevent:", event, "\nvideo data:", videoData);
|
|
||||||
}
|
|
||||||
videoData.panHandler(event);
|
videoData.panHandler(event);
|
||||||
this.execAction(this.mouseMoveActions, event, videoData)
|
this.execAction(this.mouseMoveActions, event, videoData)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ class Logger {
|
|||||||
this.conf = conf;
|
this.conf = conf;
|
||||||
this.history = [];
|
this.history = [];
|
||||||
this.startTime = performance.now();
|
this.startTime = performance.now();
|
||||||
|
this.temp_disable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
@ -39,7 +40,34 @@ class Logger {
|
|||||||
return logfileStr;
|
return logfileStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pause() {
|
||||||
|
this.temp_disable = true;
|
||||||
|
}
|
||||||
|
resume() {
|
||||||
|
this.temp_disable = false;
|
||||||
|
}
|
||||||
|
|
||||||
canLog(component) {
|
canLog(component) {
|
||||||
|
return this.canLogFile(component) || this.canLogConsole(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
canLogFile(component) {
|
||||||
|
if (!this.conf.fileOptions.enabled || this.temp_disable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (component.length ) {
|
||||||
|
for (const c in component) {
|
||||||
|
if (this.conf.fileOptions[component]) {
|
||||||
|
return this.conf.fileOptions[component];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.conf.fileOptions[component];
|
||||||
|
}
|
||||||
|
canLogConsole(component) {
|
||||||
|
if (!this.conf.consoleOptions.enabled || this.temp_disable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (component.length) {
|
if (component.length) {
|
||||||
for (const c in component) {
|
for (const c in component) {
|
||||||
if (this.conf.fileOptions[component]) {
|
if (this.conf.fileOptions[component]) {
|
||||||
@ -58,7 +86,7 @@ class Logger {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.conf.logToFile) {
|
if (this.conf.logToFile) {
|
||||||
if (this.canLog(component)) {
|
if (this.canLogFile(component)) {
|
||||||
let ts = performance.now();
|
let ts = performance.now();
|
||||||
if (ts <= this.history[this.history.length - 1]) {
|
if (ts <= this.history[this.history.length - 1]) {
|
||||||
ts = this.history[this.history.length - 1] + 0.00001;
|
ts = this.history[this.history.length - 1] + 0.00001;
|
||||||
@ -71,7 +99,7 @@ class Logger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.conf.logToConsole) {
|
if (this.conf.logToConsole) {
|
||||||
if (this.canLog(component)) {
|
if (this.canLogConsole(component)) {
|
||||||
console.log(...message);
|
console.log(...message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import Debug from '../../conf/Debug';
|
|||||||
import BrowserDetect from '../../conf/BrowserDetect';
|
import BrowserDetect from '../../conf/BrowserDetect';
|
||||||
|
|
||||||
class CommsClient {
|
class CommsClient {
|
||||||
constructor(name, settings) {
|
constructor(name, settings, logger) {
|
||||||
if (BrowserDetect.firefox) {
|
if (BrowserDetect.firefox) {
|
||||||
this.port = browser.runtime.connect({name: name});
|
this.port = browser.runtime.connect({name: name});
|
||||||
} else if (BrowserDetect.chrome) {
|
} else if (BrowserDetect.chrome) {
|
||||||
@ -18,6 +18,7 @@ class CommsClient {
|
|||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.pageInfo = undefined;
|
this.pageInfo = undefined;
|
||||||
this.commsId = (Math.random() * 20).toFixed(0);
|
this.commsId = (Math.random() * 20).toFixed(0);
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
@ -32,9 +33,7 @@ class CommsClient {
|
|||||||
|
|
||||||
this.pageInfo = pageInfo;
|
this.pageInfo = pageInfo;
|
||||||
|
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'debug', `[CommsClient::setPageInfo] <${this.commsId}>`, "SETTING PAGEINFO —", this.pageInfo, this)
|
||||||
console.log(`[CommsClient::setPageInfo] <${this.commsId}>`, "SETTING PAGEINFO —", this.pageInfo, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ths = this;
|
var ths = this;
|
||||||
this._listener = m => ths.processReceivedMessage(m);
|
this._listener = m => ths.processReceivedMessage(m);
|
||||||
@ -46,17 +45,13 @@ class CommsClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processReceivedMessage(message){
|
processReceivedMessage(message){
|
||||||
if(Debug.debug && Debug.comms){
|
this.logger.log('info', 'comms', `[CommsClient.js::processMessage] <${this.commsId}> Received message from background script!`, message);
|
||||||
console.log(`[CommsClient.js::processMessage] <${this.commsId}> Received message from background script!`, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.pageInfo || !this.settings.active) {
|
if (!this.pageInfo || !this.settings.active) {
|
||||||
if(Debug.debug && Debug.comms){
|
this.logger.log('info', 'comms', `[CommsClient.js::processMessage] <${this.commsId}> this.pageInfo (or settings) not defined. Extension is probably disabled for this site.\npageInfo:`, this.pageInfo,
|
||||||
console.log(`[CommsClient.js::processMessage] <${this.commsId}> this.pageInfo (or settings) not defined. Extension is probably disabled for this site.\npageInfo:`, this.pageInfo,
|
"\nsettings.active:", this.settings.active,
|
||||||
"\nsettings.active:", this.settings.active,
|
"\nnobj:", this
|
||||||
"\nnobj:", this
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,13 +130,11 @@ class CommsClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async requestSettings(){
|
async requestSettings(){
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'comms', "%c[CommsClient::requestSettings] sending request for congif!", "background: #11D; color: #aad");
|
||||||
console.log("%c[CommsClient::requestSettings] sending request for congif!", "background: #11D; color: #aad");
|
|
||||||
}
|
|
||||||
var response = await this.sendMessage_nonpersistent({cmd: 'get-config'});
|
var response = await this.sendMessage_nonpersistent({cmd: 'get-config'});
|
||||||
if(Debug.debug){
|
|
||||||
console.log("%c[CommsClient::requestSettings] received settings response!", "background: #11D; color: #aad", response);
|
this.logger.log('info', 'comms', "%c[CommsClient::requestSettings] received settings response!", "background: #11D; color: #aad", response);
|
||||||
}
|
|
||||||
|
|
||||||
if(! response || response.extensionConf){
|
if(! response || response.extensionConf){
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
@ -156,9 +149,7 @@ class CommsClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerVideo(){
|
registerVideo(){
|
||||||
if (Debug.debug && Debug.comms) {
|
this.logger.log('info', 'comms', `[CommsClient::registerVideo] <${this.commsId}>`, "Registering video for current page.");
|
||||||
console.log(`[CommsClient::registerVideo] <${this.commsId}>`, "Registering video for current page.");
|
|
||||||
}
|
|
||||||
if (this.pageInfo) {
|
if (this.pageInfo) {
|
||||||
if (this.pageInfo.hasVideo()) {
|
if (this.pageInfo.hasVideo()) {
|
||||||
this.port.postMessage({cmd: "has-video"});
|
this.port.postMessage({cmd: "has-video"});
|
||||||
@ -173,9 +164,7 @@ class CommsClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unregisterVideo(){
|
unregisterVideo(){
|
||||||
if (Debug.debug && Debug.comms) {
|
this.logger.log('info', 'comms', `[CommsClient::unregisterVideo] <${this.commsId}>`, "Unregistering video for current page.");
|
||||||
console.log(`[CommsClient::unregisterVideo] <${this.commsId}>`, "Unregistering video for current page.");
|
|
||||||
}
|
|
||||||
this.port.postMessage({cmd: "noVideo"}); // ayymd
|
this.port.postMessage({cmd: "noVideo"}); // ayymd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ if(Debug.debug)
|
|||||||
|
|
||||||
|
|
||||||
class PageInfo {
|
class PageInfo {
|
||||||
constructor(comms, settings, extensionMode, readOnly = false){
|
constructor(comms, settings, logger, extensionMode, readOnly = false){
|
||||||
this.hasVideos = false;
|
this.hasVideos = false;
|
||||||
this.siteDisabled = false;
|
this.siteDisabled = false;
|
||||||
this.videos = [];
|
this.videos = [];
|
||||||
@ -20,6 +20,8 @@ class PageInfo {
|
|||||||
this.extensionMode = extensionMode;
|
this.extensionMode = extensionMode;
|
||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
|
|
||||||
|
this.logger = logger;
|
||||||
|
|
||||||
if (comms){
|
if (comms){
|
||||||
this.comms = comms;
|
this.comms = comms;
|
||||||
}
|
}
|
||||||
@ -42,9 +44,7 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if(Debug.debug || Debug.init){
|
this.logger.log('info', ['debug', 'init'], "[PageInfo::destroy] destroying all videos!")
|
||||||
console.log("[PageInfo::destroy] destroying all videos!")
|
|
||||||
}
|
|
||||||
if(this.rescanTimer){
|
if(this.rescanTimer){
|
||||||
clearTimeout(this.rescanTimer);
|
clearTimeout(this.rescanTimer);
|
||||||
}
|
}
|
||||||
@ -118,9 +118,7 @@ class PageInfo {
|
|||||||
this.hasVideos = false;
|
this.hasVideos = false;
|
||||||
|
|
||||||
if(rescanReason == RescanReason.PERIODIC){
|
if(rescanReason == RescanReason.PERIODIC){
|
||||||
if (Debug.debug && Debug.videoRescan && Debug.periodic) {
|
this.logger.log('info', 'videoRescan', "[PageInfo::rescan] Scheduling normal rescan.")
|
||||||
console.log("[PageInfo::rescan] Scheduling normal rescan:")
|
|
||||||
}
|
|
||||||
this.scheduleRescan(RescanReason.PERIODIC);
|
this.scheduleRescan(RescanReason.PERIODIC);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -169,18 +167,14 @@ class PageInfo {
|
|||||||
if (videoExists) {
|
if (videoExists) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (Debug.debug && Debug.periodic && Debug.videoRescan) {
|
this.logger.log('info', 'videoRescan', "[PageInfo::rescan] found new video candidate:", video, "NOTE:: Video initialization starts here:\n--------------------------------\n")
|
||||||
console.log("[PageInfo::rescan] found new video candidate:", video, "NOTE:: Video initialization starts here:\n--------------------------------\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
v = new VideoData(video, this.settings, this);
|
v = new VideoData(video, this.settings, this, logger);
|
||||||
// console.log("[PageInfo::rescan] v is:", v)
|
// console.log("[PageInfo::rescan] v is:", v)
|
||||||
v.initArDetection();
|
v.initArDetection();
|
||||||
this.videos.push(v);
|
this.videos.push(v);
|
||||||
|
|
||||||
if(Debug.debug && Debug.periodic && Debug.videoRescan){
|
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")
|
||||||
console.log("[PageInfo::rescan] END VIDEO INITIALIZATION\n\n\n-------------------------------------\nvideos[] is now this:", this.videos,"\n\n\n\n\n\n\n\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,9 +206,7 @@ class PageInfo {
|
|||||||
// if we encounter a fuckup, we can assume that no videos were found on the page. We destroy all videoData
|
// if we encounter a fuckup, we can assume that no videos were found on the page. We destroy all videoData
|
||||||
// objects to prevent multiple initalization (which happened, but I don't know why). No biggie if we destroyed
|
// objects to prevent multiple initalization (which happened, but I don't know why). No biggie if we destroyed
|
||||||
// videoData objects in error — they'll be back in the next rescan
|
// videoData objects in error — they'll be back in the next rescan
|
||||||
if (Debug.debug) {
|
this.logger.log('error', 'debug', "rescan error: — destroying all videoData objects",e);
|
||||||
console.log("rescan error: — destroying all videoData objects",e);
|
|
||||||
}
|
|
||||||
for (const v of this.videos) {
|
for (const v of this.videos) {
|
||||||
v.destroy();
|
v.destroy();
|
||||||
}
|
}
|
||||||
@ -249,9 +241,7 @@ class PageInfo {
|
|||||||
ths = null;
|
ths = null;
|
||||||
}, this.settings.active.pageInfo.timeouts.rescan, RescanReason.PERIODIC)
|
}, this.settings.active.pageInfo.timeouts.rescan, RescanReason.PERIODIC)
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if(Debug.debug){
|
this.logger.log('error', 'debug', "[PageInfo::scheduleRescan] scheduling rescan failed. Here's why:",e)
|
||||||
console.log("[PageInfo::scheduleRescan] scheduling rescan failed. Here's why:",e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,17 +259,13 @@ class PageInfo {
|
|||||||
ths = null;
|
ths = null;
|
||||||
}, this.settings.active.pageInfo.timeouts.urlCheck)
|
}, this.settings.active.pageInfo.timeouts.urlCheck)
|
||||||
} catch(e){
|
} catch(e){
|
||||||
if(Debug.debug){
|
this.logger.log('error', 'debug', "[PageInfo::scheduleUrlCheck] scheduling URL check failed. Here's why:",e)
|
||||||
console.error("[PageInfo::scheduleUrlCheck] scheduling URL check failed. Here's why:",e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ghettoUrlCheck() {
|
ghettoUrlCheck() {
|
||||||
if (this.lastUrl != window.location.href){
|
if (this.lastUrl != window.location.href){
|
||||||
if(Debug.debug && Debug.periodic){
|
this.logger.log('error', 'videoRescan', "[PageInfo::ghettoUrlCheck] URL has changed. Triggering a rescan!");
|
||||||
console.log("[PageInfo::ghettoUrlCheck] URL has changed. Triggering a rescan!");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rescan(RescanReason.URL_CHANGE);
|
this.rescan(RescanReason.URL_CHANGE);
|
||||||
this.lastUrl = window.location.href;
|
this.lastUrl = window.location.href;
|
||||||
@ -343,7 +329,7 @@ class PageInfo {
|
|||||||
|
|
||||||
startArDetection(playingOnly){
|
startArDetection(playingOnly){
|
||||||
if (Debug.debug) {
|
if (Debug.debug) {
|
||||||
console.log('[PageInfo::startArDetection()] starting automatic ar detection!')
|
this.logger.log('info', 'debug', '[PageInfo::startArDetection()] starting automatic ar detection!')
|
||||||
}
|
}
|
||||||
if (playingOnly) {
|
if (playingOnly) {
|
||||||
for(var vd of this.videos){
|
for(var vd of this.videos){
|
||||||
@ -373,16 +359,12 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setAr(ar, playingOnly){
|
setAr(ar, playingOnly){
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly)
|
||||||
console.log('[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ar.type !== AspectRatio.Automatic) {
|
if (ar.type !== AspectRatio.Automatic) {
|
||||||
this.stopArDetection(playingOnly);
|
this.stopArDetection(playingOnly);
|
||||||
} else {
|
} else {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio is auto');
|
||||||
console.log('[PageInfo::setAr] aspect ratio is auto');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var vd of this.videos) {
|
for (var vd of this.videos) {
|
||||||
@ -391,7 +373,7 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("???", e);
|
this.logger.log('error', 'debug', "???", e);
|
||||||
}
|
}
|
||||||
this.initArDetection(playingOnly);
|
this.initArDetection(playingOnly);
|
||||||
this.startArDetection(playingOnly);
|
this.startArDetection(playingOnly);
|
||||||
|
@ -33,7 +33,7 @@ if(Debug.debug)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class PlayerData {
|
class PlayerData {
|
||||||
constructor(videoData) {
|
constructor(videoData, logger) {
|
||||||
this.videoData = videoData;
|
this.videoData = videoData;
|
||||||
this.video = videoData.video;
|
this.video = videoData.video;
|
||||||
this.settings = videoData.settings;
|
this.settings = videoData.settings;
|
||||||
@ -41,6 +41,7 @@ class PlayerData {
|
|||||||
this.element = undefined;
|
this.element = undefined;
|
||||||
this.dimensions = undefined;
|
this.dimensions = undefined;
|
||||||
this.overlayNode = undefined;
|
this.overlayNode = undefined;
|
||||||
|
this.logger = logger;
|
||||||
|
|
||||||
if (this.extensionMode === ExtensionMode.Enabled) {
|
if (this.extensionMode === ExtensionMode.Enabled) {
|
||||||
this.getPlayerDimensions();
|
this.getPlayerDimensions();
|
||||||
@ -117,9 +118,7 @@ class PlayerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unmarkPlayer() {
|
unmarkPlayer() {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[PlayerData::unmarkPlayer] unmarking player!")
|
||||||
console.log("[PlayerData::unmarkPlayer] unmarking player!")
|
|
||||||
}
|
|
||||||
if (this.playerIdElement) {
|
if (this.playerIdElement) {
|
||||||
this.playerIdElement.remove();
|
this.playerIdElement.remove();
|
||||||
}
|
}
|
||||||
@ -146,9 +145,7 @@ class PlayerData {
|
|||||||
try{
|
try{
|
||||||
ths.ghettoWatcher();
|
ths.ghettoWatcher();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[PlayerData::scheduleGhettoWatcher] Scheduling failed. Error:",e)
|
||||||
console.log("[PlayerData::scheduleGhettoWatcher] Scheduling failed. Error:",e)
|
|
||||||
}
|
|
||||||
|
|
||||||
ths.scheduleGhettoWatcher(1000);
|
ths.scheduleGhettoWatcher(1000);
|
||||||
}
|
}
|
||||||
@ -160,9 +157,7 @@ class PlayerData {
|
|||||||
|
|
||||||
ghettoWatcherFull() {
|
ghettoWatcherFull() {
|
||||||
if(this.checkPlayerSizeChange()){
|
if(this.checkPlayerSizeChange()){
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', "[uw::ghettoOnChange] change detected");
|
||||||
console.log("[uw::ghettoOnChange] change detected");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getPlayerDimensions();
|
this.getPlayerDimensions();
|
||||||
if(! this.element ){
|
if(! this.element ){
|
||||||
@ -179,9 +174,7 @@ class PlayerData {
|
|||||||
// trick it into doing that
|
// trick it into doing that
|
||||||
|
|
||||||
if(this.dimensions.fullscreen != PlayerData.isFullScreen()) {
|
if(this.dimensions.fullscreen != PlayerData.isFullScreen()) {
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', "[PlayerData::ghettoWatcher] fullscreen switch detected (basic change detection failed)");
|
||||||
console.log("[PlayerData::ghettoWatcher] fullscreen switch detected (basic change detection failed)");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getPlayerDimensions();
|
this.getPlayerDimensions();
|
||||||
|
|
||||||
@ -238,9 +231,7 @@ class PlayerData {
|
|||||||
let element = this.video.parentNode;
|
let element = this.video.parentNode;
|
||||||
|
|
||||||
if(! element ){
|
if(! element ){
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'debug', "[PlayerDetect::_pd_getPlayer] element is not valid, doing nothing.", element)
|
||||||
console.log("[PlayerDetect::_pd_getPlayer] element is not valid, doing nothing.", element)
|
|
||||||
}
|
|
||||||
if(this.element) {
|
if(this.element) {
|
||||||
const ths = this;
|
const ths = this;
|
||||||
}
|
}
|
||||||
@ -306,16 +297,11 @@ class PlayerData {
|
|||||||
|
|
||||||
grows = trustCandidateAfterGrows;
|
grows = trustCandidateAfterGrows;
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', "Found new candidate for player. Dimensions: w:", candidate_width, "h:",candidate_height, "node:", playerCandidateNode);
|
||||||
console.log("Found new candidate for player. Dimensions: w:", candidate_width, "h:",candidate_height, "node:", playerCandidateNode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(grows --<= 0){
|
else if(grows --<= 0){
|
||||||
|
this.logger.log('info', 'playerDetect', "Current element grew in comparrison to the child. We probably found the player. breaking loop, returning current result");
|
||||||
if(Debug.debug && Debug.playerDetect){
|
|
||||||
console.log("Current element grew in comparrison to the child. We probably found the player. breaking loop, returning current result");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,9 +320,7 @@ class PlayerData {
|
|||||||
const element = this.getPlayer(isFullScreen);
|
const element = this.getPlayer(isFullScreen);
|
||||||
|
|
||||||
if(! element ){
|
if(! element ){
|
||||||
if(Debug.debug) {
|
this.logger.log('error', 'debug', "[PlayerDetect::getPlayerDimensions] element is not valid, doing nothing.", element)
|
||||||
console.log("[PlayerDetect::getPlayerDimensions] element is not valid, doing nothing.", element)
|
|
||||||
}
|
|
||||||
this.element = undefined;
|
this.element = undefined;
|
||||||
this.dimensions = undefined;
|
this.dimensions = undefined;
|
||||||
return;
|
return;
|
||||||
@ -367,7 +351,7 @@ class PlayerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkPlayerSizeChange(){
|
checkPlayerSizeChange(){
|
||||||
if(Debug.debug){
|
if (this.logger.canLog('debug')){
|
||||||
if(this.element == undefined){
|
if(this.element == undefined){
|
||||||
// return true;
|
// return true;
|
||||||
}
|
}
|
||||||
@ -378,18 +362,18 @@ class PlayerData {
|
|||||||
|
|
||||||
if (this.dimensions && this.dimensions.fullscreen){
|
if (this.dimensions && this.dimensions.fullscreen){
|
||||||
if(! PlayerData.isFullScreen()){
|
if(! PlayerData.isFullScreen()){
|
||||||
console.log("[PlayerDetect] player size changed. reason: exited fullscreen");
|
this.logger.log('info', 'debug', "[PlayerDetect] player size changed. reason: exited fullscreen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(! this.element && Debug.debug && Debug.playerDetect) {
|
if(! this.element) {
|
||||||
console.log("[PlayerDetect] player element isnt defined");
|
this.logger.log('info', 'playerDetect', "[PlayerDetect] player element isnt defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.element &&
|
if ( this.element &&
|
||||||
( this.dimensions.width != this.element.offsetWidth ||
|
( this.dimensions.width != this.element.offsetWidth ||
|
||||||
this.dimensions.height != this.element.offsetHeight )
|
this.dimensions.height != this.element.offsetHeight )
|
||||||
) {
|
) {
|
||||||
console.log("[PlayerDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions.width, this.dimensions.height, "new dimensions:", this.element.offsetWidth, this.element.offsetHeight);
|
this.logger.log('info', 'debug', "[PlayerDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions.width, this.dimensions.height, "new dimensions:", this.element.offsetWidth, this.element.offsetHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,9 +401,7 @@ class PlayerData {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'debug', "[PlayerData::checkFullscreenChange] this.dimensions is not defined. Assuming fs change happened and setting default values.")
|
||||||
console.log("[PlayerData::checkFullscreenChange] this.dimensions is not defined. Assuming fs change happened and setting default values.")
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dimensions = {
|
this.dimensions = {
|
||||||
fullscreen: isFs,
|
fullscreen: isFs,
|
||||||
|
@ -5,35 +5,31 @@ import ArDetector from '../ar-detect/ArDetector';
|
|||||||
|
|
||||||
class VideoData {
|
class VideoData {
|
||||||
|
|
||||||
constructor(video, settings, pageInfo){
|
constructor(video, settings, pageInfo, logger){
|
||||||
this.arSetupComplete = false;
|
this.arSetupComplete = false;
|
||||||
this.video = video;
|
this.video = video;
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.pageInfo = pageInfo;
|
this.pageInfo = pageInfo;
|
||||||
this.extensionMode = pageInfo.extensionMode;
|
this.extensionMode = pageInfo.extensionMode;
|
||||||
|
this.logger = logger;
|
||||||
|
|
||||||
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
||||||
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
||||||
this.player = new PlayerData(this);
|
this.player = new PlayerData(this, logger);
|
||||||
this.resizer = new Resizer(this);
|
this.resizer = new Resizer(this, logger);
|
||||||
|
|
||||||
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
|
this.arDetector = new ArDetector(this, logger); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
|
||||||
// player dimensions need to be in:
|
// player dimensions need to be in:
|
||||||
// this.player.dimensions
|
// this.player.dimensions
|
||||||
|
|
||||||
// apply default align and stretch
|
// apply default align and stretch
|
||||||
if (Debug.init) {
|
this.logger.log('info', 'debug', "%c[VideoData::ctor] Initial resizer reset!", {background: '#afd', color: '#132'});
|
||||||
console.log("%c[VideoData::ctor] Initial resizer reset!", {background: '#afd', color: '#132'});
|
|
||||||
}
|
|
||||||
this.resizer.reset();
|
this.resizer.reset();
|
||||||
|
|
||||||
|
|
||||||
this.vdid = (Math.random()*100).toFixed();
|
this.vdid = (Math.random()*100).toFixed();
|
||||||
if (Debug.init) {
|
this.logger.log('info', 'init', "[VideoData::ctor] Created videoData with vdid", this.vdid,"\nextension mode:", this.extensionMode);
|
||||||
console.log("[VideoData::ctor] Created videoData with vdid", this.vdid,"\nextension mode:", this.extensionMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pageInfo.initMouseActionHandler(this);
|
this.pageInfo.initMouseActionHandler(this);
|
||||||
}
|
}
|
||||||
@ -61,9 +57,7 @@ class VideoData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startArDetection() {
|
startArDetection() {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[VideoData::startArDetection] starting AR detection")
|
||||||
console.log("[VideoData::startArDetection] starting AR detection")
|
|
||||||
}
|
|
||||||
if(this.destroyed) {
|
if(this.destroyed) {
|
||||||
throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
||||||
}
|
}
|
||||||
@ -87,9 +81,7 @@ class VideoData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if(Debug.debug || Debug.init){
|
this.logger.log('info', ['debug', 'init'], `[VideoData::destroy] <vdid:${this.vdid}> received destroy command`);
|
||||||
console.log(`[VideoData::destroy] <vdid:${this.vdid}> received destroy command`);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pause();
|
this.pause();
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
@ -133,9 +125,7 @@ class VideoData {
|
|||||||
this.player.start();
|
this.player.start();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if(Debug.debug){
|
this.logger.log('error', 'debug', "[VideoData.js::resume] cannot resume for reasons. Will destroy videoData. Error here:", e);
|
||||||
console.log("[VideoData.js::resume] cannot resume for reasons. Will destroy videoData. Error here:", e);
|
|
||||||
}
|
|
||||||
this.destroy();
|
this.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,17 @@ if(Debug.debug) {
|
|||||||
|
|
||||||
class Resizer {
|
class Resizer {
|
||||||
|
|
||||||
constructor(videoData) {
|
constructor(videoData, logger) {
|
||||||
this.conf = videoData;
|
this.conf = videoData;
|
||||||
this.video = videoData.video;
|
this.video = videoData.video;
|
||||||
this.settings = videoData.settings;
|
this.settings = videoData.settings;
|
||||||
this.extensionMode = videoData.extensionMode;
|
this.extensionMode = videoData.extensionMode;
|
||||||
|
|
||||||
this.scaler = new Scaler(this.conf);
|
this.logger = logger;
|
||||||
this.stretcher = new Stretcher(this.conf);
|
|
||||||
this.zoom = new Zoom(this.conf);
|
this.scaler = new Scaler(this.conf, logger);
|
||||||
|
this.stretcher = new Stretcher(this.conf, logger);
|
||||||
|
this.zoom = new Zoom(this.conf, logger);
|
||||||
|
|
||||||
this.cssCheckDisabled = false;
|
this.cssCheckDisabled = false;
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ class Resizer {
|
|||||||
this.resizerId = (Math.random(99)*100).toFixed(0);
|
this.resizerId = (Math.random(99)*100).toFixed(0);
|
||||||
|
|
||||||
if (this.settings.active.pan) {
|
if (this.settings.active.pan) {
|
||||||
console.log("can pan:", this.settings.active.miscSettings.mousePan.enabled, "(default:", this.settings.active.miscSettings.mousePan.enabled, ")")
|
this.logger.log('info', 'debug', "can pan:", this.settings.active.miscSettings.mousePan.enabled, "(default:", this.settings.active.miscSettings.mousePan.enabled, ")")
|
||||||
this.canPan = this.settings.active.miscSettings.mousePan.enabled;
|
this.canPan = this.settings.active.miscSettings.mousePan.enabled;
|
||||||
} else {
|
} else {
|
||||||
this.canPan = false;
|
this.canPan = false;
|
||||||
@ -68,9 +70,7 @@ class Resizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy(){
|
destroy(){
|
||||||
if(Debug.debug || Debug.init){
|
this.logger.log('info', ['debug', 'init'], `[Resizer::destroy] <rid:${this.resizerId}> received destroy command.`);
|
||||||
console.log(`[Resizer::destroy] <rid:${this.resizerId}> received destroy command.`);
|
|
||||||
}
|
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
this.stopCssWatcher();
|
this.stopCssWatcher();
|
||||||
}
|
}
|
||||||
@ -86,9 +86,7 @@ class Resizer {
|
|||||||
var ratioOut;
|
var ratioOut;
|
||||||
|
|
||||||
if (!this.conf.video) {
|
if (!this.conf.video) {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Scaler.js::modeToAr] No video??",this.conf.video, "killing videoData");
|
||||||
console.log("[Scaler.js::modeToAr] No video??",this.conf.video, "killing videoData");
|
|
||||||
}
|
|
||||||
this.conf.destroy();
|
this.conf.destroy();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -97,9 +95,7 @@ class Resizer {
|
|||||||
if (! this.conf.player.dimensions) {
|
if (! this.conf.player.dimensions) {
|
||||||
ratioOut = screen.width / screen.height;
|
ratioOut = screen.width / screen.height;
|
||||||
} else {
|
} else {
|
||||||
if (Debug.debug && Debug.resizer) {
|
this.logger.log('info', 'debug', `[Resizer::calculateRatioForLegacyOptions] <rid:${this.resizerId}> Player dimensions:`, this.conf.player.dimensions.width ,'x', this.conf.player.dimensions.height,'aspect ratio:', this.conf.player.dimensions.width / this.conf.player.dimensions.height)
|
||||||
console.log(`[Resizer::calculateRatioForLegacyOptions] <rid:${this.resizerId}> Player dimensions:`, this.conf.player.dimensions.width ,'x', this.conf.player.dimensions.height,'aspect ratio:', this.conf.player.dimensions.width / this.conf.player.dimensions.height)
|
|
||||||
}
|
|
||||||
ratioOut = this.conf.player.dimensions.width / this.conf.player.dimensions.height;
|
ratioOut = this.conf.player.dimensions.width / this.conf.player.dimensions.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,9 +114,7 @@ class Resizer {
|
|||||||
ar.ratio = ratioOut < fileAr ? ratioOut : fileAr;
|
ar.ratio = ratioOut < fileAr ? ratioOut : fileAr;
|
||||||
}
|
}
|
||||||
else if(ar.type === AspectRatio.Reset){
|
else if(ar.type === AspectRatio.Reset){
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', "[Scaler.js::modeToAr] Using original aspect ratio -", fileAr);
|
||||||
console.log("[Scaler.js::modeToAr] Using original aspect ratio -", fileAr);
|
|
||||||
}
|
|
||||||
ar.ratio = fileAr;
|
ar.ratio = fileAr;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -135,9 +129,7 @@ class Resizer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', '[Resizer::setAr] <rid:'+this.resizerId+'> trying to set ar. New ar:', ar)
|
||||||
console.log('[Resizer::setAr] <rid:'+this.resizerId+'> trying to set ar. New ar:', ar)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ar == null) {
|
if (ar == null) {
|
||||||
return;
|
return;
|
||||||
@ -166,17 +158,13 @@ class Resizer {
|
|||||||
// check if property value is on the list of allowed values
|
// check if property value is on the list of allowed values
|
||||||
// if it's not, we aren't allowed to start aard
|
// if it's not, we aren't allowed to start aard
|
||||||
if (bannedProperties[prop].allowedValues.indexOf(styleValue) === -1) {
|
if (bannedProperties[prop].allowedValues.indexOf(styleValue) === -1) {
|
||||||
if (Debug.debug) {
|
this.logger.log('error', 'debug', "%c[Resizer::setAr] video style contains forbidden css property/value combo: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
||||||
console.log("%c[Resizer::setAr] video style contains forbidden css property/value combo: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no allowed values, no problem. We have forbidden property
|
// no allowed values, no problem. We have forbidden property
|
||||||
// and this means aard can't start.
|
// and this means aard can't start.
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "%c[Resizer::setAr] video style contains forbidden css property: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
||||||
console.log("%c[Resizer::setAr] video style contains forbidden css property: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,9 +183,7 @@ class Resizer {
|
|||||||
// I'm not sure whether they do. Check that.
|
// I'm not sure whether they do. Check that.
|
||||||
ar = this.calculateRatioForLegacyOptions(ar);
|
ar = this.calculateRatioForLegacyOptions(ar);
|
||||||
if (! ar) {
|
if (! ar) {
|
||||||
if (Debug.debug && Debug.resizer) {
|
this.logger.log('info', 'resizer', `[Resizer::setAr] <${this.resizerId}> Something wrong with ar or the player. Doing nothing.`);
|
||||||
console.log(`[Resizer::setAr] <${this.resizerId}> Something wrong with ar or the player. Doing nothing.`);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.lastAr = {type: ar.type, ratio: ar.ratio}
|
this.lastAr = {type: ar.type, ratio: ar.ratio}
|
||||||
@ -238,16 +224,12 @@ class Resizer {
|
|||||||
var stretchFactors = this.scaler.calculateCrop(ar);
|
var stretchFactors = this.scaler.calculateCrop(ar);
|
||||||
|
|
||||||
if(! stretchFactors || stretchFactors.error){
|
if(! stretchFactors || stretchFactors.error){
|
||||||
if(Debug.debug){
|
this.logger.log('error', 'debug', "[Resizer::setAr] <rid:"+this.resizerId+"> failed to set AR due to problem with calculating crop. Error:", (stretchFactors ? stretchFactors.error : stretchFactors));
|
||||||
console.log("[Resizer::setAr] <rid:"+this.resizerId+"> failed to set AR due to problem with calculating crop. Error:", (stretchFactors ? stretchFactors.error : stretchFactors));
|
|
||||||
}
|
|
||||||
if (stretchFactors.error === 'no_video'){
|
if (stretchFactors.error === 'no_video'){
|
||||||
this.conf.destroy();
|
this.conf.destroy();
|
||||||
}
|
}
|
||||||
if (stretchFactors.error === 'illegal_video_dimensions') {
|
if (stretchFactors.error === 'illegal_video_dimensions') {
|
||||||
if(Debug.debug){
|
this.logger.log('error', 'debug', "[Resizer::setAr] <rid:"+this.resizerId+"> Illegal video dimensions found. We will pause everything.");
|
||||||
console.log("[Resizer::setAr] <rid:"+this.resizerId+"> Illegal video dimensions found. We will pause everything.");
|
|
||||||
}
|
|
||||||
// if we get illegal video dimensions, cssWatcher goes nuts. This is harmful,
|
// if we get illegal video dimensions, cssWatcher goes nuts. This is harmful,
|
||||||
// so we stop it until that sorts itself out
|
// so we stop it until that sorts itself out
|
||||||
this.stopCssWatcher();
|
this.stopCssWatcher();
|
||||||
@ -260,25 +242,17 @@ class Resizer {
|
|||||||
this.stretcher.applyConditionalStretch(stretchFactors, ar.ratio);
|
this.stretcher.applyConditionalStretch(stretchFactors, ar.ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Resizer::setAr] Processed stretch factors for ", this.stretcher.mode === Stretch.NoStretch ? 'stretch-free crop.' : 'crop with conditional stretch.', 'Stretch factors are:', stretchFactors);
|
||||||
console.log("[Resizer::setAr] Processed stretch factors for ", this.stretcher.mode === Stretch.NoStretch ? 'stretch-free crop.' : 'crop with conditional stretch.', 'Stretch factors are:', stretchFactors);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (this.stretcher.mode === Stretch.Hybrid) {
|
} else if (this.stretcher.mode === Stretch.Hybrid) {
|
||||||
var stretchFactors = this.stretcher.calculateStretch(ar.ratio);
|
var stretchFactors = this.stretcher.calculateStretch(ar.ratio);
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', '[Resizer::setAr] Processed stretch factors for hybrid stretch/crop. Stretch factors are:', stretchFactors);
|
||||||
console.log('[Resizer::setAr] Processed stretch factors for hybrid stretch/crop. Stretch factors are:', stretchFactors);
|
|
||||||
}
|
|
||||||
} else if (this.stretcher.mode === Stretch.Basic) {
|
} else if (this.stretcher.mode === Stretch.Basic) {
|
||||||
var stretchFactors = this.stretcher.calculateBasicStretch();
|
var stretchFactors = this.stretcher.calculateBasicStretch();
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', '[Resizer::setAr] Processed stretch factors for basic stretch. Stretch factors are:', stretchFactors);
|
||||||
console.log('[Resizer::setAr] Processed stretch factors for basic stretch. Stretch factors are:', stretchFactors);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
var stretchFactors = {xFactor: 1, yFactor: 1}
|
var stretchFactors = {xFactor: 1, yFactor: 1}
|
||||||
if (Debug.debug) {
|
this.logger.log('error', 'debug', '[Resizer::setAr] Okay wtf happened? If you see this, something has gone wrong', stretchFactors,"\n------[ i n f o d u m p ]------\nstretcher:", this.stretcher);
|
||||||
console.log('[Resizer::setAr] Okay wtf happened? If you see this, something has gone wrong', stretchFactors,"\n------[ i n f o d u m p ]------\nstretcher:", this.stretcher);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.zoom.applyZoom(stretchFactors);
|
this.zoom.applyZoom(stretchFactors);
|
||||||
@ -320,10 +294,7 @@ class Resizer {
|
|||||||
const relativeX = (event.pageX - player.offsetLeft) / player.offsetWidth;
|
const relativeX = (event.pageX - player.offsetLeft) / player.offsetWidth;
|
||||||
const relativeY = (event.pageY - player.offsetTop) / player.offsetHeight;
|
const relativeY = (event.pageY - player.offsetTop) / player.offsetHeight;
|
||||||
|
|
||||||
if (Debug.debug && Debug.mousemove) {
|
this.logger.log('info', 'mousemove', "[Resizer::panHandler] mousemove.pageX, pageY:", event.pageX, event.pageY, "\nrelativeX/Y:", relativeX, relativeY)
|
||||||
console.log("[Resizer::panHandler] mousemove.pageX, pageY:", event.pageX, event.pageY,
|
|
||||||
"\nrelativeX/Y:", relativeX, relativeY)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setPan(relativeX, relativeY);
|
this.setPan(relativeX, relativeY);
|
||||||
}
|
}
|
||||||
@ -343,9 +314,6 @@ class Resizer {
|
|||||||
this.pan.relativeOffsetX = -(relativeMousePosX * 1.1) + 0.55;
|
this.pan.relativeOffsetX = -(relativeMousePosX * 1.1) + 0.55;
|
||||||
this.pan.relativeOffsetY = -(relativeMousePosY * 1.1) + 0.55;
|
this.pan.relativeOffsetY = -(relativeMousePosY * 1.1) + 0.55;
|
||||||
}
|
}
|
||||||
// if(Debug.debug){
|
|
||||||
// console.log("[Resizer::setPan] relative cursor pos:", relativeMousePosX, ",",relativeMousePosY, " | new pan obj:", this.pan)
|
|
||||||
// }
|
|
||||||
this.restore();
|
this.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,9 +323,7 @@ class Resizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startCssWatcher(){
|
startCssWatcher(){
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'cssWatcher', "[Resizer.js::startCssWatcher] starting css watcher. Is resizer destroyed?", this.destroyed);
|
||||||
console.log("[Resizer.js::startCssWatcher] starting css watcher. Is resizer destroyed?", this.destroyed);
|
|
||||||
}
|
|
||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -399,25 +365,19 @@ class Resizer {
|
|||||||
ths.cssCheck();
|
ths.cssCheck();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if(Debug.debug) {
|
this.logger.log('error', 'debug', "[Resizer.js::scheduleCssWatcher] Css check failed. Error:", e);
|
||||||
console.log("[Resizer.js::scheduleCssWatcher] Css check failed. Error:", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
stopCssWatcher() {
|
stopCssWatcher() {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'cssWatcher', `[Resizer.js] <${this.resizerId}> STOPPING CSS WATCHER!`)
|
||||||
console.log(`[Resizer.js] <${this.resizerId}> STOPPING CSS WATCHER!`)
|
|
||||||
}
|
|
||||||
this.cssCheckDisabled = true;
|
this.cssCheckDisabled = true;
|
||||||
clearInterval(this.cssWatcherTimeout);
|
clearInterval(this.cssWatcherTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
restore() {
|
restore() {
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', "[Resizer::restore] <rid:"+this.resizerId+"> attempting to restore aspect ratio. this & settings:", {'a_lastAr': this.lastAr, 'this': this, "settings": this.settings} );
|
||||||
console.log("[Resizer::restore] <rid:"+this.resizerId+"> attempting to restore aspect ratio. this & settings:", {'a_lastAr': this.lastAr, 'this': this, "settings": this.settings} );
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is true until we verify that css has actually been applied
|
// this is true until we verify that css has actually been applied
|
||||||
this.restore_wd = true;
|
this.restore_wd = true;
|
||||||
@ -481,9 +441,7 @@ class Resizer {
|
|||||||
|
|
||||||
computeOffsets(stretchFactors){
|
computeOffsets(stretchFactors){
|
||||||
|
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Resizer::computeOffsets] <rid:"+this.resizerId+"> video will be aligned to ", this.settings.active.sites['@global'].videoAlignment);
|
||||||
console.log("[Resizer::computeOffsets] <rid:"+this.resizerId+"> video will be aligned to ", this.settings.active.sites['@global'].videoAlignment);
|
|
||||||
}
|
|
||||||
|
|
||||||
const wdiff = this.conf.player.dimensions.width - this.conf.video.offsetWidth;
|
const wdiff = this.conf.player.dimensions.width - this.conf.video.offsetWidth;
|
||||||
const hdiff = this.conf.player.dimensions.height - this.conf.video.offsetHeight;
|
const hdiff = this.conf.player.dimensions.height - this.conf.video.offsetHeight;
|
||||||
@ -512,16 +470,14 @@ class Resizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'debug', "[Resizer::_res_computeOffsets] <rid:"+this.resizerId+"> calculated offsets:\n\n",
|
||||||
console.log("[Resizer::_res_computeOffsets] <rid:"+this.resizerId+"> calculated offsets:\n\n",
|
'---- data in ----\n',
|
||||||
'---- data in ----\n',
|
'player dimensions:', {w: this.conf.player.dimensions.width, h: this.conf.player.dimensions.height},
|
||||||
'player dimensions:', {w: this.conf.player.dimensions.width, h: this.conf.player.dimensions.height},
|
'video dimensions: ', {w: this.conf.video.offsetWidth, h: this.conf.video.offsetHeight},
|
||||||
'video dimensions: ', {w: this.conf.video.offsetWidth, h: this.conf.video.offsetHeight},
|
'stretch factors: ', stretchFactors,
|
||||||
'stretch factors: ', stretchFactors,
|
'pan & zoom: ', this.pan, this.zoom,
|
||||||
'pan & zoom: ', this.pan, this.zoom,
|
'\n\n---- data out ----\n',
|
||||||
'\n\n---- data out ----\n',
|
'translate:', translate);
|
||||||
'translate:', translate);
|
|
||||||
}
|
|
||||||
|
|
||||||
return translate;
|
return translate;
|
||||||
}
|
}
|
||||||
@ -583,18 +539,13 @@ class Resizer {
|
|||||||
// apply extra CSS here. In case of duplicated properties, extraCss overrides
|
// apply extra CSS here. In case of duplicated properties, extraCss overrides
|
||||||
// default styleString
|
// default styleString
|
||||||
if (! this.video) {
|
if (! this.video) {
|
||||||
if(Debug.debug) {
|
this.logger.log('warn', 'debug', "[Resizer::applyCss] <rid:"+this.resizerId+"> Video went missing, doing nothing.");
|
||||||
console.log("[Resizer::applyCss] <rid:"+this.resizerId+"> Video went missing, doing nothing.");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.conf.destroy();
|
this.conf.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Debug.debug && Debug.resizer) {
|
this.logger.log('info', 'resizer', "[Resizer::applyCss] <rid:"+this.resizerId+"> will apply css.", {stretchFactors, translate});
|
||||||
console.log("[Resizer::applyCss] <rid:"+this.resizerId+"> will apply css.", {stretchFactors, translate});
|
|
||||||
}
|
|
||||||
|
|
||||||
// save stuff for quick tests (before we turn numbers into css values):
|
// save stuff for quick tests (before we turn numbers into css values):
|
||||||
this.currentVideoSettings = {
|
this.currentVideoSettings = {
|
||||||
@ -633,8 +584,7 @@ class Resizer {
|
|||||||
|
|
||||||
if (this.restore_wd) {
|
if (this.restore_wd) {
|
||||||
if (!this.video){
|
if (!this.video){
|
||||||
if(Debug.debug)
|
this.logger.log('warn', 'debug', "[Resizer::_res_setStyleString] <rid:"+this.resizerId+"> Video element went missing, nothing to do here.")
|
||||||
console.log("[Resizer::_res_setStyleString] <rid:"+this.resizerId+"> Video element went missing, nothing to do here.")
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,14 +608,13 @@ class Resizer {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(Debug.debug)
|
this.logger.log('info', 'resizer', "[Resizer::_res_setStyleString] <rid:"+this.resizerId+"> css applied. Style string:", styleString);
|
||||||
console.log("[Resizer::_res_setStyleString] <rid:"+this.resizerId+"> css applied. Style string:", styleString);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cssCheck(){
|
cssCheck(){
|
||||||
if (this.cssCheckDisabled) {
|
if (this.cssCheckDisabled) {
|
||||||
throw "fucking dont"
|
// throw "fucking dont"
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// this means we haven't set our CSS yet, or that we changed video.
|
// this means we haven't set our CSS yet, or that we changed video.
|
||||||
@ -676,17 +625,13 @@ class Resizer {
|
|||||||
|
|
||||||
// this means video went missing. videoData will be re-initialized when the next video is found
|
// this means video went missing. videoData will be re-initialized when the next video is found
|
||||||
if (!this.video){
|
if (!this.video){
|
||||||
if(Debug.debug && Debug.resizer) {
|
this.logger.log('info', 'cssWatcher', "[Resizer::cssCheck] <rid:"+this.resizerId+"> no video detecting, issuing destroy command");
|
||||||
console.log("[Resizer::cssCheck] <rid:"+this.resizerId+"> no video detecting, issuing destroy command");
|
|
||||||
}
|
|
||||||
this.conf.destroy();
|
this.conf.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.destroyed) {
|
if(this.destroyed) {
|
||||||
if(Debug.debug && Debug.resizer) {
|
this.logger.log('info', 'cssWatcher', "[Resizer::cssCheck] <rid:"+this.resizerId+"> destroyed flag is set, we shouldnt be running");
|
||||||
console.log("[Resizer::cssCheck] <rid:"+this.resizerId+"> destroyed flag is set, we shouldnt be running");
|
|
||||||
}
|
|
||||||
this.stopCssWatcher();
|
this.stopCssWatcher();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -705,9 +650,7 @@ class Resizer {
|
|||||||
cssValid &= this.currentPlayerStyleString === playerStyleString;
|
cssValid &= this.currentPlayerStyleString === playerStyleString;
|
||||||
}
|
}
|
||||||
if (!cssValid){
|
if (!cssValid){
|
||||||
if(Debug.debug && Debug.resizer) {
|
this.logger.log('info', 'cssWatcher', `%c[Resizer::cssCheck] <rid:${this.resizerId}> something touched our style string. We need to re-apply the style.`, {background: '#ddf', color: '#007'});
|
||||||
console.log(`%c[Resizer::cssCheck] <rid:${this.resizerId}> something touched our style string. We need to re-apply the style.`, {background: '#ddf', color: '#007'});
|
|
||||||
}
|
|
||||||
this.restore();
|
this.restore();
|
||||||
this.scheduleCssWatcher(10);
|
this.scheduleCssWatcher(10);
|
||||||
|
|
||||||
|
@ -9,8 +9,9 @@ class Scaler {
|
|||||||
// internal variables
|
// internal variables
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
constructor(videoData) {
|
constructor(videoData, logger) {
|
||||||
this.conf = videoData;
|
this.conf = videoData;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -25,9 +26,7 @@ class Scaler {
|
|||||||
var ratioOut;
|
var ratioOut;
|
||||||
|
|
||||||
if (!this.conf.video) {
|
if (!this.conf.video) {
|
||||||
if(Debug.debug){
|
this.logger.log('error', 'debug', "[Scaler.js::modeToAr] No video??",this.conf.video, "killing videoData");
|
||||||
console.log("[Scaler.js::modeToAr] No video??",this.conf.video, "killing videoData");
|
|
||||||
}
|
|
||||||
this.conf.destroy();
|
this.conf.destroy();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -59,9 +58,7 @@ class Scaler {
|
|||||||
return ratioOut;
|
return ratioOut;
|
||||||
}
|
}
|
||||||
else if(ar.type === AspectRatio.Reset){
|
else if(ar.type === AspectRatio.Reset){
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', "[Scaler.js::modeToAr] Using original aspect ratio -", fileAr)
|
||||||
console.log("[Scaler.js::modeToAr] Using original aspect ratio -", fileAr)
|
|
||||||
}
|
|
||||||
ar.ar = fileAr;
|
ar.ar = fileAr;
|
||||||
return fileAr;
|
return fileAr;
|
||||||
}
|
}
|
||||||
@ -71,9 +68,7 @@ class Scaler {
|
|||||||
|
|
||||||
calculateCrop(ar) {
|
calculateCrop(ar) {
|
||||||
if(!this.conf.video){
|
if(!this.conf.video){
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Scaler::calculateCrop] ERROR — no video detected. Conf:", this.conf, "video:", this.conf.video, "video dimensions:", this.conf.video && this.conf.video.videoWidth, '×', this.conf.video && this.conf.video.videoHeight);
|
||||||
console.log("[Scaler::calculateCrop] ERROR — no video detected. Conf:", this.conf, "video:", this.conf.video, "video dimensions:", this.conf.video && this.conf.video.videoWidth, '×', this.conf.video && this.conf.video.videoHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.conf.destroy();
|
this.conf.destroy();
|
||||||
return {error: "no_video"};
|
return {error: "no_video"};
|
||||||
@ -81,9 +76,7 @@ class Scaler {
|
|||||||
if (this.conf.video.videoWidth == 0 || this.conf.video.videoHeight == 0) {
|
if (this.conf.video.videoWidth == 0 || this.conf.video.videoHeight == 0) {
|
||||||
// that's illegal, but not illegal enough to just blast our shit to high hell
|
// that's illegal, but not illegal enough to just blast our shit to high hell
|
||||||
// mr officer will let you go with a warning this time around
|
// mr officer will let you go with a warning this time around
|
||||||
if (Debug.debug) {
|
this.logger.log('error', 'debug', "[Scaler::calculateCrop] Video has illegal dimensions. Video dimensions:", this.conf.video && this.conf.video.videoWidth, '×', this.conf.video && this.conf.video.videoHeight);
|
||||||
console.log("[Scaler::calculateCrop] Video has illegal dimensions. Video dimensions:", this.conf.video && this.conf.video.videoWidth, '×', this.conf.video && this.conf.video.videoHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {error: "illegal_video_dimensions"};
|
return {error: "illegal_video_dimensions"};
|
||||||
}
|
}
|
||||||
@ -94,20 +87,14 @@ class Scaler {
|
|||||||
|
|
||||||
// handle fuckie-wuckies
|
// handle fuckie-wuckies
|
||||||
if (!ar.ratio){
|
if (!ar.ratio){
|
||||||
if (Debug.debug && Debug.scaler) {
|
this.logger.log('error', 'scaler', "[Scaler::calculateCrop] no ar?", ar.ratio, " -- we were given this mode:", ar);
|
||||||
console.log("[Scaler::calculateCrop] no ar?", ar.ratio, " -- we were given this mode:", ar);
|
|
||||||
}
|
|
||||||
return {error: "no_ar", ratio: ar.ratio};
|
return {error: "no_ar", ratio: ar.ratio};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Debug.debug && Debug.scaler) {
|
this.logger.log('info', 'scaler', "[Scaler::calculateCrop] trying to set ar. args are: ar->",ar.ratio,"; this.conf.player.dimensions->",this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "| obj:", this.conf.player.dimensions);
|
||||||
console.log("[Scaler::calculateCrop] trying to set ar. args are: ar->",ar.ratio,"; this.conf.player.dimensions->",this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "| obj:", this.conf.player.dimensions);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( (! this.conf.player.dimensions) || this.conf.player.dimensions.width === 0 || this.conf.player.dimensions.height === 0 ){
|
if( (! this.conf.player.dimensions) || this.conf.player.dimensions.width === 0 || this.conf.player.dimensions.height === 0 ){
|
||||||
if (Debug.debug && Debug.scaler) {
|
this.logger.log('error', 'scaler', "[Scaler::calculateCrop] ERROR — no (or invalid) this.conf.player.dimensions:",this.conf.player.dimensions);
|
||||||
console.log("[Scaler::calculateCrop] ERROR — no (or invalid) this.conf.player.dimensions:",this.conf.player.dimensions);
|
|
||||||
}
|
|
||||||
return {error: "this.conf.player.dimensions_error"};
|
return {error: "this.conf.player.dimensions_error"};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,9 +111,7 @@ class Scaler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Debug.debug && Debug.scaler) {
|
this.logger.log('info', 'scaler', "[Scaler::calculateCrop] ar is " ,ar.ratio, ", file ar is", fileAr, ", this.conf.player.dimensions are ", this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "| obj:", this.conf.player.dimensions);
|
||||||
console.log("[Scaler::calculateCrop] ar is " ,ar.ratio, ", file ar is", fileAr, ", this.conf.player.dimensions are ", this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "| obj:", this.conf.player.dimensions);
|
|
||||||
}
|
|
||||||
|
|
||||||
var videoDimensions = {
|
var videoDimensions = {
|
||||||
xFactor: 1,
|
xFactor: 1,
|
||||||
@ -152,9 +137,7 @@ class Scaler {
|
|||||||
videoDimensions.yFactor = videoDimensions.xFactor;
|
videoDimensions.yFactor = videoDimensions.xFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Debug.debug && Debug.scaler) {
|
this.logger.log('info', 'scaler', "[Scaler::calculateCrop] Crop factor calculated — ", videoDimensions.xFactor);
|
||||||
console.log("[Scaler::calculateCrop] Crop factor calculated — ", videoDimensions.xFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videoDimensions;
|
return videoDimensions;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import Debug from '../../conf/Debug';
|
|
||||||
import Stretch from '../../../common/enums/stretch.enum';
|
import Stretch from '../../../common/enums/stretch.enum';
|
||||||
|
|
||||||
// računa vrednosti za transform-scale (x, y)
|
// računa vrednosti za transform-scale (x, y)
|
||||||
@ -11,10 +10,11 @@ class Stretcher {
|
|||||||
|
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
constructor(videoData) {
|
constructor(videoData, logger) {
|
||||||
this.conf = videoData;
|
this.conf = videoData;
|
||||||
this.settings = videoData.settings;
|
this.settings = videoData.settings;
|
||||||
this.mode = this.settings.getDefaultStretchMode(window.location.hostname);
|
this.mode = this.settings.getDefaultStretchMode(window.location.hostname);
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
setStretchMode(stretchMode) {
|
setStretchMode(stretchMode) {
|
||||||
@ -120,9 +120,7 @@ class Stretcher {
|
|||||||
stretchFactors.xFactor = playerAr / videoAr;
|
stretchFactors.xFactor = playerAr / videoAr;
|
||||||
stretchFactors.yFactor = actualAr / videoAr;
|
stretchFactors.yFactor = actualAr / videoAr;
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'stretcher', "[Stretcher.js::calculateStretch] stretching strategy 1")
|
||||||
console.log("[Stretcher.js::calculateStretch] stretching strategy 1")
|
|
||||||
}
|
|
||||||
} else if ( actualAr >= videoAr) {
|
} else if ( actualAr >= videoAr) {
|
||||||
// VERIFIED WORKS
|
// VERIFIED WORKS
|
||||||
|
|
||||||
@ -132,18 +130,14 @@ class Stretcher {
|
|||||||
stretchFactors.xFactor = playerAr / videoAr;
|
stretchFactors.xFactor = playerAr / videoAr;
|
||||||
stretchFactors.yFactor = actualAr / videoAr;
|
stretchFactors.yFactor = actualAr / videoAr;
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'stretcher', "[Stretcher.js::calculateStretch] stretching strategy 2")
|
||||||
console.log("[Stretcher.js::calculateStretch] stretching strategy 2")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// NEEDS CHECKING
|
// NEEDS CHECKING
|
||||||
// player > video > actual — double pillarbox
|
// player > video > actual — double pillarbox
|
||||||
stretchFactors.xFactor = actualAr / playerAr;
|
stretchFactors.xFactor = actualAr / playerAr;
|
||||||
stretchFactors.yFactor = 1;
|
stretchFactors.yFactor = 1;
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'stretcher', "[Stretcher.js::calculateStretch] stretching strategy 3")
|
||||||
console.log("[Stretcher.js::calculateStretch] stretching strategy 3")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// player adds LETTERBOX
|
// player adds LETTERBOX
|
||||||
@ -156,9 +150,7 @@ class Stretcher {
|
|||||||
stretchFactors.xFactor = actualAr / playerAr;
|
stretchFactors.xFactor = actualAr / playerAr;
|
||||||
stretchFactors.yFactor = videoAr / playerAr;
|
stretchFactors.yFactor = videoAr / playerAr;
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'stretcher', "[Stretcher.js::calculateStretch] stretching strategy 4")
|
||||||
console.log("[Stretcher.js::calculateStretch] stretching strategy 4")
|
|
||||||
}
|
|
||||||
} else if ( actualAr < videoAr ) {
|
} else if ( actualAr < videoAr ) {
|
||||||
// NEEDS CHECKING
|
// NEEDS CHECKING
|
||||||
|
|
||||||
@ -168,9 +160,7 @@ class Stretcher {
|
|||||||
stretchFactors.xFactor = actualAr / playerAr;
|
stretchFactors.xFactor = actualAr / playerAr;
|
||||||
stretchFActors.yFactor = actualAr / playerAr;
|
stretchFActors.yFactor = actualAr / playerAr;
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'stretcher', "[Stretcher.js::calculateStretch] stretching strategy 5")
|
||||||
console.log("[Stretcher.js::calculateStretch] stretching strategy 5")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// VERIFIED CORRECT
|
// VERIFIED CORRECT
|
||||||
|
|
||||||
@ -179,9 +169,7 @@ class Stretcher {
|
|||||||
stretchFactors.xFactor = 1;
|
stretchFactors.xFactor = 1;
|
||||||
stretchFactors.yFactor = actualAr / playerAr;
|
stretchFactors.yFactor = actualAr / playerAr;
|
||||||
|
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'stretcher', "[Stretcher.js::calculateStretch] stretching strategy 6")
|
||||||
console.log("[Stretcher.js::calculateStretch] stretching strategy 6")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,13 +5,14 @@ import Debug from '../../conf/Debug';
|
|||||||
|
|
||||||
class Zoom {
|
class Zoom {
|
||||||
// functions
|
// functions
|
||||||
constructor(videoData) {
|
constructor(videoData, logger) {
|
||||||
this.scale = 1;
|
this.scale = 1;
|
||||||
this.logScale = 0;
|
this.logScale = 0;
|
||||||
this.scaleStep = 0.1;
|
this.scaleStep = 0.1;
|
||||||
this.minScale = -1; // 50% (log2(0.5) = -1)
|
this.minScale = -1; // 50% (log2(0.5) = -1)
|
||||||
this.maxScale = 3; // 800% (log2(8) = 3)
|
this.maxScale = 3; // 800% (log2(8) = 3)
|
||||||
this.conf = videoData;
|
this.conf = videoData;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(){
|
reset(){
|
||||||
@ -30,18 +31,14 @@ class Zoom {
|
|||||||
|
|
||||||
this.scale = Math.pow(2, this.logScale);
|
this.scale = Math.pow(2, this.logScale);
|
||||||
|
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Zoom::zoomStep] changing zoom by", amount, ". New zoom level:", this.scale);
|
||||||
console.log("[Zoom::zoomStep] changing zoom by", amount, ". New zoom level:", this.scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.conf.restoreAr();
|
this.conf.restoreAr();
|
||||||
this.conf.announceZoom(this.scale);
|
this.conf.announceZoom(this.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
setZoom(scale, no_announce){
|
setZoom(scale, no_announce){
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Zoom::setZoom] Setting zoom to", scale, "!");
|
||||||
console.log("[Zoom::setZoom] Setting zoom to", scale, "!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: SCALE IS NOT LOGARITHMIC
|
// NOTE: SCALE IS NOT LOGARITHMIC
|
||||||
if(scale < Math.pow(2, this.minScale)) {
|
if(scale < Math.pow(2, this.minScale)) {
|
||||||
@ -62,16 +59,12 @@ class Zoom {
|
|||||||
if (!stretchFactors) {
|
if (!stretchFactors) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Zoom::setZoom] Applying zoom. Stretch factors pre:", stretchFactors, " —> scale:", this.scale);
|
||||||
console.log("[Zoom::setZoom] Applying zoom. Stretch factors pre:", stretchFactors, " —> scale:", this.scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
stretchFactors.xFactor *= this.scale;
|
stretchFactors.xFactor *= this.scale;
|
||||||
stretchFactors.yFactor *= this.scale;
|
stretchFactors.yFactor *= this.scale;
|
||||||
|
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[Zoom::setZoom] Applying zoom. Stretch factors post:", stretchFactors);
|
||||||
console.log("[Zoom::setZoom] Applying zoom. Stretch factors post:", stretchFactors);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import Settings from './lib/Settings';
|
|||||||
import ActionHandler from './lib/ActionHandler';
|
import ActionHandler from './lib/ActionHandler';
|
||||||
import CommsClient from './lib/comms/CommsClient';
|
import CommsClient from './lib/comms/CommsClient';
|
||||||
import PageInfo from './lib/video-data/PageInfo';
|
import PageInfo from './lib/video-data/PageInfo';
|
||||||
|
import Logger from './lib/Logger';
|
||||||
|
|
||||||
if(Debug.debug){
|
if(Debug.debug){
|
||||||
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
||||||
@ -30,6 +31,7 @@ class UW {
|
|||||||
this.comms = undefined;
|
this.comms = undefined;
|
||||||
this.settings = undefined;
|
this.settings = undefined;
|
||||||
this.actionHandler = undefined;
|
this.actionHandler = undefined;
|
||||||
|
this.logger = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(){
|
async init(){
|
||||||
@ -39,9 +41,8 @@ class UW {
|
|||||||
|
|
||||||
// init() is re-run any time settings change
|
// init() is re-run any time settings change
|
||||||
if (this.pageInfo) {
|
if (this.pageInfo) {
|
||||||
if(Debug.debug){
|
// if this executes, logger must have been initiated at some point before this point
|
||||||
console.log("[uw::init] Destroying existing pageInfo", this.pageInfo);
|
this.logger.log('info', 'debug', "[uw::init] Destroying existing pageInfo", this.pageInfo);
|
||||||
}
|
|
||||||
this.pageInfo.destroy();
|
this.pageInfo.destroy();
|
||||||
}
|
}
|
||||||
if (this.comms) {
|
if (this.comms) {
|
||||||
@ -54,51 +55,45 @@ class UW {
|
|||||||
await this.settings.init();
|
await this.settings.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.comms = new CommsClient('content-client-port', this.settings);
|
if (!this.logger) {
|
||||||
|
this.logger = new Logger(this.settings.getLoggingOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.comms = new CommsClient('content-client-port', this.settings, this.logger);
|
||||||
|
|
||||||
// če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar
|
// če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar
|
||||||
// If extension is soft-disabled, don't do shit
|
// If extension is soft-disabled, don't do shit
|
||||||
|
|
||||||
var extensionMode = this.settings.getExtensionMode();
|
var extensionMode = this.settings.getExtensionMode();
|
||||||
|
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'debug', "[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full'));
|
||||||
console.log("[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full'));
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSiteDisabled = extensionMode === ExtensionMode.Disabled
|
const isSiteDisabled = extensionMode === ExtensionMode.Disabled
|
||||||
|
|
||||||
if (isSiteDisabled) {
|
if (isSiteDisabled) {
|
||||||
if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) {
|
if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) {
|
||||||
if (Debug.debug) {
|
this.logger.log('info', 'debug', "[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
|
||||||
console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.pageInfo = new PageInfo(this.comms, this.settings, extensionMode, isSiteDisabled);
|
this.pageInfo = new PageInfo(this.comms, this.settings, this.logger, extensionMode, isSiteDisabled);
|
||||||
if(Debug.debug){
|
this.logger.log('info', 'debug', "[uw.js::setup] pageInfo initialized. Here's the object:", this.pageInfo);
|
||||||
console.log("[uw.js::setup] pageInfo initialized. Here's the object:", this.pageInfo);
|
|
||||||
}
|
|
||||||
this.comms.setPageInfo(this.pageInfo);
|
this.comms.setPageInfo(this.pageInfo);
|
||||||
|
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'debug', "[uw.js::setup] will try to initate ActionHandler. Settings are:", this.settings, this.settings.active)
|
||||||
console.log("[uw.js::setup] will try to initate ActionHandler. Settings are:", this.settings, this.settings.active)
|
|
||||||
}
|
|
||||||
|
|
||||||
// start action handler only if extension is enabled for this site
|
// start action handler only if extension is enabled for this site
|
||||||
if (!isSiteDisabled) {
|
if (!isSiteDisabled) {
|
||||||
this.actionHandler = new ActionHandler(this.pageInfo);
|
this.actionHandler = new ActionHandler(this.pageInfo, this.logger);
|
||||||
this.actionHandler.init();
|
this.actionHandler.init();
|
||||||
|
|
||||||
if(Debug.debug) {
|
this.logger.log('info', 'debug', "[uw.js::setup] ActionHandler initiated:", this.actionHandler);
|
||||||
console.log("[uw.js::setup] ActionHandler initiated:", this.actionHandler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("[uw::init] FAILED TO START EXTENSION. Error:", e);
|
this.logger.log('error', 'debug', "[uw::init] FAILED TO START EXTENSION. Error:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user