gamepad-trigger-rumble-effect-manual.https.html (3403B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 </head> 9 <body> 10 <p> 11 This test requires a gamepad device to be connected. Please interact with 12 the gamepad for it to be recognized. The "Trigger rumble!" button will be 13 enabled after that. 14 </p> 15 <p> 16 After pressing the "Trigger rumble!" button below, you should expect to 17 feel a localized vibration in both triggers of all connected 18 trigger-rumble compatible gamepads for one second. 19 </p> 20 <p> 21 Please press the "Confirm effect has played" button to conclude 22 the test. 23 </p> 24 <button id="play_trigger_rumble_button" disabled>No trigger-rumble gamepads detected</button> 25 <button id="confirm_effect_button" disabled>Confirm effect has played</button> 26 <script> 27 async_test(t => { 28 let connectedTriggerRumbleGamepads = {}; 29 playEffectButton = document.getElementById('play_trigger_rumble_button'); 30 31 function isTriggerRumbleSupported(gamepad) { 32 return gamepad.vibrationActuator.effects.includes('trigger-rumble'); 33 } 34 35 window.addEventListener('gamepadconnected', (e) => { 36 if (!e.gamepad || !e.gamepad.vibrationActuator || !e.gamepad.vibrationActuator.effects) { 37 return; 38 } 39 40 if (isTriggerRumbleSupported(e.gamepad)) { 41 connectedTriggerRumbleGamepads[e.gamepad.index] = e.gamepad; 42 43 if (playEffectButton.disabled) { 44 playEffectButton.disabled = false; 45 playEffectButton.innerText = 'Trigger rumble!' 46 } 47 } 48 }); 49 50 window.addEventListener('gamepaddisconnected', (e) => { 51 delete connectedTriggerRumbleGamepads[e.gamepad.index]; 52 53 let anyTriggerRumbleGamepad = false; 54 for (let index in connectedTriggerRumbleGamepads){ 55 const gamepad = connectedTriggerRumbleGamepads[index]; 56 if (!gamepad || !gamepad.vibrationActuator || !gamepad.vibrationActuator.effects) { 57 continue; 58 } 59 60 if (isTriggerRumbleSupported(gamepad)){ 61 anyTriggerRumbleGamepad = true; 62 break; 63 } 64 } 65 66 if (!anyTriggerRumbleGamepad && !playEffectButton.disabled) { 67 playEffectButton.disabled = true; 68 playEffectButton.innerText = "No trigger-rumble gamepads detected"; 69 } 70 }); 71 72 playEffectButton.addEventListener("click", () => { 73 let gamepads = navigator.getGamepads(); 74 for (const gamepad of gamepads) { 75 if (gamepad && isTriggerRumbleSupported(gamepad)) { 76 gamepad.vibrationActuator.playEffect("trigger-rumble", { 77 duration: 1000, 78 leftTrigger: 1.0, 79 rightTrigger: 1.0, 80 }); 81 } 82 } 83 84 const confirmButton = document.getElementById("confirm_effect_button"); 85 if (confirmButton.disabled) { 86 confirmButton.disabled = false; 87 } 88 confirmButton.addEventListener('click', () => { 89 t.done(); 90 }); 91 }); 92 }, "Gamepads with trigger-rumble capabilities should have the triggers' motors activated."); 93 </script> 94 </body> 95 </html>