gamepad-dual-rumble-effect-manual.https.html (3287B)
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 "Dual rumble!" button will be 13 enabled after that. 14 </p> 15 <p> 16 After pressing the "Dual rumble!" button below, you should expect all the 17 "dual-rumble" compatible gamepads to vibrate for one second. 18 </p> 19 <p> 20 Please press the "Confirm effect has played" button to conclude 21 the test. 22 </p> 23 <button id="play_dual_rumble_button" disabled>No dual-rumble gamepads detected</button> 24 <button id="confirm_effect_button" disabled>Confirm effect has played</button> 25 <script> 26 async_test(t => { 27 let connectedDualRumbleGamepads = {}; 28 playEffectButton = document.getElementById('play_dual_rumble_button'); 29 30 function isDualRumbleSupported(gamepad) { 31 return gamepad.vibrationActuator.effects.includes('dual-rumble'); 32 } 33 34 window.addEventListener('gamepadconnected', (e) => { 35 if (!e.gamepad || !e.gamepad.vibrationActuator || !e.gamepad.vibrationActuator.effects) { 36 return; 37 } 38 39 if (isDualRumbleSupported(e.gamepad)) { 40 connectedDualRumbleGamepads[e.gamepad.index] = e.gamepad; 41 42 if (playEffectButton.disabled) { 43 playEffectButton.disabled = false; 44 playEffectButton.innerText = 'Dual rumble!' 45 } 46 } 47 }); 48 49 window.addEventListener('gamepaddisconnected', (e) => { 50 delete connectedDualRumbleGamepads[e.gamepad.index]; 51 52 let anyDualRumbleGamepad = false; 53 for (let index in connectedDualRumbleGamepads){ 54 const gamepad = connectedDualRumbleGamepads[index]; 55 if (!gamepad || !gamepad.vibrationActuator || !gamepad.vibrationActuator.effects) { 56 continue; 57 } 58 59 if (isDualRumbleSupported(gamepad)){ 60 anyDualRumbleGamepad = true; 61 break; 62 } 63 } 64 65 if (!anyDualRumbleGamepad && !playEffectButton.disabled) { 66 playEffectButton.disabled = true; 67 playEffectButton.innerText = "No dual-rumble gamepads detected"; 68 } 69 }); 70 71 playEffectButton.addEventListener("click", () => { 72 let gamepads = navigator.getGamepads(); 73 for (const gamepad of gamepads) { 74 if (gamepad && isDualRumbleSupported(gamepad)) { 75 gamepad.vibrationActuator.playEffect("dual-rumble", { 76 duration: 1000, 77 strongMagnitude: 1.0, 78 weakMagnitude: 1.0, 79 }); 80 } 81 } 82 83 const confirmButton = document.getElementById("confirm_effect_button"); 84 if (confirmButton.disabled) { 85 confirmButton.disabled = false; 86 } 87 confirmButton.addEventListener('click', () => { 88 t.done(); 89 }); 90 }); 91 }, "Gamepads with dual-rumble capabilities should have the body's motors activated."); 92 </script> 93 </body> 94 </html>