add playerMouseHandler
This commit is contained in:
parent
08479242f7
commit
c954f8b984
@ -1,13 +1,13 @@
|
||||
import Debug from './conf/Debug';
|
||||
import ExtensionMode from '../common/enums/ExtensionMode.enum';
|
||||
import Settings from './lib/Settings';
|
||||
import KeyboardHandler from '../../../../KeyboardHandler';
|
||||
import Comms from './lib/comms/Comms';
|
||||
import CommsClient from './lib/comms/CommsClient';
|
||||
import PageInfo from './lib/video-data/PageInfo';
|
||||
import Logger, { baseLoggingOptions } from './lib/Logger';
|
||||
import UWGlobals from './lib/UWGlobals';
|
||||
import EventBus from './lib/EventBus';
|
||||
import KeyboardHandler from './lib/kbm/KeyboardHandler';
|
||||
|
||||
export default class UWContent {
|
||||
pageInfo: PageInfo;
|
||||
|
@ -19,7 +19,7 @@ if(process.env.CHANNEL !== 'stable'){
|
||||
* kbm-disable disables keyboard shortcuts and mouse panning
|
||||
* kbm-set-config sets configuration for this module.
|
||||
*/
|
||||
class KeyboardHandler {
|
||||
export class KeyboardHandler {
|
||||
logger: Logger;
|
||||
settings: Settings;
|
||||
eventBus: EventBus;
|
||||
@ -133,9 +133,6 @@ class KeyboardHandler {
|
||||
case 'keyup':
|
||||
this.handleKeyup(event);
|
||||
break;
|
||||
case 'mousemove':
|
||||
this.handleMouseMove(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +140,7 @@ class KeyboardHandler {
|
||||
* Enables KeyboardHandler
|
||||
*/
|
||||
enable() {
|
||||
this.addListener();
|
||||
this.load();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,12 +161,6 @@ class KeyboardHandler {
|
||||
case 'enabled':
|
||||
config[confKey] ? this.enable() : this.disable();
|
||||
break;
|
||||
case 'keyboardEnabled':
|
||||
this.keyboardEnabled = config[confKey];
|
||||
break;
|
||||
case 'mouseEnabled':
|
||||
this.mouseEnabled = config[confKey];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -183,23 +174,6 @@ class KeyboardHandler {
|
||||
this.load();
|
||||
}
|
||||
|
||||
|
||||
registerHandleMouse(videoData) {
|
||||
this.logger.log('info', ['KeyboardHandler', 'mousemove'], "[KeyboardHandler::registerHandleMouse] registering handle mouse for videodata:", videoData.id)
|
||||
|
||||
var ths = this;
|
||||
if (videoData.player && videoData.player.element) {
|
||||
videoData.player.element.addEventListener('mousemove', (event) => ths.handleMouseMove(event, videoData));
|
||||
}
|
||||
}
|
||||
|
||||
unregisterHandleMouse(videoData) {
|
||||
var ths = this;
|
||||
if (videoData.player && videoData.player.element) {
|
||||
videoData.player.element.removeEventListener('mousemove', (event) => ths.handleMouseMove(event, videoData));
|
||||
}
|
||||
}
|
||||
|
||||
setKeyboardLocal(state) {
|
||||
if (state === ExtensionMode.Enabled) {
|
||||
this.keyboardLocalDisabled = false;
|
||||
@ -306,10 +280,10 @@ class KeyboardHandler {
|
||||
|
||||
|
||||
handleKeyup(event) {
|
||||
if (!this.keyboardEnabled) {
|
||||
this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] kbmHandler.keyboardEnabled is set to false. Doing nothing.");
|
||||
return;
|
||||
}
|
||||
// if (!this.keyboardEnabled) {
|
||||
// this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] kbmHandler.keyboardEnabled is set to false. Doing nothing.");
|
||||
// return;
|
||||
// }
|
||||
this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] we pressed a key: ", "color: #ff0", event.key , " | keyup: ", event.keyup, "event:", event);
|
||||
|
||||
try {
|
||||
@ -332,19 +306,6 @@ class KeyboardHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
handleMouseMove(event, videoData?: VideoData) {
|
||||
if (!this.mouseEnabled) {
|
||||
this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] kbmHandler.keyboardEnabled is set to false. Doing nothing.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.log('info', 'keyboard', "[KeyboardHandler::handleMouseMove] mouse move is being handled.\nevent:", event, "\nvideo data:", videoData);
|
||||
console.info('mousemove must be migrated!');
|
||||
// videoData?.panHandler(event);
|
||||
// this.execAction(this.mouseMoveActions, event, videoData)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(process.env.CHANNEL !== 'stable'){
|
||||
|
100
src/ext/lib/kbm/PlayerMouseHandler.ts
Normal file
100
src/ext/lib/kbm/PlayerMouseHandler.ts
Normal file
@ -0,0 +1,100 @@
|
||||
import EventBus, { EventBusCommand } from '../EventBus';
|
||||
import Logger from '../Logger';
|
||||
import Settings from '../Settings';
|
||||
|
||||
if(process.env.CHANNEL !== 'stable'){
|
||||
console.info("Loading PlayerMouseHandler");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles keypress
|
||||
*/
|
||||
export class MouseHandler {
|
||||
logger: Logger;
|
||||
settings: Settings;
|
||||
eventBus: EventBus;
|
||||
playerElement: HTMLElement;
|
||||
|
||||
eventBusCommands: { [x: string]: EventBusCommand } = {
|
||||
'kbm-enable': {
|
||||
function: () => this.enable()
|
||||
},
|
||||
'kbm-disable': {
|
||||
function: () => this.disable()
|
||||
},
|
||||
'kbm-set-config': {
|
||||
function: (data: {config: any, temporary?: boolean}) => this.setConfig(data.config, data.temporary),
|
||||
},
|
||||
'uw-enable': {
|
||||
function: () => this.load()
|
||||
},
|
||||
'uw-disable': {
|
||||
function: () => this.disable()
|
||||
},
|
||||
}
|
||||
|
||||
//#region lifecycle
|
||||
constructor(playerElement: HTMLElement, eventBus: EventBus, settings: Settings, logger: Logger) {
|
||||
this.logger = logger;
|
||||
this.settings = settings;
|
||||
this.eventBus = eventBus;
|
||||
this.playerElement = playerElement;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.logger.log('info', 'debug', '[MouseHandler::init] starting init');
|
||||
}
|
||||
|
||||
load() {
|
||||
if (!this.settings.isEnabledForSite() || this.settings.active.kbm.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.addListener();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.removeListener();
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region listener setup, teardown, handling
|
||||
private addListener() {
|
||||
if (this.settings.active.kbm.enabled && this.settings.active.kbm.mouseEnabled) {
|
||||
this.playerElement.addEventListener('mousemove', this);
|
||||
}
|
||||
}
|
||||
|
||||
private removeListener() {
|
||||
this.playerElement.removeEventListener('mousemove', this);
|
||||
}
|
||||
|
||||
handleEvent(event: MouseEvent) {
|
||||
switch (event.type) {
|
||||
case 'mousemove':
|
||||
this.handleMouseMove(event)
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
enable() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
disable() {
|
||||
this.removeListener();
|
||||
}
|
||||
|
||||
private setConfig(config, isTemporary?) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private handleMouseMove(event: MouseEvent) {
|
||||
|
||||
}
|
||||
}
|
@ -61,7 +61,7 @@ class PageInfo {
|
||||
extensionMode: ExtensionMode;
|
||||
defaultCrop: any;
|
||||
currentCrop: any;
|
||||
kbmHandlerInitQueue: any[] = [];
|
||||
keyboardHandlerInitQueue: any[] = [];
|
||||
currentZoomScale: number = 1;
|
||||
|
||||
keyboardHandler: any;
|
||||
|
Loading…
Reference in New Issue
Block a user