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';PC browser
Create a Peer
const peer = new SmartController('id');
// parameters are optional:
// ID: if id isn't provided a random one will be createdCreate a QRcode
Make a qr code for easy phone connection
peer.createQrCode(url, div element id, width = 256, height = 256, playerID = null);
//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 displayedEvents
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 calledTypes 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 (not yet implemented)
peer.getStats(type, DomElement)
//Specify type of stats you wish to display (latency, update frequency...) and an html element to display themFields
peer.remotePeers
// list of currecntly connected users
peer.peerConnection
//peer objectRemoteTouchPad
Adds fields, methods and callback options specific to touchscreen input
Extends SmartPeer
Create a Peer
const touchpad_peer = new TouchPadSmartPeer('id'); Fields
touchpad_peer.touchpadList
//list of Touchpad objects, 1 object per playerMethods (not yet implemented)
touchpad_peer.recognizeGesture();
// recognizeGesture will take the current finger_postion and tries to match it to one of the available gesturesTouchapad class
Each player has their own touchpad object
Fields
touchpad.connecion // peer id
touchpad.isActive // true if the user is currently intercating with the phone screen
touchpad.state //coordinates for each finger, cant tell finger appart coordinates are recorded in order of tapping the screen
touchpad.figer_number //number of fingers touching the screenRemoteJoystick
Adds fields, methods and callback options specific to joystick input
Extends SmartPeer
Create a Peer
const joystick_peer = new JoystickSmartPeer('id'); Fields
joystick_peer.joystickList
//list of Touchpad objects, 1 object per playerJoystick class
Each player has their own joystick object
Fields
touchpad.connecion // peer id
touchpad.isActive // true if the user is currently interacting with the phone screen
touchpad.state //all information sent from joystick [angle, direction, distance, position coordinates]
touchpad.lastPosition = {x:0, y:0} //last position on pc screen Mobile browser
Create a Peer
const peer = new SmartPhoneController();
//will automatically create a connection with the PC peer id in urlSend a message to a peer
peer.connection.send(data);
//send any user input data in the following format {type: 'user', data: data} to be recognized by the PC browser