Getting Started

The basic workflow with the Conductor JavaScript wrapper is:

  1. Load the API directly from conductor.link-labs.com
  2. Create a session
  3. Access data for streams as needed

Load the API

Load the Conductor JavaScript API from http://conductor.link-labs.com/conductor-api.min.js along with other utility libraries such as jquery and knockout.js. The jquery library is required and it provides AJAX and Promise implementations. Knockout is optional.

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
<script src="//conductor.link-labs.com/conductor-api.min.js"></script>

Create a session

Create a Conductor object and initialize a session:

  var conductor = new Conductor();
  conductor.getSession().then( function onValidSession() {
    // An authenticated Conductor account is available, proceed normally
  }, function onInvalidSession() {
    // In this case, the user does not have access to Conductor, so a
    // login operation is necessary.  The best practice is to redirect
    // to a login page, and then return here once conductor.login() 
    // succeeds.  This way, you avoid operating with the conductor object
    // unless the session-based cookies are working correctly. 
    window.location = 'login.html';
  });

Access data

For a streaming client, the easiest way to access message traffic is to use an observable array data structure such as the one in knockout.js. For example:

  var dataType = 'gateway';  // could also be 'application', 'network', or 'node'
  var dataHolder = {
    gatewayId: '$101-0-0-0-xxxxxxxxx',   // for nodeType=='gateway'
    messages: new ko.ObservableArray()
  }
  conductor.attachMessages( dataType, dataHolder );
  // Use dataHolder.messages as appropriate.
  // sometime later…
  conductor.detachMessages( dataType, dataHolder );

0 Comments

Add your comment

E-Mail me when someone replies to this comment