diff --git a/gamepad.cpp b/gamepad.cpp index c18dff8..eac6979 100644 --- a/gamepad.cpp +++ b/gamepad.cpp @@ -132,14 +132,6 @@ void MoonlightInstance::PollGamepads() { void MoonlightInstance::ClControllerRumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor) { - PP_GamepadsSampleData gamepadData; - g_Instance->m_GamepadApi->Sample(g_Instance->pp_instance(), &gamepadData); - - // We must determine which gamepads are connected before sending rumble events. - const unsigned short activeGamepadMask = static_cast(GetActiveGamepadMask(gamepadData)); - if ((activeGamepadMask & (1 << controllerNumber)) == 0) - return; - const float weakMagnitude = static_cast(highFreqMotor) / static_cast(UINT16_MAX); const float strongMagnitude = static_cast(lowFreqMotor) / static_cast(UINT16_MAX); diff --git a/static/js/messages.js b/static/js/messages.js index 3a0970d..b6348ce 100644 --- a/static/js/messages.js +++ b/static/js/messages.js @@ -87,7 +87,10 @@ function handleMessage(msg) { const weakMagnitude = parseFloat(eventData[1]); const strongMagnitude = parseFloat(eventData[2]); console.log("Playing rumble on gamepad " + gamepadIdx + " with weakMagnitude " + weakMagnitude + " and strongMagnitude " + strongMagnitude); - navigator.getGamepads()[gamepadIdx].vibrationActuator.playEffect('dual-rumble', { + + // We may not actually have a gamepad at this index. + // Even if we do have a gamepad, it may not have a vibrationActuator associated with it. + navigator.getGamepads()[gamepadIdx]?.vibrationActuator?.playEffect('dual-rumble', { startDelay: 0, duration: 5000, // Moonlight should be sending another rumble event when stopping. weakMagnitude: weakMagnitude,