2.0.1 • Published 5 years ago
@lookapanda/extplane-ts v2.0.1
extplane-ts
A TypeScript client library for nodeJs that uses the ExtPlane plugin.
Based on ExtPlaneJs
Prerequisites
- You obviously need X-Plane with the ExtPlane plugin installed.
- NodeJs >= 10.18
Installation
Install via npm
$ npm install --save @lookapanda/extplane-js
Install via yarn
$ yarn add @lookapanda/extplane-js
Usage
const { ExtPlane } = '@lookapanda/extplane-js';
const extPlane = new ExtPlane({
host: '127.0.0.1',
port: 51000,
debug: true,
});
extPlane
.interval(1000)
.observe([
'sim/flightmodel/position/latitude',
'sim/flightmodel/position/longitude',
'sim/time/framerate_period',
])
.subscribe({
next: ([dataRef, value]) => {
switch (dataRef) {
case 'sim/flightmodel/position/latitude':
console.warn('Lat', value);
break;
case 'sim/flightmodel/position/longitude':
console.warn('Long', value);
break;
case 'sim/time/framerate_period':
console.warn('FPS', Math.floor(1 / value));
break;
}
},
});
API
ExtPlane(config: ExtPlaneOptions)
Instantiates extplane-ts. Does not connect until an observer is added!
ExtPlane.connect()
Connects to ExtPlane
ExtPlane.disconnect()
Disconnects ExtPlane
ExtPlane.observe(dataRefs: string[])
Connects to ExtPlane (if not already connected) and subscribes to one or more datarefs
ExtPlane.unobserve(dataRefs: string[])
Unsubscribes one or more datarefs, but does not close the connection