joy-joy

0.0.7 • Public • Published

Joy Joy

A Joy-Con game controller library for the browser. Built using the Gamepad API.

To see a demo of the library, visit https://taktran.github.io/joy-joy/.

Installation

npm install joy-joy

Usage

import {
  subscribeToGamepads,
  unsubscribeFromGamepads,
  startPolling
} from 'joy-joy';
 
subscribeToGamepads({
  onGamepadConnected: ({ key, gamepad }) => {
    // addGamepad(key, gamepad)
  },
  onGamepadDisconnected: ({ key, gamepad }) => {
    // removeGamepad(key, gamepad)
  }
});
 
const { stopPolling } = startPolling(data => {
  // Do something with data
});
 
// When done
stopPolling();
unsubscribeFromGamepads();

Data

onGamepadConnected/onGamepadDisconnected > gamepad (see Gamepad docs):

{
  connected: true,
  id: "Joy-Con (R) (Vendor: 057e Product: 2007)",
  index: 0,
  mapping: "",
  timestamp: 0,
  vibrationActuator: null,
  axes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1.2857143878936768],
  buttons: [
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton,
    GamepadButton
  ]
}

GamepadButton (see GamepadButton docs):

{
  pressed: false,
  touched: false,
  value: 0
}

startPolling > data:

{
  0: {
    connected: true,
    id: "Joy-Con (R) (Vendor: 057e Product: 2007)",
    index: 0,
    mapping: "",
    timestamp: 0,
    vibrationActuator: null,
    axes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1.2857143878936768],
    buttons: [
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton,
      GamepadButton
    ]
  },
  ...
}

Development

  • Install nvm

  • Use correct node version

      nvm use
    
  • Install dependencies

      npm install
    
  • Go to demo folder and run

Package Sidebar

Install

npm i joy-joy

Weekly Downloads

1

Version

0.0.7

License

MIT

Unpacked Size

6.35 kB

Total Files

5

Last publish

Collaborators

  • ttt