add examples from README to examples folder

This commit is contained in:
2024-10-23 16:47:24 -05:00
parent 82d4e17ec9
commit 9273f5a1a5
2 changed files with 48 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
const { Encoder, Tracker } = require('../dist');
const encoder = new Encoder('Server Name', 2, 3); //server name, version high, version low
const trackers = [];
const tracker = new Tracker(1, 'Tracker 1'); // id, name
tracker.setPos(1.0, 1.0, 1.0); // x, y, z
trackers.push(tracker);
const timestamp = 1;
// these two calls return an array of Buffers due to potential splitting that might take place because of max UDP packet size
const dataPackets = encoder.getDataPackets(timestamp, trackers);
const infoPackets = encoder.getInfoPackets(timestamp, trackers);
dataPackets.forEach((dataPacket) => {
console.log('send packet somehow');
console.log(dataPacket);
});
infoPackets.forEach((infoPacket) => {
console.log('send packet somehow');
console.log(infoPacket);
});