1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Moved gamepad to input and serverNotofications cleanup

This commit is contained in:
ferferga 2020-02-05 14:13:28 +01:00
parent c60dbbb3ae
commit ab0a9ef065
4 changed files with 120 additions and 107 deletions

View file

@ -255,13 +255,11 @@ require(['apphost'], function (appHost) {
// Get the latest gamepad state.
var gamepads;
gamepads = navigator.getGamepads();
gamepads = gamepads || [];
var i;
var j;
var len;
for (i = 0, len = gamepads.length; i < len; i++) {
var gamepad = gamepads[i];
if (gamepad) {
// Iterate through the axes
var axes = gamepad.axes;
var leftStickX = axes[0];
@ -284,7 +282,6 @@ require(['apphost'], function (appHost) {
var buttons = gamepad.buttons;
for (j = 0, len = buttons.length; j < len; j++) {
if (ProcessedButtons.indexOf(j) !== -1) {
if (buttons[j].pressed) {
switch (j) {
case _GAMEPAD_DPAD_UP_BUTTON_INDEX:
@ -349,7 +346,6 @@ require(['apphost'], function (appHost) {
}
}
}
}
// Schedule the next one
requestAnimationFrame(runInputLoop);
}

View file

@ -126,6 +126,45 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
});
}
function isGamepadConnected() {
var gamepads = navigator.getGamepads();
var i, len;
for (i = 0, len = gamepads.length; i < len; i++) {
var gamepad = gamepads[i];
if (gamepad) {
console.log(gamepad);
return true;
}
}
return false;
}
function attachGamepad(e) {
if (isGamepadConnected()) {
require(["components/input/gamepadtokey"]);
console.log("Gamepad connected! Attaching gamepadtokey.js script");
}
}
function dettachGamepad(e) {
if (!isGamepadConnected()) {
delete require.cache[require(["components/input/gamepadtokey"])];
console.log("Gamepad disconnected! No other gamepads are connected, dettaching gamepadtokey.js");
} else {
console.log("Gamepad disconnected! There are gamepads still connected.");
}
}
if (isGamepadConnected()) {
console.log("Gamepad connected! Attaching gamepadtokey.js script");
} else {
console.log("No gamepad connected to this device");
}
// No need to check for gamepads manually at load time, the eventhandler will be fired at load time as well
window.addEventListener("gamepaddisconnected", dettachGamepad);
window.addEventListener("gamepadconnected", attachGamepad);
require(["components/input/mouseManager"]);
return {
enable: enable,
getKeyName: getKeyName

View file

@ -191,36 +191,14 @@ define(['connectionManager', 'playbackManager', 'events', 'inputManager', 'focus
events.trigger(serverNotifications, msg.MessageType, [apiClient, msg.Data]);
}
}
function bindEvents(apiClient) {
events.off(apiClient, "message", onMessageReceived);
events.on(apiClient, "message", onMessageReceived);
}
function attachgamepad(e) {
if (navigator.getGamepads.length > 0) {
require(["components/serverNotifications/gamepadtokey"]);
console.log("Gamepad connected! Attaching gamepadtokey.js script");
}
}
function dettachgamepad(e) {
delete require.cache[require(["components/serverNotifications/gamepadtokey"])];
console.log("Gamepad disconnected! Dettaching gamepadtokey.js");
}
connectionManager.getApiClients().forEach(bindEvents);
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {
bindEvents(newApiClient);
});
if (navigator.getGamepads()[0] != null) {
require(["components/serverNotifications/gamepadtokey"]);
console.log("Gamepad connected! Attaching gamepadtokey.js script");
window.addEventListener("gamepaddisconnected", dettachgamepad);
} else {
window.addEventListener("gamepadconnected", attachgamepad);
console.log("No gamepad connected to this device");
}
// require(["components/serverNotifications/mouseManager"]);
return serverNotifications;
});