Skip to main content
Documentation - Limelight XE™ - Tutorial
Tutorial
Getting Started with Limelight XE Scripting

Overview

One of the most powerful features of Limelight XE is the built-in scripting functionality.  It is based on the Microsoft ChakraCore ECMA 6 compliant JavaScript engine.  By writing scripts that run inside of the Limelight XE engine, developers can access any object and property providing the ability to expand the functionality of the system. 

Prerequisites

Lesson 1

Once Limelight XE is installed, registered and a license key activated you can begin programming your first script.  Log into the Limelight XE server using the Limelight XE Console and navigate to the components tab - the scripting engine manager can be found in the tree view on the left under System Management.

Right click on the Script Manager and in the pop-up menu select New (or alternatively press Ctrl-N).  This will create a new script entry in the server.  Now click on the newly created entry - it will begin with script_ followed by a number and the .js extension (you can rename the script to anything you like with normal naming conventions).  Select the Properties tab in the window to the right of the component tree view and you should see all the script properties.

To begin creating a new script, you'll need to invoke the editor by either clicking the Edit button at the bottom of the window or double clicking on the script name under the Script Manager.  When the editor appears it will already have a default application that can be run - basically a shell.

Click the Run button (blue right arrow) on the tool bar of the editor window and the script will execute... you should see these results in the Console Log:

In the following lesson we will add a line of code to write to the console.  This will include coding, updating the script source, attempting to run the program (with an error), finding the error, correcting it and running it again.

 

Exercise 1

In this exercise we will modify the shell code from above...

1. copy the code below and paste into the editor as described above then click the Update button to save the changes.

// Default Limelight Javascript Shell
(()=>{  // main script begins...

 // user code goes here...
 // example:
 var x = 41;
 x = PlusOne(x);
 // send to console log with color attributes
 // for more on text attributes see ECMA-48 SGR escape codes
 console.log('The result is: \x1b[96m' + x)
 // this introduces an error line
 console.log('Using Limelight XE scripting is easy!);
}
// end of main script
)(); // end of main script...

// functions can go here or before the main script begins

// example function
function PlusOne(value){
 var i = value;
 i++;
 return i;
}

2. Now press the Run button... you will notice the engine flagged an error

The engine even tells you where the issue is... the single quote following the exclamation point at the end of the string is missing. 

3. Now add the single quote so the line now looks like this (see below).

 console.log('Using Limelight XE scripting is easy!');

4. Click Update to save it.

5. Click Run again to execute the updated script.

You should now see the output from the script as shown below.

Some things to remember when coding

  • When making changes, make sure to save your altered code before running the script by pressing the Update button.  The script engine runs the file, not the altered code in the editing window.  If you attempt to run a script you have not saved, you will receive a warning from the server.
  • Scripts run with administrator privileges and therefore have complete control of the system... so they can alter any writeable property on any accessible object including those on other Limelight XE servers.  This includes all connected hardware such as PLCs, access control components, video sources, etc.
  • Only administrators can edit scripts, but operators can run them - a general user would not be able to even see this section of the server.

See the next scripting tutorial on accessing object properties to understand how this engine integrates with Limelight XE.

Related Topics

About

Strasis Systems, LLC is a provider of software for command and control centers, data visualization, security and systems integration.