Getting Started Javascript SDK

The Chirp Connect Javascript SDK allows you to send payloads to a receiving device.

(Please notice that the Javascript SDK is send only)

Running the SDK in the browser

Include the chirp-v3.min.js file in your HMTL and add your website URL (i.e. http://localhost:8080, http://my-website.com) to origins in the Admin Centre.

<script src="../build/chirp-v3.min.js"></script>

A Web Audio Context is needed to instantiate a new ChirpConnect instance, as well as your application key.

Remember to add your website URL (i.e. http://localhost:8080, http://my-website.com) to origins in admin.chirp.io
<script>
window.onload = function() {

  var audioContext = null;

  /**
   * Instantiates an audio context on which the Chirp will be played.
   */
  try {
    // Fix up for browser prefixing
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    audioContext = new AudioContext();
  } catch (e) {
    console.log(e);
  }

  var Chirp = new ChirpConnect('APPLICATION_KEY', audioContext);

  // rest of your code goes here...
}
</script>

Chirp can use its function .send() to chirp a payload, as a second argument a call back function has to be provided in order to verify errors or success.

// example payload:
Chirp.send(new Uint8Array([172, 47, 117, 192]), err => {
  if (err) {
    console.error(err);
  } else {
    console.log('this will be logged after the payload has been sent');
  }
});