flightnethelper 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Main.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Msg } from "./types";
2
+ export declare class FlightnetPredictions {
3
+ private ws;
4
+ private latestPayload;
5
+ private idx;
6
+ private timer;
7
+ /** Client reads this: { t, d } */
8
+ data: Msg | null;
9
+ constructor(url: string, intervalMs?: number);
10
+ private start;
11
+ private stop;
12
+ }
package/dist/Main.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FlightnetPredictions = void 0;
7
+ const ws_1 = __importDefault(require("ws"));
8
+ const ORDER = ["1", "2", "3", "4", "5"];
9
+ class FlightnetPredictions {
10
+ constructor(url, intervalMs = 200) {
11
+ this.latestPayload = null;
12
+ this.idx = 0;
13
+ this.timer = null;
14
+ /** Client reads this: { t, d } */
15
+ this.data = null;
16
+ this.ws = new ws_1.default(url);
17
+ this.ws.on("message", raw => {
18
+ try {
19
+ this.latestPayload = JSON.parse(raw.toString());
20
+ }
21
+ catch {
22
+ // ignore malformed frames
23
+ }
24
+ });
25
+ this.ws.on("open", () => this.start(intervalMs));
26
+ this.ws.on("close", () => this.stop());
27
+ }
28
+ start(intervalMs) {
29
+ if (this.timer)
30
+ return;
31
+ this.timer = setInterval(() => {
32
+ if (!this.latestPayload)
33
+ return;
34
+ const msg = this.latestPayload[ORDER[this.idx]];
35
+ if (!msg)
36
+ return;
37
+ // ✅ expose ONLY { t, d }
38
+ this.data = msg;
39
+ this.idx = (this.idx + 1) % ORDER.length;
40
+ }, intervalMs);
41
+ }
42
+ stop() {
43
+ if (this.timer) {
44
+ clearInterval(this.timer);
45
+ this.timer = null;
46
+ }
47
+ }
48
+ }
49
+ exports.FlightnetPredictions = FlightnetPredictions;
@@ -0,0 +1,2 @@
1
+ export { FlightnetPredictions } from "./Main";
2
+ export * from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FlightnetPredictions = void 0;
18
+ var Main_1 = require("./Main");
19
+ Object.defineProperty(exports, "FlightnetPredictions", { enumerable: true, get: function () { return Main_1.FlightnetPredictions; } });
20
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,7 @@
1
+ export interface Msg {
2
+ t: string;
3
+ d: any;
4
+ }
5
+ export interface WsPayload {
6
+ [key: string]: Msg;
7
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "flightnethelper",
3
+ "version": "1.0.0",
4
+ "description": "A npm package that is meant to help a client connecting to flightnet.",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "package.json"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "dependencies": {
18
+ "ws": "^8.16.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^25.0.3",
22
+ "@types/ws": "^8.18.1"
23
+ }
24
+ }