Composer
Composer is an Angular library that simplifies interacting with Engine. It abstracts the complexity of the WebSocket API and manages the following:
Directives for binding to Status variables
Calling functions in the Driver
Resource access (database manipulation)
Authentication with Engine
Driver debug binding directives
The magic of Angular is that it allows you to build a dynamic web page in a declarative manner.
NOTE:: for universal support between mouse and touch devices we use the Hammer library which has action recognizers, such as pressing, swiping, pinching, etc.
Status Variable Bindings
Imagine the driver below running on Engine.
It is a type of Display
It has a status variable called input
Input can be changed on the device by calling
Display.switch_to(input_name)
You can request the status values available in drivers so you can present these graphically to a user. This is performed using the binding
directive and the data requested is updated in real time as the status changes.
Our aim with the client library was to make the interface code as self describing as possible, no abstract channel codes or feedback numbers. Let’s break this line down a little more.
binding
: this tells Angular that we want to use the binding directive[sys]
: this is the system ID we want to connect to. The[]
indicate that this is an input variablemod
: this is a raw string indicating the driver we would like to reference.by default the driver index is 1 so in the example we are referencing
Display_1
this could be more explicit:
mod="Display_1"
or even more explicit
mod="Display" [index]="model.selected_index"
[(value)]
: this is the variable that will hold the status value requestedThe binding is two way
[()]
so we can send any changes to the server / deviceIf the value is changed, by a user interacting with the interface, the function defined by
exec
will be called on the device module.This is the primary method for updating state on the server / device
exec
this is the function to run on the device module if the status value changesThe function is called with the parameters defined by
[params]
There are times where execute can be simplified.
When the status variable and function used to update that status variable have the same name, the exec process can be simplified. This is an example of controlling volume and power for the same device.
You can see that exec is present with no value configured. The result of this code is a power toggle button for the device and when the device is on there is a volume slider available.
Calling Functions in the Driver
You can call functions without binding to values first.
You can also execute functions from type script
Resource Access
Engine exposes a rich set of APIs that can be easily accessed via composer resources on the SystemsService
You can get
the following resource factories:
Dependency: available drivers
Trigger: trigger CRUD
System: control system CRUD
Module: module CRUD
Zone: zone CRUD
User: Current user details
Log: Access logs
Authentication
Authentication with Engine is handled automatically by composer.
Composer will request
/auth/authority
which contains information about how to authenticateIf composer doesn’t have a valid OAuth2 token it will redirect to the defined login page
A light weight page
oauth-resp.html
is used to extract the token and save it in local storageA client side redirect back to the initial route
For this to occur composer must be configured as part of the applications load sequence.
See the example of this in Composer Starter
The composer starter example
ensures the request to
/auth/authority
succeedsconfigures connection and OAuth2 details
configures mode: production, development and if a mock / virtual control system should be used
calls
this.systems.setup(config);
which kicks off the authentication process as required
Driver Debug Bindings
It is possible to request debug logging to be redirected to your browser. This provides a real time window into the inner workings of the driver as it is executing.
Useful for technical or administration pages.
Last updated