Browse Source

Add input processing. (#28)

Ian Walton 3 years ago
parent
commit
1fe4ce50b9
2 changed files with 39 additions and 0 deletions
  1. 34 0
      native/jmpInputPlugin.js
  2. 5 0
      native/nativeshell.js

+ 34 - 0
native/jmpInputPlugin.js

@@ -0,0 +1,34 @@
+const remap = {
+    "play_pause": "playpause",
+    "seek_forward": "fastforward",
+    "seek_backward": "rewind",
+    "host:fullscreen": "togglefullscreen",
+    "cycle_audio": "changeaudiotrack",
+    "cycle_subtitles": "changesubtitletrack",
+    "increase_volume": "volumeup",
+    "decrease_volume": "volumedown",
+    "step_backward": "previouschapter",
+    "step_forward": "nextchapter",
+    "enter": "select",
+}
+
+class jmpInputPlugin {
+    constructor({ inputManager }) {
+        this.name = 'JMP Input Plugin';
+        this.type = 'input';
+        this.id = 'jmpInputPlugin';
+
+        window.api.input.hostInput.connect((actions) => {
+            actions.forEach(action => {
+                if (remap.hasOwnProperty(action)) {
+                    action = remap[action];
+                }
+                inputManager.handleCommand(action, {});
+            });
+        });
+
+        window.api.system.hello("jmpInputPlugin");
+    }
+}
+
+window._jmpInputPlugin = jmpInputPlugin;

+ 5 - 0
native/nativeshell.js

@@ -11,11 +11,16 @@ const features = [
     "multiserver",
     "remotecontrol",
     "fullscreenchange",
+    "filedownload",
+    "remotevideo",
+    "displaymode",
+    "screensaver"
 ];
 
 const plugins = [
     'mpvVideoPlayer',
     'mpvAudioPlayer',
+    'jmpInputPlugin'
 ];
 
 function loadScript(src) {