A package for communicating with opentrack via UDP over network.
npm install opentrackA couple examples are available in the /examples folder for both client and server.
The client is used when you want to input data to opentrack.
const OpenTrack = require('opentrack')
const client = new OpenTrack.Client('127.0.0.1', 4243)
// Called every time data is sent
client.onUpdate((transform, delta) => {
// The modified transform will be sent on the next update
transform.rotation.z += delta * 15
})The server is used when you want to output data from opentrack.
const OpenTrack = require('opentrack')
const server = new OpenTrack.Server('127.0.0.1', 4242)
// Called when the server is listening
server.on('listening', address => {
console.log(`Server listening on ${address}`)
})
// Called every time opentrack sends an update
server.on('transformUpdated', transform => {
console.log(transform.toString())
})The client is used to send data to opentrack.
Client(host = '127.0.0.1', port = 4242, options = {})hostThe host address to send data to.portThe port to use.optionsAn object containing optional settings for the client.updateRate(default250) How many updates to send per second. The default of250comes from opentrack's own output system.startPaused(defaultfalse) Should the client start paused? When creating a new client, it will immediately begin sending data.
handlerA function to be called when the client sends an update to opentrack.transformthe current transform of the client.deltathe time delta since the last update.
When the client sends data, it calls the handler function to allow changes to be applied to the transform object. Changes to the transform can be applied outside of the handler function, but it's easier and more game-like to handle it here as it provides the loop and delta time.
paused(defaulttrue) A boolean to set the paused state of the client.
When the client is paused, it will not send data, but will continue to loop in the background.
updateRate(default250) How many updates should be sent to opentrack per second.
The loop is simple and relies on setInterval, so there may be a pause when changing the update rate.
hostthe host address to send data to.
Unlike the Server, the client can easily change its target host and port.
portthe host port to send data to.
Returns the time delta since the last update.
Returns the Transform object of the client.
transformThe newTransformobject to be applied to the client.
Returns an object containing address data for the server.
Objectipstring of the server's IPportnumber of the server's portfamilystring of IP family (Example:IPv4)
Returns a string of the server's address. (Example: 127.0.0.1:4242)
Closes the bound socket and stops the update loop.
The server is used to receive data from opentrack.
Server(host = '127.0.0.1', port = 4242)hostThe host address to send data to.portThe port to use.
The server object extends the default EventEmitter. Events can be bound like this:
server.on('listening', address => {
console.log(`Server listening on ${address}`)
})addressstring containing the address of the server. Formatted bygetAddressString()Fired when the server begins to listen for data.
transformaTransformobject. Fired when data is received from opentrack.
Fired when the server socket closes.
errorcontains error from socket. Fired when an error occurs with the server's socket.
Returns the transform of the server. The transform is updated when the server receives an update from opentrack.
Returns an object containing address data for the server.
Objectipstring of the server's IPportnumber of the server's portfamilystring of IP family (Example:IPv4)
Returns a string of the server's address. (Example: 127.0.0.1:4242)
Closes the bound socket.
The Transform object holds data for position and rotation.
Transform(x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0)xx position.yy position.zz position.rxx euler rotation in degrees.ryy euler rotation in degrees.rzz euler rotation in degrees.
positionA vector object containing the position.rotationA vector object containing the euler rotation in degrees.
- 'buffer' A buffer following the opentrack UDP protocol.
Returns a new Transform object using data from the buffer.
- 'buffer' A buffer following the opentrack UDP protocol.
Returns self. Sets the transform's data using data from the buffer.
transformA Transform object.
Applies the values from the given Transform to the current Transform.
Returns a new buffer in the format of the opentrack protocol.
Returns a neatly formatted string for debugging purposes.
The Transform object holds data for position and rotation.
Vector(x = 0, y = 0, z = 0)xx value.yy value.zz value.
xThe x value.yThe y value.zThe z value.
xThe x value to apply.yThe y value to apply.zThe z value to apply.
Returns self.
This is the format used by opentrack when sending and receiving data.
OpenTrack uses 6 little endian doubles for position and rotation.
48 bytes are used in the following format:
| offset | name |
|---|---|
| 0 | position x |
| 8 | position y |
| 16 | position z |
| 24 | rotation x |
| 32 | rotation y |
| 40 | rotation z |