Home Manual Reference Source
import Stopwatch from 'itslanguage/audio/tools.js'
public class | source

Stopwatch

this class is experimental. When binding to an Audio Recorder, the stopwatch is not always synced properly. A difference of 0.1s or 0.2s too high may occur when counting. When binding to an Audio Player however, the timer will sync properly and show the correct duration of the loaded audio file.

A simple stopwatch that ticks every 100 ms. It can be bound to an AudioPlayer or AudioRecorder which binds the stop and playing functionality to the stopping and starting of the Watch. It can also be listened to by other entities.

Constructor Summary

Public Constructor
public

Member Summary

Private Members
private
private
private

_tickCb: *

private

Method Summary

Public Methods
public

registerListener(tickCb: *)

public

reset()

Reset count to 0.

public

start()

Start counting and tick every 100 ms.

public

stop()

Stop counting.

public

stopListening(tickCb: *)

public

tick()

Invoke the tick callback with the current value.

public

update()

Tick once and increment the value by 1.

Public Constructors

public constructor(tickCb: Function) source

Params:

NameTypeAttributeDescription
tickCb Function

The callback that is invoked on every tick (every 100ms).

Throw:

Error

If tickCb is missing.

Private Members

private _emitter: * source

private _interval: * source

private _tickCb: * source

private _value: number source

Public Methods

public registerListener(tickCb: *) source

Params:

NameTypeAttributeDescription
tickCb *

public reset() source

Reset count to 0.

public start() source

Start counting and tick every 100 ms.

public stop() source

Stop counting.

public stopListening(tickCb: *) source

Params:

NameTypeAttributeDescription
tickCb *

public tick() source

Invoke the tick callback with the current value.

public update() source

Tick once and increment the value by 1.