JavaScript
From SpinetiX Support Wiki

Contents |
ECMAScript
- ECMAScript is the scripting language that forms the basis of several well-known client-side scripting languages like JavaScript, JScript, ActionScript etc.
- ECMAScript is standardized by the Ecma International standards organization in the ECMA-262 specification and ISO/IEC 16262.
JavaScript engine and core objects
As JavaScript engine, the HMP uses the open-source SpiderMonkey JavaScript engine, which is currently maintained by the Mozilla Foundation.
- As of firmware 3.0.0 the HMP uses version 1.8.5 of SpiderMonkey, firmware 2.2.x uses version 1.8.0.
- SpiderMonkey 1.8.5 implements ECMAScript 5, 1.8.0 implements ECMAScript 3.
- To get started with the JavaScript language, refer to Mozilla's JavaScript Guide. You can also check out W3Schools' JavaScript Tutorial or JavaScript Wikibook.
- For the complete documentation of JavaScript language features, refer to the JavaScript Reference.
The following are particularly relevant to digital signage applications:
- Global objects:
Date,
RegExp,
String;
- Functions:
decodeURI(),
decodeURIComponent,
encodeURI(),
encodeURIComponent.
Supported APIs
- µDOM API See The SVG Micro DOM (uDOM) for information about the DOM APIs used to manipulate SVG content on screen and to create interactive applications.
- See also the JavaScript additions to the SVG uDOM.
- Global variables for device identification:
MULTI_SCREEN_ID
,DEVICE_NAME
,SERIAL_NUMBER
anddeviceInfo
. - Shared variables framework for real-time data exchange and instant messaging.
- Parsing functions for the parsing of RSS, CSV and iCalendar files.
- jSignage API to simplify writing JavaScript code.
- New APIs introduced in 3.0 firmware:
- HTMLImageElement, an HTML5 API to query size information on graphic resources.
- RS232 Programming to read and write from the serial port in javascript
- USB I/O Programming to control and receive events from USB Human Interface Devices in the form of digital and analog inputs/outputs.
- Web Storage API to enable permanent storage of data on the HMP.
- Node.js API - to create UDP and TCP sockets and servers. The supported modules are: net, dgram, events and the Buffer object.
How to include JavaScript code
To include JavaScript code inside an SVG file, the <script> element is used. The JavaScript code can either be placed inline in the <script>
element (as character data) or as an external resource, referenced through xlink:href
attribute.
<script xlink:href="http://download.spinetix.com/spxjslibs/jSignage.js" /> <script> <![CDATA[ // Your code goes here ... ]]> </script>
In case of interactive projects, the JavaScript code can also be included using the <handler> element in a similar manner as above.
How to debug the code
The best tool to debug the JavaScript code is to use the Developer Console included into Elementi X (respectively the HMD Developer Console included into HMD Professional). Otherwise, you can use standard alert messages - these are displayed on the screen in Elementi / HMD and written inside the javascript.log on the HMP.