From SpinetiX Support Wiki

Jump to: navigation, search
The HMP conforms with the ECMAScript Standard (ECMA-262) and implements SpiderMonkey as JavaScript engine.



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

  • New APIs introduced in 3.0 firmware:
    • HTMLImageElement, an HTML5 API to query size information on graphic resources.
    • RS232 I/O API to read and write from the serial port in javascript
    • USB I/O API 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="" />
       // Your code goes here ...

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.