add playerMouseHandler
This commit is contained in:
parent
08479242f7
commit
c954f8b984
@ -1,13 +1,13 @@
|
|||||||
import Debug from './conf/Debug';
|
import Debug from './conf/Debug';
|
||||||
import ExtensionMode from '../common/enums/ExtensionMode.enum';
|
import ExtensionMode from '../common/enums/ExtensionMode.enum';
|
||||||
import Settings from './lib/Settings';
|
import Settings from './lib/Settings';
|
||||||
import KeyboardHandler from '../../../../KeyboardHandler';
|
|
||||||
import Comms from './lib/comms/Comms';
|
import Comms from './lib/comms/Comms';
|
||||||
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, { baseLoggingOptions } from './lib/Logger';
|
import Logger, { baseLoggingOptions } from './lib/Logger';
|
||||||
import UWGlobals from './lib/UWGlobals';
|
import UWGlobals from './lib/UWGlobals';
|
||||||
import EventBus from './lib/EventBus';
|
import EventBus from './lib/EventBus';
|
||||||
|
import KeyboardHandler from './lib/kbm/KeyboardHandler';
|
||||||
|
|
||||||
export default class UWContent {
|
export default class UWContent {
|
||||||
pageInfo: PageInfo;
|
pageInfo: PageInfo;
|
||||||
|
@ -19,7 +19,7 @@ if(process.env.CHANNEL !== 'stable'){
|
|||||||
* kbm-disable disables keyboard shortcuts and mouse panning
|
* kbm-disable disables keyboard shortcuts and mouse panning
|
||||||
* kbm-set-config sets configuration for this module.
|
* kbm-set-config sets configuration for this module.
|
||||||
*/
|
*/
|
||||||
class KeyboardHandler {
|
export class KeyboardHandler {
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
settings: Settings;
|
settings: Settings;
|
||||||
eventBus: EventBus;
|
eventBus: EventBus;
|
||||||
@ -133,9 +133,6 @@ class KeyboardHandler {
|
|||||||
case 'keyup':
|
case 'keyup':
|
||||||
this.handleKeyup(event);
|
this.handleKeyup(event);
|
||||||
break;
|
break;
|
||||||
case 'mousemove':
|
|
||||||
this.handleMouseMove(event);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +140,7 @@ class KeyboardHandler {
|
|||||||
* Enables KeyboardHandler
|
* Enables KeyboardHandler
|
||||||
*/
|
*/
|
||||||
enable() {
|
enable() {
|
||||||
this.addListener();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,12 +161,6 @@ class KeyboardHandler {
|
|||||||
case 'enabled':
|
case 'enabled':
|
||||||
config[confKey] ? this.enable() : this.disable();
|
config[confKey] ? this.enable() : this.disable();
|
||||||
break;
|
break;
|
||||||
case 'keyboardEnabled':
|
|
||||||
this.keyboardEnabled = config[confKey];
|
|
||||||
break;
|
|
||||||
case 'mouseEnabled':
|
|
||||||
this.mouseEnabled = config[confKey];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -183,23 +174,6 @@ class KeyboardHandler {
|
|||||||
this.load();
|
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) {
|
setKeyboardLocal(state) {
|
||||||
if (state === ExtensionMode.Enabled) {
|
if (state === ExtensionMode.Enabled) {
|
||||||
this.keyboardLocalDisabled = false;
|
this.keyboardLocalDisabled = false;
|
||||||
@ -306,10 +280,10 @@ class KeyboardHandler {
|
|||||||
|
|
||||||
|
|
||||||
handleKeyup(event) {
|
handleKeyup(event) {
|
||||||
if (!this.keyboardEnabled) {
|
// if (!this.keyboardEnabled) {
|
||||||
this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] kbmHandler.keyboardEnabled is set to false. Doing nothing.");
|
// this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] kbmHandler.keyboardEnabled is set to false. Doing nothing.");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] we pressed a key: ", "color: #ff0", event.key , " | keyup: ", event.keyup, "event:", event);
|
this.logger.log('info', 'keyboard', "%c[KeyboardHandler::handleKeyup] we pressed a key: ", "color: #ff0", event.key , " | keyup: ", event.keyup, "event:", event);
|
||||||
|
|
||||||
try {
|
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'){
|
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;
|
extensionMode: ExtensionMode;
|
||||||
defaultCrop: any;
|
defaultCrop: any;
|
||||||
currentCrop: any;
|
currentCrop: any;
|
||||||
kbmHandlerInitQueue: any[] = [];
|
keyboardHandlerInitQueue: any[] = [];
|
||||||
currentZoomScale: number = 1;
|
currentZoomScale: number = 1;
|
||||||
|
|
||||||
keyboardHandler: any;
|
keyboardHandler: any;
|
||||||
|
Loading…
Reference in New Issue
Block a user