Reference Source
public class | source

MobileHandlerSingleton

You can directly use an instance of this class. MobileHandler

Static Member Summary

Static Private Members
private static

The maximum layer

private static

The max number of controllers that can be recycled

private static

Whether or not an instance can be touched by multiple fingers.

private static

Whether or not an instance can be touched or not.

Constructor Summary

Private Constructor
private

Member Summary

Public Members
public

version: *

The version of the module.

Private Members
private

An array of all controllers that are active

private

Weakmap to track data belonging to instances used in this module.

private

The mobile handler interface that our controllers will exist in

private

Check if the user agent string contains 'Android'

private

Check if the user agent string contains 'iPhone' or 'iPad'

private

Whether this device is mobile or not.

private

Check if the 'ontouchstart' event is supported

private

The logger module this module uses to log errors / logs

private

An object that stores the mapPosition over the screen

private

An array of all controllers that have been recycled

private

An array that holds the current screen zones taken, 'left' or 'right'.

private

An object containing the safe area offset values to account for the notch on notch enabled devices.

private

An array that holds all the diobs that are currently being touched

private

An object holding the current window size

private

The middle of the screen's x coordinate. This is used to figure out which side of the screen is being interacted with.

private

An object holding the controllers in zones

Method Summary

Public Methods
public

Creates a controller component with the passed options.

public

Detects the type of device based on user agent.

public

Gets the device's current RAM. Only works in a cordova environment.

public

Short hand for getting the safe area inset for the bottom of the screen.

public

Short hand for getting the safe area inset for the left of the screen.

public

Short hand for getting the safe area inset for the right of the screen.

public

Short hand for getting the safe area inset for the top of the screen.

public

If this device is an android device.

public

If this device is an ios device.

public

If this device is a mobile device.

public

If this device can register touch events.

public
public

vibrate(pDuration: number)

Vibrates the mobile device.

Private Methods
private

Gets the instance that the user tapped if there was one.

private

An object containing the safe area offset values to account for the notch on notch enabled devices.

private

getTrackerObject(pTouchedInstance: Object): Object | void

Returns the tracker object associated with pTouchedInstance if it exists.

private

handleCancel(pEvent: Object)

The event function called when a touch is canceled.

private

handleEnd(pEvent: Object)

The event function called when a touch ends.

private

handleMove(pEvent: Object)

The event function called when a touch is moved.

private

handleStart(pEvent: Object)

The event function called when a touch starts.

private

handleZoneMove(pX: number, pY: number, pFingerID: string)

When a finger on the screen moves, check if the fingerID belongs to a zoned controller, if it does update that zoned controller

private

When a finger on the screen is removed it checks to see if it belongs to a zoned controller.

private

handleZoneTouch(pX: number, pY: number, pFingerID: string)

Handles when a finger is placed onto the screen in a zone

private

isTracking(pTouchedInstance: Object): boolean

Checks if the instance that was touched is being tracked internally.

private

Queries the safe area inset values set by the device and stores them.

private

Sets the needed event handlers for this module.

private

track(pTouchedInstance: Object)

Starts internally tracking this instance.

private

windowResizeHandler(pWidth: number, pHeight: number)

Handler event for when the window resizes.

Static Private Members

private static MAX_LAYER: number source

The maximum layer

private static MAX_RECYCLED_CONTROLLERS: number source

The max number of controllers that can be recycled

private static MULTI_TOUCH: number source

Whether or not an instance can be touched by multiple fingers. If their touchOpacity is set to MULTI_TOUCH it can be interacted with multiple times via different touches.

private static NO_TOUCH: number source

Whether or not an instance can be touched or not. If their touchOpacity is set to NO_TOUCH, it cannot be touched

Private Constructors

private constructor() source

Public Members

public version: * source

The version of the module.

Private Members

private activeControllers: Array source

An array of all controllers that are active

private instanceWeakMap: WeakMap source

Weakmap to track data belonging to instances used in this module.

private interfaceHandle: string source

The mobile handler interface that our controllers will exist in

private isAndroid: boolean source

Check if the user agent string contains 'Android'

private isIOS: boolean source

Check if the user agent string contains 'iPhone' or 'iPad'

private isMobile: boolean source

Whether this device is mobile or not. Can be simulated.

private isTouchEnabled: boolean source

Check if the 'ontouchstart' event is supported

private logger: Object source

The logger module this module uses to log errors / logs

private mapPositionObject: Object source

An object that stores the mapPosition over the screen

private recycledControllers: Array source

An array of all controllers that have been recycled

private reservedScreenZones: Array source

An array that holds the current screen zones taken, 'left' or 'right'.

private safeAreaValues: Object source

An object containing the safe area offset values to account for the notch on notch enabled devices. This will keep the UI in a safe area The safe-area-inset-* variables are four environment variables that define a rectangle by its top, right, bottom, and left insets from the edge of the viewport, which is safe to put content into without risking it being cut off by the shape of a non‑rectangular display. For rectangular viewports, like your average laptop monitor, their value is equal to zero. For non-rectangular displays — like a round watch face — the four values set by the user agent form a rectangle such that all content inside the rectangle is visible. https://developer.mozilla.org/en-US/docs/Web/CSS/env

Properties:

NameTypeAttributeDescription
top boolean

safeAreaInsetTop.

right boolean

safeAreaInsetRight.

bottom boolean

safeAreaInsetBottom.

left boolean

safeAreaInsetLeft.

private touchedInstances: Array source

An array that holds all the diobs that are currently being touched

private windowSize: Object source

An object holding the current window size

private xCenterScreenPosition: number source

The middle of the screen's x coordinate. This is used to figure out which side of the screen is being interacted with.

private zonedControllers: Object source

An object holding the controllers in zones

Public Methods

public createController(pOptions: Object): Controller source

Creates a controller component with the passed options.

Params:

NameTypeAttributeDescription
pOptions Object

The options of this controller.

pOptions.type string

The way this controller will behave. stationary | traversal | static.

pOptions.size number

The width/height of the joystick. The width & height of the joystick should be the same. The inner ring will be 50% of this size.

pOptions.position Object

The initial position of the joystick.

pOptions.position.x string

The initial x position of the joystick.

pOptions.position.y string

The initial y position of the joystick.

pOptions.lockedDimension string

The locked dimension of the joystick. both | vertical | horizontal. This is used to lock the joystick from moving in certain dimensions. If this joystick's type is traversal it cannot be locked.

pOptions.zone string

The zone the joystick will occupy. If there is already a controller of the traversal or static type, then you must use a zone. If there is only one controller no zone is needed. left | right This will give each controller equal space on the left | right sides of the screen.

pOptions.inactiveAlpha number

The alpha value the joystick will be when it is considered to be inactive.

pOptions.transitionTime number

How long it takes in ms to transition to the inactiveAlpha value.

pOptions.scale number

The scale you want the joystick controller to be.

pOptions.plane number

The plane of the joystick controller.

pOptions.layer number

The layer of the joystick controller.

pOptions.atlasName string

The atlasName of the joystick.

pOptions.joystickIconName string

The iconName of the joystick.

pOptions.joyringIconName string

The iconName of the joyring.

pOptions.callback Object

An object holding options callbacks to attach to events the joystick emits.

pOptions.callback.onTouchBegin Function

Callback to be called when the joystick is touched after being released.

pOptions.callback.onRelease Function

Callback to be called when the joystick is released and no longer held.

pOptions.callback.onMove Function

Callback to be called when the joystick is moved.

Return:

Controller

A new controller component

public detectDeviceType(): string source

Detects the type of device based on user agent.

Return:

string

The detected device type ('desktop' or 'mobile').

public getDeviceRAM(): number source

Gets the device's current RAM. Only works in a cordova environment.

Return:

number

The device's current RAM

public getSafeAreaBottom(): number source

Short hand for getting the safe area inset for the bottom of the screen.

Return:

number

public getSafeAreaLeft(): number source

Short hand for getting the safe area inset for the left of the screen.

Return:

number

public getSafeAreaRight(): number source

Short hand for getting the safe area inset for the right of the screen.

Return:

number

public getSafeAreaTop(): number source

Short hand for getting the safe area inset for the top of the screen.

Return:

number

public isAndroidDevice(): boolean source

If this device is an android device.

Return:

boolean

Whether this device is an android device.

public isIOSDevice(): boolean source

If this device is an ios device.

Return:

boolean

Whether this device is an ios device.

public isMobileDevice(): boolean source

If this device is a mobile device.

Return:

boolean

Whether this device is a mobile device.

public isTouchDevice(): boolean source

If this device can register touch events.

Return:

boolean

Whether this device is a touch enabled device.

public queryUserAgent() source

public vibrate(pDuration: number) source

Vibrates the mobile device. https://github.com/apache/cordova-plugin-vibration#readme https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API

Params:

NameTypeAttributeDescription
pDuration number

The duration of the vibration.

Private Methods

private getDiobUnderFinger(pX: number, pY: number): Object source

Gets the instance that the user tapped if there was one.

Params:

NameTypeAttributeDescription
pX number

The x position on the screen where the user tapped.

pY number

The y position on the screen where the user tapped.

Return:

Object

The instance that was tapped or null if nothing was touched.

private getSafeAreaInsets(): Object source

An object containing the safe area offset values to account for the notch on notch enabled devices. This will keep the UI in a safe area The safe-area-inset-* variables are four environment variables that define a rectangle by its top, right, bottom, and left insets from the edge of the viewport, which is safe to put content into without risking it being cut off by the shape of a non‑rectangular display. For rectangular viewports, like your average laptop monitor, their value is equal to zero. For non-rectangular displays — like a round watch face — the four values set by the user agent form a rectangle such that all content inside the rectangle is visible. https://developer.mozilla.org/en-US/docs/Web/CSS/env

Return:

Object

The safe area inset values

Return Properties:

NameTypeAttributeDescription
top boolean

safeAreaInsetTop.

right boolean

safeAreaInsetRight.

bottom boolean

safeAreaInsetBottom.

left boolean

safeAreaInsetLeft.

private getTrackerObject(pTouchedInstance: Object): Object | void source

Returns the tracker object associated with pTouchedInstance if it exists.

Params:

NameTypeAttributeDescription
pTouchedInstance Object

The instance that needs to be tracked.

Return:

Object | void

The tracker object associated with pTouchedInstance if it exists. void if not.

private handleCancel(pEvent: Object) source

The event function called when a touch is canceled.

Params:

NameTypeAttributeDescription
pEvent Object

Represents an event which takes place in the DOM.

private handleEnd(pEvent: Object) source

The event function called when a touch ends.

Params:

NameTypeAttributeDescription
pEvent Object

Represents an event which takes place in the DOM.

private handleMove(pEvent: Object) source

The event function called when a touch is moved.

Params:

NameTypeAttributeDescription
pEvent Object

Represents an event which takes place in the DOM.

private handleStart(pEvent: Object) source

The event function called when a touch starts.

Params:

NameTypeAttributeDescription
pEvent Object

Represents an event which takes place in the DOM.

private handleZoneMove(pX: number, pY: number, pFingerID: string) source

When a finger on the screen moves, check if the fingerID belongs to a zoned controller, if it does update that zoned controller

Params:

NameTypeAttributeDescription
pX number

The x position on the screen where the user tapped.

pY number

The y position on the screen where the user tapped.

pFingerID string

The ID of the finger

private handleZoneRelease(pFingerID: string) source

When a finger on the screen is removed it checks to see if it belongs to a zoned controller. If so it releases that controller.

Params:

NameTypeAttributeDescription
pFingerID string

The ID of the finger.

private handleZoneTouch(pX: number, pY: number, pFingerID: string) source

Handles when a finger is placed onto the screen in a zone

Params:

NameTypeAttributeDescription
pX number

The x position on the screen where the user tapped.

pY number

The y position on the screen where the user tapped.

pFingerID string

The ID of the finger

private isTracking(pTouchedInstance: Object): boolean source

Checks if the instance that was touched is being tracked internally.

Params:

NameTypeAttributeDescription
pTouchedInstance Object

The instance that needs to be tracked.

Return:

boolean

Whether pTouchedInstance is being tracked.

private querySafeAreaValues() source

Queries the safe area inset values set by the device and stores them.

private registerEventHandlers() source

Sets the needed event handlers for this module.

private track(pTouchedInstance: Object) source

Starts internally tracking this instance.

Params:

NameTypeAttributeDescription
pTouchedInstance Object

The instance that needs to be tracked.

private windowResizeHandler(pWidth: number, pHeight: number) source

Handler event for when the window resizes.

Params:

NameTypeAttributeDescription
pWidth number

The window's new width.

pHeight number

The window's new height.