The Conductor JavaScript API is published at
http://conductor.link-labs.com/conductor-api.min.js
The Conductor JavaScript API allows web-based clients to access device and message data from Conductor. This API abstraction includes elements from the access, clientEdge and networkAsset system calls. It provides a single interface to build an integrated user experience. For example, the Conductor JavaScript API is used by the Conductor web interface.
The basic workflow with the Conductor JavaScript wrapper is:
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 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';
});
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 );
Constructor for the Conductor API.
options - an object with the following keys:
This API call logs into Conductor and creates a session, returning a Promise. The returned Promise-value includes account information about the now authenticated user.
Ends the current Conductor session, returning a Promise that resolves upon completion.
Fetches the current session, if still valid. If the returned Promise object is resolved as a rejection, then the client should create a new session using the login call.
This call loads messages for the given node type from Conductor as a single connection (without streaming or polling). No messages older than 5 days will be returned. Returns a Promise that resolves to the requested data.
Creates a streaming connection to Conductor and populates messages from the nodeType/nodeId combination as they arrive. The first time a stream is attached, the JavaScript API will populate up to options.maxResults history messages from the previous 5 days of traffic. Returns a Promise that resolves to the Conductor.Subscription object that implements the streaming connection.
Closes a stream created by the attachMessages operation. The nodeType and streamOptions.<gatewayId, networkToken, applicationToken, or module> parameters must match the corresponding attachMessages call. There is no return value.
Sends a hex payload to the given destination. If a gateway is provided, then the message will use Conductor’s commandRoutes mode for transmission. Otherwise, commandTargets mode is used. All messages sent with this API wrapper have a ttl of 60 seconds. The return value is a Promise that resolves to Conductor’s envelope information about the command.
Loads all gateways in the current session’s account, returning a Promise that resolves into the known Gateway objects.
Updates the name of a given gateway, returning a Promise that resolves upon completion.
Updates the network token registration for the given gateway, returning a Promise that resolves upon completion.
Loads all network tokens in the current session’s account, returning a Promise that resolves into the known Network objects. Universal (Open) network(s) are also discovered as a side effect.
Updates the friendly name of a given network token, returning a Promise that resolves upon completion.
Loads all application ids in the current session’s account, returning a Promise that resolves into the know Application objects.
Updates the friendly name of a given application, returning a Promise that resolves upon completion.
Creates a new application id and associates it with the current account. Returns a Promise that resolves upon completion of the creation process.
Accesses Conductor to find all modules registered to this account, updating the various data structures returned from loadApplications(), loadGateways(), and loadNetworks(). Returns a Promise that resolves upon the first completion of the Conductor call. If refresh is enabled (with a value greater than 0 ms), then subsequent calls will not have an effect on the Promise.
Loads all users in the current session’s account, returning a Promise that resolves into the known User objects.
Updates the personal information for the given user. Returns a Promise that resolves upon successful update of the user.
Updates the user’s password. Unlike most other calls in this API wrapper, updatePassword() does not use the current session. This call returns a Promise that resolves upon successful completion of the change operation, logout, login, and getSession. The Promise may reject upon a failure at any of those steps, so refer to the Promise’s value for a description of how it failed.
Creates a new user. If there is an authenticated session, then the new user will be provisioned as a member of the current account. Otherwise, the user will be anonymously provisioned. Returns a Promise that resolves with the new user’s information upon completion of the provisioning process.