Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ShakeDetector

Hierarchy

  • ShakeDetector

Implements

Index

Constructors

constructor

Properties

Private Readonly debounceDelay

debounceDelay: number

Private isRunning

isRunning: boolean = false

Private lastAcceleration

lastAcceleration: StoredAcceleration

Private lastTime

lastTime: number

Private listeners

listeners: ShakeHandlersList = []

Private Readonly motionMonitor

motionMonitor: MotionMonitor

Private Readonly threshold

threshold: number

Static SHAKE_EVENT

SHAKE_EVENT: string = "shake-detected"

Methods

confirmPermissionGranted

  • confirmPermissionGranted(): this
  • Notifies the detector that permission to listen to the motion events has already been granted.

    Returns this

Private onDeviceMotion

  • onDeviceMotion(e: DeviceMotionEvent): void
  • Listens to the motion events and tries to detect the shake event.

    Parameters

    • e: DeviceMotionEvent

    Returns void

Private onShake

  • onShake(): void
  • Notifies all the shake event listeners that the shake event happened

    Returns void

requestPermission

  • requestPermission(triggerElement?: HTMLElement): Promise<boolean>
  • IOS (since 12.2) requires a user's permission to listen to the motion events. Such permission could be obtained only in response to user interaction.

    This method sets a click listener on the provided element (on html if not provided) and returns a promise. Once the element clicked, it asks for permission. The promise will be resolved with a boolean reflecting the user's decision.

    If no such permission needed, the method returns resolved promise.

    Parameters

    • Default value triggerElement: HTMLElement = document.documentElement

    Returns Promise<boolean>

Private reset

  • reset(): void
  • Resets previously collected data

    Returns void

start

  • start(): this
  • Starts monitoring the motion event

    Returns this

stop

  • stop(): this
  • Stops monitoring the motion event

    Returns this

subscribe

  • Adds a handler to the shake event handlers pool

    Parameters

    Returns this

unsubscribe

  • Removes a handler from the shake event handlers pool

    Parameters

    Returns this

Object literals

Static Private defaultOptions

defaultOptions: object

debounceDelay

debounceDelay: number = 1000

threshold

threshold: number = 15

Generated using TypeDoc