DataStreamClient
This client handles communication between the sandyApps and the JLS JetBridge. It can be used with the native WebSocketAPI (default) or with the socket.io library.
JLS.loaders.DataStreamClient
new DataStreamClient(ip, options)
// Implementation example - shorten for brevity
import { DataStreamClient } from 'path/to/loaders'
const xplaneDataClient = new DataStreamClient(127.0.0.1, {
port: 8585,
socketType: 'native',
});
DataStreamClient.setShared(xplaneDataClient) // Use this instance of a data client for grabbing data
// Optionally listen for various events
JLS.DataStreamClient.shared
.onConnectionSuccess(() => {
// do something
})
.onMessage(() => {
// do something
})
.onDisconnect(() => {
// do something, perhaps show an error on screen
})
options
The word "options" is used somewhat loosely here as most of the fields are required. Actual optional parameters will have an optional flag.
| Name | Type | Default | Description |
|---|---|---|---|
| directories | object | { images: 'images', sounds: 'sounds' } | optional The path to store each type of asset. |
Members
ip
The ip of the host to connect to.
port
The port of the host to connect to.
socket
A reference to the socket connection.
socketType
The type of socket that the client is using.
autoConnect
Whether to connect to the host automatically.
hasStarted
A convience method to determine if the client has started and is receiving data.
registeredDataRefs
A directory / list of all the registered datarefs the client is listening for.
data
The data the client receives.
shared
The instance of the shared data client.
Methods
setShared(obj)
Sets the shared instance given a instantiated DataStreamClient object.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| obj | object | --- | The instance of the data stream client |
registerDataRefs(dataRefArray)
Registers a dataref. The dataRefArray is a array of strings that you would like to subscribe to. Each string in the array is simply a key/id. In the context of XPlane, it is the actual dataRef.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| dataRefArray | array | --- | An array of strings that are datarefs. Easiest way to get all data refs needed is to use theJLS.Screen.getAllDataRefs method. |
getRegisteredDataRefs()
Returns the registered datarefs.
getDataValue(dataRef)
Returns the dataref's value.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| dataRef | string | --- | The data ref to get the value of. |
getAll()
Gets all datarefs along with their current value. Will return empty array if no data is being received. For get a list of current registered datarefs. Use the getRegisteredDataRefs.
sendData(data, channel)
Sends socket data over the socket connection.
parameters
| Name | Type | Default | Description |
|---|---|---|---|
| data | {any} | --- | The data to send |
| channel | string | message | optional The channel to emit the message to. Especially useful for discrete messages on different channels when using socket.io |
update(id, value)
Convience function to update the globally stored data. May also simply set directly like so: this.data[*] = *
| Name | Type | Default | Description |
|---|---|---|---|
| id | string | --- | The data ref |
| value | {any} | --- | The value to set for this data ref |
connect()
Connects to the socket connection.
disconnect()
Disconnects the socket connection.
init()
Called from the constructor function, this calls other functions to "initialize" or setup the class.