/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@z0mt3c/racehub-io-f1-telemetry-client@0.2.7-9/build/src/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)Object.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t.default=e,t};Object.defineProperty(exports,"__esModule",{value:!0});const dgram=__importStar(require("dgram")),events_1=require("events"),constants=__importStar(require("./constants"));exports.constants=constants;const constantsTypes=__importStar(require("./constants/types"));exports.constantsTypes=constantsTypes;const packets_1=require("./parsers/packets"),packetTypes=__importStar(require("./parsers/packets/types"));exports.packetTypes=packetTypes;const DEFAULT_PORT=20777;exports.DEFAULT_PORT=DEFAULT_PORT;const FORWARD_ADDRESSES=void 0;exports.FORWARD_ADDRESSES=FORWARD_ADDRESSES;const BIGINT_ENABLED=!0;exports.BIGINT_ENABLED=BIGINT_ENABLED;const ADDRESS="localhost";class F1TelemetryClient extends events_1.EventEmitter{constructor(e={}){super();const{port:t=DEFAULT_PORT,bigintEnabled:s=BIGINT_ENABLED,forwardAddresses:a=FORWARD_ADDRESSES}=e;this.port=t,this.bigintEnabled=s,this.forwardAddresses=a,this.socket=dgram.createSocket("udp4")}static parseBufferMessage(e,t=!1){const{m_packetFormat:s,m_packetId:a}=F1TelemetryClient.parsePacketHeader(e,t),r=F1TelemetryClient.getParserByPacketId(a);if(!r)return;return{packetData:new r(e,s,t),packetID:Object.keys(constants.PACKETS)[a]}}static parsePacketHeader(e,t){const s=new packets_1.PacketFormatParser,{m_packetFormat:a}=s.fromBuffer(e);return new packets_1.PacketHeaderParser(a,t).fromBuffer(e)}static getPacketSize(e,t){const{PACKET_SIZES:s}=constants;return Object.values(s)[t][e]}static getParserByPacketId(e){const{PACKETS:t}=constants;switch(Object.keys(t)[e]){case t.session:return packets_1.PacketSessionDataParser;case t.motion:return packets_1.PacketMotionDataParser;case t.lapData:return packets_1.PacketLapDataParser;case t.event:return packets_1.PacketEventDataParser;case t.participants:return packets_1.PacketParticipantsDataParser;case t.carSetups:return packets_1.PacketCarSetupDataParser;case t.carTelemetry:return packets_1.PacketCarTelemetryDataParser;case t.carStatus:return packets_1.PacketCarStatusDataParser;case t.finalClassification:return packets_1.PacketFinalClassificationDataParser;case t.lobbyInfo:return packets_1.PacketLobbyInfoDataParser;case t.carDamage:return packets_1.PacketCarDamageDataParser;case t.sessionHistory:return packets_1.PacketSessionHistoryDataParser;default:return null}}handleMessage(e){this.forwardAddresses&&this.bridgeMessage(e);const t=F1TelemetryClient.parseBufferMessage(e,this.bigintEnabled);t&&t.packetData&&this.emit(t.packetID,t.packetData.data)}bridgeMessage(e){if(!this.socket)throw new Error("Socket is not initialized");if(!this.forwardAddresses)throw new Error("No ports to bridge over");for(const t of this.forwardAddresses)this.socket.send(e,0,e.length,t.port,t.ip||"0.0.0.0")}start(){this.socket&&(this.socket.on("listening",(()=>{if(!this.socket)return;const e=this.socket.address();console.log(`UDP Client listening on ${e.address}:${e.port} 🏎`),this.socket.setBroadcast(!0)})),this.socket.on("message",(e=>this.handleMessage(e))),this.socket.bind({port:this.port,exclusive:!1}))}stop(){if(this.socket)return this.socket.close((()=>{console.log("UDP Client closed 🏁"),this.socket=void 0}))}}exports.F1TelemetryClient=F1TelemetryClient;
//# sourceMappingURL=/sm/462710ee1451a37cf147ab3cab0d92094b35ffd49e370c64356b61cc6c577113.map