liblwes-node
Node.js port of the LWES (Light Weight Event System) library. Compiled from C to Javascript using Emscripten + asm.js and wrapped in a Javascript API which abstracts the low-level internals.
Installation
$ npm install liblwes
Usage
Emitter
var Emitter = Emitter; // Example of emitter with ESF validation and type inferencevar emitter = 'address' : '127.0.0.1' 'port' : 1111 'esf' : __dirname +'/data/sample.esf'; emitter; // Example of emitter with ESF validation and no type inferencevar emitter2 = 'esf' : __dirname +'/data/sample.esf' ; emitter2; // Example of emitter with no ESF validation and no type inferencevar emitter3 = ; emitter3;
The type of each event attribute can be defined in an ESF file, e.g. sample.esf
:
FooBar # Sample LWES event
{
string fooStr; # Sample string attribute
int16 foo16; # Sample 16-bit integer attribute
uint16 fooU16; # Sample 16-bit unsigned integer attribute
int32 foo32; # Sample 32-bit integer attribute
uint32 fooU32; # Sample 32-bit unsigned integer attribute
int64 foo64; # Sample 64-bit integer attribute
uint64 fooU64; # Sample 64-bit unsigned integer attribute
boolean fooBool; # Sample boolean attribute
ip_addr fooIP; # Sample IP address attribute
}
For more details on the LWES protocol and the ESF specification, please see the LWES documentation at lwes.org or their github page at github.com/lwes.
Listener
var Listener = Listener; var listener = '127.0.0.1' 1111; // Listen to all eventslistener; // Listen to specific eventslistener;
Note: 64-bit integers are returned as strings.
API documentation
Emitter
The constructor of the Emitter
class accepts the following options:
Name | Description |
---|---|
address |
The destination IP address ('127.0.0.1 ' by default). |
port |
The destination port (1111 by default). |
esf |
Path to the ESF (Event Specification Format) file (e.g. 'data/sample.esf' ). |
heartbeat |
Heartbeat frequency, e.g. 60 . Disabled (false ) by default. |
iface |
The network interface (all local interfaces by default). |
ttl |
The multicast TTL (time to live) |
The following attribute types can be used in the event object passed to the emit
function:
Type | Description |
---|---|
UInt16 |
16-bit unsigned integer |
Int16 |
16-bit integer |
UInt32 |
32-bit unsigned integer |
Int32 |
32-bit integer |
String |
String |
IPAddr |
IP address |
Int64 |
64-bit integer |
UInt64 |
64-bit unsigned integer |
Boolean |
Boolean |
Emitters can be closed individually with emitter.close()
or globally with Emitter.closeAll()
. This releases all resources allocated in the emscripten subsystem and fires a System::Shutdown
event if the heartbeat
is enabled.
Listener
Listeners conform to Node's EventEmitter
API, with the addition of wildcard events to support notifications on any LWES event:
listener;
Listeners can be closed with the close
method:
listener;
You can capture liblwes
errors by listening on liblwes::error
events, e.g.:
listener;
Compilation
You can recompile the liblwes.js
library with emscripten by running make
. The emcc
binary must be in your PATH
.
License
Created by Luca Bernardo Ciddio for YP Intellectual Property, LLC (YellowPages.com) and licensed under the MIT License.