Added controller rumble support.

Pepper SDK and NaCl in general is EOL for Chrome, although still supported for Chrome Apps.
This means that the Pepper Gamepad API was never updated with rumble support so in order
to add rumble support, rumble messages from Gamestream have to be forwarded to JavaScript
and handled with gamepad.vibrationActuator.playEffect().

Side note, Chrome limits the duration of playEffect to 5 seconds and requesting more than
that causes the vibration request to be rejected.
This commit is contained in:
bob
2022-10-20 06:52:28 +00:00
committed by Cameron Gutman
parent ab3aac8d05
commit aaa1ca7079
5 changed files with 28 additions and 1 deletions

View File

@@ -81,6 +81,18 @@ function handleMessage(msg) {
snackbarLogLong(msg.data.replace('DialogMsg: ', ''));
} else if (msg.data === 'displayVideo') {
$("#listener").addClass("fullscreen");
} else if (msg.data.indexOf('controllerRumble: ' ) === 0) {
const eventData = msg.data.split( ' ' )[1].split(',');
const gamepadIdx = parseInt(eventData[0]);
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', {
startDelay: 0,
duration: 5000, // Moonlight should be sending another rumble event when stopping.
weakMagnitude: weakMagnitude,
strongMagnitude: strongMagnitude,
});
}
}
}