Skip to content

Add Gamepad vibrationActuator API to web-sys #4098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
* Add bindings to `RTCRtpTransceiverDirection.stopped`.
[#4102](https://github.com/rustwasm/wasm-bindgen/pull/4102)

* Added support for the `vibrationActuator` API in `Gamepad`.
[#4098](https://github.com/rustwasm/wasm-bindgen/pull/4098)

### Changed

* Deprecated `hapticActuators` API in `Gamepad`.
[#4098](https://github.com/rustwasm/wasm-bindgen/pull/4098)

### Fixed

* Fixed linked modules emitting snippet files when not using `--split-linked-modules`.
Expand Down
3 changes: 3 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,14 @@ GamepadAxisMoveEventInit = []
GamepadButton = []
GamepadButtonEvent = ["Event", "GamepadEvent"]
GamepadButtonEventInit = []
GamepadEffectParameters = []
GamepadEvent = ["Event"]
GamepadEventInit = []
GamepadHand = []
GamepadHapticActuator = []
GamepadHapticActuatorType = []
GamepadHapticEffectType = []
GamepadHapticsResult = []
GamepadMappingType = []
GamepadPose = []
GamepadServiceTest = []
Expand Down
9 changes: 9 additions & 0 deletions crates/web-sys/src/features/gen_Gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,14 @@ extern "C" {
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/hapticActuators)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Gamepad`*"]
#[deprecated]
pub fn haptic_actuators(this: &Gamepad) -> ::js_sys::Array;
#[cfg(feature = "GamepadHapticActuator")]
# [wasm_bindgen (structural , method , getter , js_class = "Gamepad" , js_name = vibrationActuator)]
#[doc = "Getter for the `vibrationActuator` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/vibrationActuator)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Gamepad`, `GamepadHapticActuator`*"]
pub fn vibration_actuator(this: &Gamepad) -> GamepadHapticActuator;
}
118 changes: 118 additions & 0 deletions crates/web-sys/src/features/gen_GamepadEffectParameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = GamepadEffectParameters)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `GamepadEffectParameters` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
pub type GamepadEffectParameters;
#[doc = "Get the `duration` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, getter = "duration")]
pub fn get_duration(this: &GamepadEffectParameters) -> Option<f64>;
#[doc = "Change the `duration` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, setter = "duration")]
pub fn set_duration(this: &GamepadEffectParameters, val: f64);
#[doc = "Get the `leftTrigger` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, getter = "leftTrigger")]
pub fn get_left_trigger(this: &GamepadEffectParameters) -> Option<f64>;
#[doc = "Change the `leftTrigger` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, setter = "leftTrigger")]
pub fn set_left_trigger(this: &GamepadEffectParameters, val: f64);
#[doc = "Get the `rightTrigger` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, getter = "rightTrigger")]
pub fn get_right_trigger(this: &GamepadEffectParameters) -> Option<f64>;
#[doc = "Change the `rightTrigger` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, setter = "rightTrigger")]
pub fn set_right_trigger(this: &GamepadEffectParameters, val: f64);
#[doc = "Get the `startDelay` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, getter = "startDelay")]
pub fn get_start_delay(this: &GamepadEffectParameters) -> Option<f64>;
#[doc = "Change the `startDelay` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, setter = "startDelay")]
pub fn set_start_delay(this: &GamepadEffectParameters, val: f64);
#[doc = "Get the `strongMagnitude` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, getter = "strongMagnitude")]
pub fn get_strong_magnitude(this: &GamepadEffectParameters) -> Option<f64>;
#[doc = "Change the `strongMagnitude` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, setter = "strongMagnitude")]
pub fn set_strong_magnitude(this: &GamepadEffectParameters, val: f64);
#[doc = "Get the `weakMagnitude` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, getter = "weakMagnitude")]
pub fn get_weak_magnitude(this: &GamepadEffectParameters) -> Option<f64>;
#[doc = "Change the `weakMagnitude` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
#[wasm_bindgen(method, setter = "weakMagnitude")]
pub fn set_weak_magnitude(this: &GamepadEffectParameters, val: f64);
}
impl GamepadEffectParameters {
#[doc = "Construct a new `GamepadEffectParameters`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[deprecated = "Use `set_duration()` instead."]
pub fn duration(&mut self, val: f64) -> &mut Self {
self.set_duration(val);
self
}
#[deprecated = "Use `set_left_trigger()` instead."]
pub fn left_trigger(&mut self, val: f64) -> &mut Self {
self.set_left_trigger(val);
self
}
#[deprecated = "Use `set_right_trigger()` instead."]
pub fn right_trigger(&mut self, val: f64) -> &mut Self {
self.set_right_trigger(val);
self
}
#[deprecated = "Use `set_start_delay()` instead."]
pub fn start_delay(&mut self, val: f64) -> &mut Self {
self.set_start_delay(val);
self
}
#[deprecated = "Use `set_strong_magnitude()` instead."]
pub fn strong_magnitude(&mut self, val: f64) -> &mut Self {
self.set_strong_magnitude(val);
self
}
#[deprecated = "Use `set_weak_magnitude()` instead."]
pub fn weak_magnitude(&mut self, val: f64) -> &mut Self {
self.set_weak_magnitude(val);
self
}
}
impl Default for GamepadEffectParameters {
fn default() -> Self {
Self::new()
}
}
42 changes: 42 additions & 0 deletions crates/web-sys/src/features/gen_GamepadHapticActuator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,58 @@ extern "C" {
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator/type)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadHapticActuator`, `GamepadHapticActuatorType`*"]
#[deprecated]
pub fn type_(this: &GamepadHapticActuator) -> GamepadHapticActuatorType;
# [wasm_bindgen (structural , method , getter , js_class = "GamepadHapticActuator" , js_name = effects)]
#[doc = "Getter for the `effects` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator/effects)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadHapticActuator`*"]
pub fn effects(this: &GamepadHapticActuator) -> ::js_sys::Array;
#[cfg(feature = "GamepadHapticEffectType")]
# [wasm_bindgen (method , structural , js_class = "GamepadHapticActuator" , js_name = playEffect)]
#[doc = "The `playEffect()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator/playEffect)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadHapticActuator`, `GamepadHapticEffectType`*"]
pub fn play_effect(
this: &GamepadHapticActuator,
type_: GamepadHapticEffectType,
) -> ::js_sys::Promise;
#[cfg(all(
feature = "GamepadEffectParameters",
feature = "GamepadHapticEffectType",
))]
# [wasm_bindgen (method , structural , js_class = "GamepadHapticActuator" , js_name = playEffect)]
#[doc = "The `playEffect()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator/playEffect)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadEffectParameters`, `GamepadHapticActuator`, `GamepadHapticEffectType`*"]
pub fn play_effect_with_params(
this: &GamepadHapticActuator,
type_: GamepadHapticEffectType,
params: &GamepadEffectParameters,
) -> ::js_sys::Promise;
# [wasm_bindgen (catch , method , structural , js_class = "GamepadHapticActuator" , js_name = pulse)]
#[doc = "The `pulse()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator/pulse)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadHapticActuator`*"]
#[deprecated]
pub fn pulse(
this: &GamepadHapticActuator,
value: f64,
duration: f64,
) -> Result<::js_sys::Promise, JsValue>;
# [wasm_bindgen (method , structural , js_class = "GamepadHapticActuator" , js_name = reset)]
#[doc = "The `reset()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator/reset)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadHapticActuator`*"]
pub fn reset(this: &GamepadHapticActuator) -> ::js_sys::Promise;
}
12 changes: 12 additions & 0 deletions crates/web-sys/src/features/gen_GamepadHapticEffectType.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[doc = "The `GamepadHapticEffectType` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadHapticEffectType`*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GamepadHapticEffectType {
DualRumble = "dual-rumble",
TriggerRumble = "trigger-rumble",
}
12 changes: 12 additions & 0 deletions crates/web-sys/src/features/gen_GamepadHapticsResult.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[doc = "The `GamepadHapticsResult` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GamepadHapticsResult`*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GamepadHapticsResult {
Complete = "complete",
Preempted = "preempted",
}
21 changes: 21 additions & 0 deletions crates/web-sys/src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2959,6 +2959,13 @@ mod gen_GamepadButtonEventInit;
#[allow(unused_imports)]
pub use gen_GamepadButtonEventInit::*;

#[cfg(feature = "GamepadEffectParameters")]
#[allow(non_snake_case)]
mod gen_GamepadEffectParameters;
#[cfg(feature = "GamepadEffectParameters")]
#[allow(unused_imports)]
pub use gen_GamepadEffectParameters::*;

#[cfg(feature = "GamepadEvent")]
#[allow(non_snake_case)]
mod gen_GamepadEvent;
Expand Down Expand Up @@ -2994,6 +3001,20 @@ mod gen_GamepadHapticActuatorType;
#[allow(unused_imports)]
pub use gen_GamepadHapticActuatorType::*;

#[cfg(feature = "GamepadHapticEffectType")]
#[allow(non_snake_case)]
mod gen_GamepadHapticEffectType;
#[cfg(feature = "GamepadHapticEffectType")]
#[allow(unused_imports)]
pub use gen_GamepadHapticEffectType::*;

#[cfg(feature = "GamepadHapticsResult")]
#[allow(non_snake_case)]
mod gen_GamepadHapticsResult;
#[cfg(feature = "GamepadHapticsResult")]
#[allow(unused_imports)]
pub use gen_GamepadHapticsResult::*;

#[cfg(feature = "GamepadMappingType")]
#[allow(non_snake_case)]
mod gen_GamepadMappingType;
Expand Down
8 changes: 7 additions & 1 deletion crates/web-sys/webidls/enabled/Gamepad.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ interface Gamepad {
* The current haptic actuator of the device, an array of
* GamepadHapticActuator.
*/
[Constant, Cached, Frozen, Pref="dom.gamepad.extensions.enabled"]
[Constant, Cached, Frozen, RustDeprecated, Pref="dom.gamepad.extensions.enabled"]
readonly attribute sequence<GamepadHapticActuator> hapticActuators;

/**
* The vibration actuator of the device.
*/
[Constant, Cached, Frozen, Pref="dom.gamepad.extensions.enabled"]
readonly attribute GamepadHapticActuator vibrationActuator;
};
21 changes: 0 additions & 21 deletions crates/web-sys/webidls/enabled/GamepadHapticActuator.webidl

This file was deleted.

50 changes: 50 additions & 0 deletions crates/web-sys/webidls/unstable/GamepadHapticActuator.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* https://w3c.github.io/gamepad/
* (Deprecated) https://w3c.github.io/gamepad/extensions.html#gamepadhapticactuator-interface
*/

[RustDeprecated]
enum GamepadHapticActuatorType {
"vibration"
};
Comment on lines +11 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, this can't be made unstable without a breaking change anymore.


enum GamepadHapticEffectType {
"dual-rumble",
"trigger-rumble"
};

enum GamepadHapticsResult {
"complete",
"preempted"
};

dictionary GamepadEffectParameters {
unsigned long long duration = 0;
unsigned long long startDelay = 0;
double strongMagnitude = 0.0;
double weakMagnitude = 0.0;
double leftTrigger = 0.0;
double rightTrigger = 0.0;
};

[Pref="dom.gamepad.extensions.enabled",
HeaderFile="mozilla/dom/GamepadHapticActuator.h"]
interface GamepadHapticActuator
{
[RustDeprecated]
readonly attribute GamepadHapticActuatorType type;
[Throws, NewObject, RustDeprecated]
Promise<boolean> pulse(double value, double duration);
Comment on lines +37 to +42
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already stabilized APIs can't simply be made unstable, this would be a breaking change.


readonly attribute FrozenArray<GamepadHapticEffectType> effects;
Promise<GamepadHapticsResult> playEffect(
GamepadHapticEffectType type,
optional GamepadEffectParameters params = {}
);
Promise<GamepadHapticsResult> reset();
};
Loading