Javascript API

Interact with and control the Intrasonics JS Decoder programmatically

The script intrasonics.js is used to instantiate a global intrasonics object.

Methods, Events and Properties of this object form the primary interface to interact with and control the Intrasonics JS Decoder. 


An event listener can be used to capture the events raised by JS Decoder as it runs.

A typical event listener is written to register a callback function that receives a payload object.

For example:

window.onload = function() {
    intrasonics.on("action", function(action){
        // show the received codeword

The complete list of events and a description of their payloads:

Event Payload Description
  status: String
Emitted when the JS Decoder starts/stops.
The status property will contain one of the following representing the new state of operation:
  id: String,
  engine: String
  timestamp: Integer
Emitted when the JS Decoder detects an audio trigger activated by the currently loaded token.
The id property is the unique audio trigger detected. Use this value to decide how your content should update.
The engine property describes the mode of decoding used to detect the audio trigger.
The timestamp property is the number of milliseconds since 00:00 on 1st January 1970 the audio-trigger was detected. Based on local system clock.
  schemeName: String,
  signalStrength: Float,
  volume: Float,
  confidence: String
Emitted regularly while the JS Decoder is active.
The schemeName property can be used to distinguish performance data for diffent encoding schemes (separate performance events are raised for each of the schemes the token enables).
The signalStrength property indicates the likelihood of the currently sampled audio containing a codeword.
The volume property is a value representing the strength of the audio stream available to the JS Decoder.
The confidence property contains a string constant to representing a level of likelihood of a codeword being detected. One of the following values will be used:
  audio: Boolean
Emitted when the user either grants or denies JS Decoder access to the microphone.
The audio property will be true if access was granted, and false if denied.
  message: String
Emitted whenever the JS Decoder encounters a problem.
The message property contains the details of the error.

Public Methods

The complete list of available public methods:

Method Description
init(void) : void Initialises the JS Decoder (called internally for default driver)
isRunning(void) : Boolean Returns information about whether the JS Decoder is currently active and listening for codewords.
loadToken(path: String) : Promise Loads a decoding token into JS Decoder using a path relative to the current script. If path is a secure web URL (e.g., the token will be loaded from a remote location.
    eventName: String,
    handler: Function
) : void
This method allows event listeners to be registered with the JS Decoder. See the 'Events' section above for more information.
setToken(token: String) : void Loads a decoding token into JS Decoder from a string (e.g. the contents of a token file).
start(void) : void Calling this method will attempt to start the JS Decoder.
stop(void) : void Calling this method will stop the JS Decoder.