0.0.7 • Published 5 years ago

joy-joy v0.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.1

5 years ago