Migrate actionhandler to ts
This commit is contained in:
parent
075168ed85
commit
7e41768aba
@ -1,20 +1,37 @@
|
|||||||
import Debug from '../conf/Debug';
|
import Debug from '../conf/Debug';
|
||||||
import PlayerData from './video-data/PlayerData';
|
import PlayerData from './video-data/PlayerData';
|
||||||
import ExtensionMode from '../../common/enums/ExtensionMode.enum';
|
import ExtensionMode from '../../common/enums/ExtensionMode.enum';
|
||||||
|
import Logger from './Logger';
|
||||||
|
import PageInfo from './video-data/PageInfo';
|
||||||
|
import Settings from './Settings';
|
||||||
|
import VideoData from './video-data/VideoData';
|
||||||
|
|
||||||
if(process.env.CHANNEL !== 'stable'){
|
if(process.env.CHANNEL !== 'stable'){
|
||||||
console.info("Loading ActionHandler");
|
console.info("Loading ActionHandler");
|
||||||
}
|
}
|
||||||
|
|
||||||
class ActionHandler {
|
class ActionHandler {
|
||||||
|
logger: Logger;
|
||||||
|
pageInfo: PageInfo;
|
||||||
|
settings: Settings;
|
||||||
|
|
||||||
|
|
||||||
|
inputs: string[] = ['input', 'select', 'button', 'textarea'];
|
||||||
|
keyboardLocalDisabled: boolean = true;
|
||||||
|
|
||||||
|
keyUpActions: any[] = [];
|
||||||
|
keyDownActions: any[] = [];
|
||||||
|
mouseMoveActions: any[] = [];
|
||||||
|
mouseScrollUpActions: any[] = [];
|
||||||
|
mouseScrollDownActions: any[] = [];
|
||||||
|
mouseEnterActions: any[] = [];
|
||||||
|
mouseLeaveActions: any[] = [];
|
||||||
|
|
||||||
|
|
||||||
constructor(pageInfo) {
|
constructor(pageInfo) {
|
||||||
this.logger = pageInfo.logger;
|
this.logger = pageInfo.logger;
|
||||||
this.pageInfo = pageInfo;
|
this.pageInfo = pageInfo;
|
||||||
this.settings = pageInfo.settings;
|
this.settings = pageInfo.settings;
|
||||||
|
|
||||||
this.inputs = ['input', 'select', 'button', 'textarea'];
|
|
||||||
this.keyboardLocalDisabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
@ -240,7 +257,7 @@ class ActionHandler {
|
|||||||
this.isActionMatchStandard(shortcut, event) || this.isActionMatchKeyCode(shortcut, event);
|
this.isActionMatchStandard(shortcut, event) || this.isActionMatchKeyCode(shortcut, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
execAction(actions, event, videoData) {
|
execAction(actions, event, videoData?: VideoData) {
|
||||||
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event);
|
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event);
|
||||||
|
|
||||||
const isLatin = event.key ? this.isLatin(event.key) : true;
|
const isLatin = event.key ? this.isLatin(event.key) : true;
|
||||||
@ -275,10 +292,10 @@ class ActionHandler {
|
|||||||
this.settings.active.sites[site].stretch = cmd.arg;
|
this.settings.active.sites[site].stretch = cmd.arg;
|
||||||
} else if (cmd.action === "set-alignment") {
|
} else if (cmd.action === "set-alignment") {
|
||||||
this.settings.active.sites[site].videoAlignment = cmd.arg;
|
this.settings.active.sites[site].videoAlignment = cmd.arg;
|
||||||
} else if (cmd.action === "set-ExtensionMode") {
|
} else if (cmd.action === "set-extension-mode") {
|
||||||
this.settings.active.sites[site].status = cmd.arg;
|
this.settings.active.sites[site].mode = cmd.arg;
|
||||||
} else if (cmd.action === "set-autoar-mode") {
|
} else if (cmd.action === "set-autoar-mode") {
|
||||||
this.settings.active.sites[site].arStatus = cmd.arg;
|
this.settings.active.sites[site].autoar = cmd.arg;
|
||||||
} else if (cmd.action === 'set-keyboard') {
|
} else if (cmd.action === 'set-keyboard') {
|
||||||
this.settings.active.sites[site].keyboardShortcutsEnabled = cmd.arg;
|
this.settings.active.sites[site].keyboardShortcutsEnabled = cmd.arg;
|
||||||
} else if (cmd.action === 'set-ar-persistence') {
|
} else if (cmd.action === 'set-ar-persistence') {
|
||||||
@ -323,9 +340,9 @@ class ActionHandler {
|
|||||||
this.execAction(this.keyDownActions, event);
|
this.execAction(this.keyDownActions, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseMove(event, videoData) {
|
handleMouseMove(event, videoData?: VideoData) {
|
||||||
this.logger.log('info', 'keyboard', "[ActionHandler::handleMouseMove] mouse move is being handled.\nevent:", event, "\nvideo data:", videoData);
|
this.logger.log('info', 'keyboard', "[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)
|
||||||
}
|
}
|
||||||
|
|
@ -439,7 +439,7 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setAr(ar, playingOnly){
|
setAr(ar, playingOnly?: boolean){
|
||||||
this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly)
|
this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly)
|
||||||
|
|
||||||
if (ar.type !== AspectRatioType.Automatic) {
|
if (ar.type !== AspectRatioType.Automatic) {
|
||||||
@ -491,7 +491,7 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setPanMode(mode, playingOnly) {
|
setPanMode(mode, playingOnly?: boolean) {
|
||||||
if (playingOnly) {
|
if (playingOnly) {
|
||||||
for(let vd of this.videos) {
|
for(let vd of this.videos) {
|
||||||
if (vd.isPlaying()) {
|
if (vd.isPlaying()) {
|
||||||
@ -519,7 +519,7 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setStretchMode(stretchMode, playingOnly, fixedStretchRatio){
|
setStretchMode(stretchMode, playingOnly?: boolean, fixedStretchRatio?: boolean){
|
||||||
// TODO: find a way to only change aspect ratio for one video
|
// TODO: find a way to only change aspect ratio for one video
|
||||||
|
|
||||||
if (playingOnly) {
|
if (playingOnly) {
|
||||||
@ -535,7 +535,7 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setZoom(zoomLevel, no_announce, playingOnly) {
|
setZoom(zoomLevel, no_announce?: boolean, playingOnly?: boolean) {
|
||||||
if (playingOnly) {
|
if (playingOnly) {
|
||||||
for(let vd of this.videos) {
|
for(let vd of this.videos) {
|
||||||
if (vd.isPlaying()) {
|
if (vd.isPlaying()) {
|
||||||
@ -549,7 +549,7 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomStep(step, playingOnly) {
|
zoomStep(step, playingOnly?: boolean) {
|
||||||
for(let vd of this.videos){
|
for(let vd of this.videos){
|
||||||
if (!playingOnly || vd.isPlaying()) {
|
if (!playingOnly || vd.isPlaying()) {
|
||||||
vd.zoomStep(step);
|
vd.zoomStep(step);
|
||||||
|
@ -606,7 +606,7 @@ class VideoData {
|
|||||||
this.resizer.setLastAr('original');
|
this.resizer.setLastAr('original');
|
||||||
}
|
}
|
||||||
|
|
||||||
panHandler(event, forcePan) {
|
panHandler(event, forcePan?: boolean) {
|
||||||
if (this.invalid) {
|
if (this.invalid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user