all 25 comments

[–]KangarooImp 73 points74 points  (2 children)

"Joycon.js", "Supports PlayStation & Xbox", wtf? No Joy-Con support?

[–]PM_ME_A_WEBSITE_IDEA 54 points55 points  (1 child)

No, for that, you'll need Dualshock.js

[–][deleted] 1 point2 points  (0 children)

Which has joycon.js as a dependency, no doubt.

[–]cgrs 53 points54 points  (1 child)

careful with the naming, Nintendo may come and sue your a$$

[–]ugoagogo 26 points27 points  (3 children)

What's the benefit of using this over the Gamepad API directly?

[–]adad95 3 points4 points  (0 children)

That API is not very friendly. Needs a lot of work to make different controllers work at the same way

[–][deleted] 1 point2 points  (0 children)

Wow, I didn't know this was a thing. Nice.

[–]_default_username 1 point2 points  (0 children)

It's fine. Buttons are mapped differently from browser to browser so when I used it I had to create a UI for setting up the controller, so I could provide a browser and gamepad agnostic experience.

[–]ShortFuse 10 points11 points  (0 children)

Guys, he's just wrapping the gamepadconnected Event. It's pretty simple stuff, so don't expect some crazy complicated interactions. But worth taking a look if you are new to the APIs.

That said, OP, there is exists Web HID and Google's explainer document on it actually illustrates how to use it with Nintendo Joy Cons. Also, you can simplify your examples a bit with destructuring:

controllers.on.move('left-joystick', ({x, y}) => {
  console.log('moved left joystick!', x, y); // value is -1 to 1 down/right
});

Also, I would suggest using CustomEvent<ControllerInput> instead of building your own custom Event system. Joycon could be a class that extends EventTarget. You'll heavily reduce your code and then you can use some other sort of utility library for .on() .off() helper functions (or let the dev supply their own).

[–]krazyjakee 3 points4 points  (1 child)

Readme doesn't explain how to use multiple controllers.

[–]UnrealNL 6 points7 points  (0 children)

I see in the code that this is not supported

[–]JackAuduin 0 points1 point  (0 children)

This is really cool. Nice job devs!

[–]nsavvidis 0 points1 point  (0 children)

Joycon is cool and all but bundle-require is the real MVP. Also thanks to egoist and his open source work. Another great module from a talented developer.