From 28c12861e535e37dfab728f234da0631f8e7b964 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Wed, 21 Oct 2020 23:52:16 +0200 Subject: [PATCH] Change action handler --- src/ext/lib/ActionHandler.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ext/lib/ActionHandler.js b/src/ext/lib/ActionHandler.js index c0d2bf0..dd34e3e 100644 --- a/src/ext/lib/ActionHandler.js +++ b/src/ext/lib/ActionHandler.js @@ -104,14 +104,36 @@ class ActionHandler { } } - document.addEventListener('keydown', (event) => ths.handleKeydown(event) ); - document.addEventListener('keyup', (event) => ths.handleKeyup(event) ); + // events should be handled in handleEvent function. We need to do things this + // way, otherwise we can't remove event listenerđ + // https://stackoverflow.com/a/19507086 + document.addEventListener('keydown', this ); + document.addEventListener('keyup', this ); this.pageInfo.setActionHandler(this); this.logger.log('info', 'debug', "[ActionHandler::init] initialization complete"); } + handleEvent(event) { + switch(event.type) { + case 'keydown': + this.handleKeydown(event); + break; + case 'keyup': + this.handleKeyup(event); + break; + case 'mousemove': + this.handleMouseMove(event); + break; + } + } + + destroy() { + document.removeEventListener('keydown', this); + document.removeEventListener('keyup', this); + } + registerHandleMouse(videoData) { this.logger.log('info', ['actionHandler', 'mousemove'], "[ActionHandler::registerHandleMouse] registering handle mouse for videodata:", videoData.id)