Sending & Receiving Data
This guide aims to help you understand how data is exchanged between the flight simulator and the web app.
Prerequisites
- JLS_JetBridge
- JLS API > DataStreamClient
Setting up X-Plane
// TODO: add to docs
Setting up the Server
// TODO: add to docs
Setting up the Client
Create a new instance of
JLS.loaders.DataStreamClient, specifying theipand any options (if required).const xpDataClient = new DataStreamClient('127.0.0.1', { port: 8585, socketType: 'io', autoConnect: false, })Register the required datarefs for this screen
xpDataClient.registerDataRefs([ 'jetlink/rj45...', 'jetlink/rj45...', 'jetlink/rj45...', 'jetlink/rj45...', 'jetlink/rj45...', 'jetlink/rj45...', 'jetlink/rj45...', 'jetlink/rj45...', ])
Set the main data client to use as the globally shared. This allows you have different data coming from more than one source and set the main client at anytime. This can be helpful for using the same app for many flight simulations or having a "back-up" data source if the initial client fails.
DataStreamClient.setShared(xpDataClient)
That's it! The client is now receiving data. Each time data is received, the client's
onMessageevent is fired and can be used for any purpose. To bind an animating element to a dataref set it'sdataRefvalue.const engine1_oilPress_Pointer = new PointerElement({ ... dataRef: 'jetlink/rj45...', ... })
JSON Schema
The DataStreamClient returns an array of objects. Each object includes a dataRef which is of type string and a dataValue with the type of data (generally a string, float, int).
Expected data format received from JLS JetBridge
[
{
"dataRef": "jetlink/rj45...",
"dataValue": 98.42
},
{
"dataRef": "jetlink/rj45...",
"dataValue": 1
},
{
"dataRef": "jetlink/rj45...",
"dataValue": "OFF"
}
]
The JetBridge expects an array of objects with dataCommand being a string of the X-Plane dataref to change along with a dataValue (generally a string, float, int).
Expected data format to send commands to JLS JetBridge
[
{
"dataCommand": "jetlink/rj45...",
"dataValue": "OFF"
}
]