Node.js Bindings

Tangible Engine enables users to take advantage of specially engineered physical objects that can be recognized by Ideum touch-enabled products. The objects, called tangibles, are made of conductive material that mimics touches on the surface of a p-cap display. On the software end, the Tangible Engine is a windows service that runs in the background, awaiting the connection of client apps that require tangible recognition capabilities. A service model was chosen to enable Ideum to create and deploy fixes and new features without requiring clients to rebuild their own apps.

The Tangible Engine Node.js binding offers an interface for interacting with the Tangible Engine 2 service using Node.js application frameworks, such as Electron. The Node.js bindings use a TCP socket to communicate with the locally running Tangible Engine service.

Setting up the Engine

Once initialized, the TangibleEngine class creates a TCP socket connection with the Tangible Engine service and registered touch event listeners on a DOM target.

Install

Import the TangibleEngine class using Node module exports, or import if your development environment supports ES6-style imports (such as when transpiling with Babel).

// using exports module
const TangibleEngine = require('./TangibleEngine').default

// using ES6-style imports
import TangibleEngine from './TangibleEngine'

Instantiate TangibleEngine. By default, the TangibleEngine constructor will attach touch event listeners to the window and open a TCP socket on port 4949. Optionally, you can pass a DOMString selector for the touch event listeners, and a port number.

// with defaults
const te = new TangibleEngine()

// with options
const te = new TangibleEngine('#app', 4002)

Note

The port number must match the port number used by the Tangible Engine service.

Interfacing with the Engine

  • Initialize TangibleEngine
// intialize update loop and register touch event listeners
te.init()
  • Subscribe to the patterns event
te.on('patterns', (response) => {
  response.PATTERNS.foreach((pattern) => {
    // do some stuff
  })
})
  • Subscribe to the update event
te.on('update', (response) => {
  response.TANGIBLES.foreach((tangible) => {
    // do some stuff
  })
})

Tear-down

  • De-initialize the Tangible Engine client and remove registered touch event listeners
te.deinit()
Last Updated: 9/8/2020, 9:37:23 AM