JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q70526F
  • License ISC

SmartController provides an easy way of turning a smartphone into versatile controller.

Package Exports

  • smartcontroller

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (smartcontroller) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SmartController: Peer-to-peer for creating smartphone controllers

SmartController provides an easy way of turning a smartphone into versatile controller.

Getting started

Include the library

install NPM package: npm install smartcontroller

// The usage -
import SmartController from 'smartcontroller';

Create a Peer

const peer = new SmartController('id', 'frequency'); 
// all parameters are optional:
// ID: if id isn't provided a random one will be created
// Frequency: how often should the the updates occur 

Create a QRcode
Make a qr code for easy phone connection

peer.createQrCode(type, url, canvas);
//select from premade controllers by specifying a type (joystick, touchscreen, nes controller) or provide a url for your own controller
//canvas element for the qr code to be displayed

Events

Register a new event

peer.on(flag, function);
//Flag: specify when the function should be called (connection, data, close)
//Function: pass a function to be called

Types of callbacks
connection : will pass a number of player who just connected to your function
data : will pass a player number and the input from the phone
close : will pass a number of player who just disconnected

Connection

Display stats

peer.getStats(type, DomElement)
//Specify type of stats you wish to display (latency, update frequency...) and an html element to display them

Access last state of a player

peer.state.playerNumber
//will return last known state of a given player

Check active players

peer.state.players
//will return a dictoniary of currently connected players

RemoteTouchPad

Adds fields, methods and callback options specific to touchscreen input
Extends SmartPeer

Create a Peer

const touchpad_peer = new TouchPadSmartPeer('id', 'frequency'); 

Fields

touchpad_peer.finger_number = 1-5;
touchpad_peer.finger_position = { 1:{x, y}, 2:{x,y}, ... , 5:{x,y}};

// current number of fingers on touchscreen
// dictionary of coordinates for each finger

Methods

touchpad_peer.recognizeGesture();
touchpad_peer.createQRCode(default url, canvas);

// recognizeGesture will take the current finger_postion and tries to match it to one of the available gestures
// createQRCode defaults to url with premade touch pad

Callbacks

touchpad_peer.on(finger_number, func(){});
touchpad_peer.on("touch_start / touch_move / touch_end", func(){});

//finger_number can be set to 1-5 to call a specific function when there is input from 1-5 fingers
//start/move/end commands on touchpad

RemoteJoystick

Adds fields, methods and callback options specific to joystick input
Extends SmartPeer

Create a Peer

const joystick_peer = new JoystickSmartPeer('id', 'frequency'); 

Fields

joystick_peer.vector = [x,y]; 
joystick_peer.state = { position :{x, y}, angle:{degrees, radians}, direction :{x, y, angle}, force, distance};

//current vector calulated from the centre of the joystick and its current position
//provides description of the last knows state of the joystick

Methods

joystick_peer.createQRCode(default url);
//createQRCode defaults to url with premade joystick

Callbacks

joystick_peer.on("touch_start / touch_move / touch_end", func(){});
//start/move/end commands on joystick