gameglue 4.0.0 → 4.0.1

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/gg.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("oidc-client-ts"),e=require("jwt-decode"),o=require("socket.io-client"),n=require("event-emitter");const i={},a=(t,e)=>l()?localStorage.setItem(t,e):i[t]=e,r=t=>l()?localStorage.getItem(t):i[t],s=t=>l()?localStorage.removeItem(t):delete i[t],l=()=>!("object"==typeof process&&"[object process]"===String(process));function m(t){if(!t)return!1;const e=(t.message||t.toString()||"").toLowerCase();return e.includes("cors")||e.includes("cross-origin")||e.includes("network error")||e.includes("failed to fetch")||e.includes("networkerror")||e.includes("load failed")||e.includes("xhr poll error")||e.includes("websocket error")||e.includes("transport")&&e.includes("error")}function p(t,e){console.error(`\n╔══════════════════════════════════════════════════════════════════════════════╗\n║ GameGlue SDK: Possible CORS Error Detected ║\n╠══════════════════════════════════════════════════════════════════════════════╣\n║ Context: ${t.padEnd(66)}║\n║ URL: ${(e||"unknown").substring(0,70).padEnd(70)}║\n╠══════════════════════════════════════════════════════════════════════════════╣\n║ This error typically means the server rejected the request due to CORS. ║\n║ ║\n║ To fix this, add your origin to your app's allowed Web Origins: ║\n║ ║\n║ 1. Go to the GameGlue Developer Portal (https://developer.gameglue.gg) ║\n║ 2. Select your app ║\n║ 3. Add your origin to "Web Origins" and save ║\n║ ║\n║ IMPORTANT: Protocol and port must match exactly. ║\n║ http://localhost:3000 and https://localhost:3000 are different origins. ║\n║ http://localhost:3000 and http://localhost:5000 are different origins. ║\n╚══════════════════════════════════════════════════════════════════════════════╝\n`)}let c=null;class _{constructor(e){const o=e.authUrl||"https://auth.gameglue.gg/realms/GameGlue";this._oidcSettings={authority:o,client_id:e.clientId,redirect_uri:g(e.redirect_uri||window.location.href),post_logout_redirect_uri:g(window.location.href),response_type:"code",scope:`openid ${(e.scopes||[]).join(" ")}`,response_mode:"fragment",filterProtocolClaims:!0},this._oidcClient=new t.OidcClient(this._oidcSettings),this._refreshCallback=()=>{},this._refreshTimeout=null}async isAuthenticated(){return this._hasCallbackParams()&&await this._processCallback(),this._hasValidTokens()}login(){this._oidcClient.createSigninRequest({state:{bar:15}}).then(t=>{window.location=t.url}).catch(t=>{m(t)&&p("Login Request",this._oidcSettings.authority),console.error("Failed to create signin request:",t)})}logout(t={}){if(s("gg-auth-token"),s("gg-refresh-token"),clearTimeout(this._refreshTimeout),!1!==t.redirect){const t=`${this._oidcSettings.authority}/protocol/openid-connect/logout?post_logout_redirect_uri=${encodeURIComponent(this._oidcSettings.post_logout_redirect_uri)}`;window.location.href=t}}getUser(){const t=this._getAccessToken();if(!t)throw new Error("Not authenticated");return e(t).sub}getAccessToken(){return this._getAccessToken()}onTokenRefreshed(t){this._refreshCallback=t}_hasCallbackParams(){return location.hash.includes("state=")&&(location.hash.includes("code=")||location.hash.includes("error="))}_clearCallbackUrl(){window.history.replaceState("",document.title,window.location.pathname+window.location.search)}async _processCallback(){if(c)await c;else{c=this._doProcessCallback();try{await c}finally{c=null}}}async _doProcessCallback(){try{const t=await this._oidcClient.processSigninResponse(window.location.href);if(t.error)throw this._clearCallbackUrl(),new Error(t.error);if(!t.access_token)throw this._clearCallbackUrl(),new Error("No access token received");this._setAccessToken(t.access_token),this._setRefreshToken(t.refresh_token),this._clearCallbackUrl()}catch(t){if(this._hasValidTokens())return void this._clearCallbackUrl();throw this._clearCallbackUrl(),t}}_hasValidTokens(){const t=this._getAccessToken();if(!t)return!1;try{const o=e(t);return new Date(1e3*o.exp)>new Date}catch{return!1}}_getAccessToken(){const t=r("gg-auth-token");return t&&this._setTokenRefreshTimeout(t),t||void 0}_setAccessToken(t){return this._setTokenRefreshTimeout(t),a("gg-auth-token",t)}_setRefreshToken(t){return a("gg-refresh-token",t)}_getRefreshToken(){return r("gg-refresh-token")}_setTokenRefreshTimeout(t){if(t){clearTimeout(this._refreshTimeout);try{const o=1e3*e(t).exp-Date.now()-5e3;o>0&&(this._refreshTimeout=setTimeout(()=>{this._attemptRefresh()},o))}catch{}}}async _attemptRefresh(){const t=`${this._oidcSettings.authority}/protocol/openid-connect/token`,e=this._oidcSettings.client_id,o=this._getRefreshToken();try{const n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,grant_type:"refresh_token",refresh_token:o})});if(200===n.status){const t=await n.json();this._setAccessToken(t.access_token),this._setRefreshToken(t.refresh_token),this._refreshCallback(t.access_token)}}catch(e){m(e)&&p("Token Refresh",t),console.error("Token refresh failed:",e)}}}function g(t){return t.endsWith("/")?t.replace(/\/+$/,""):t}const d={radiansToDegrees:t=>t*(180/Math.PI),degreesToRadians:t=>t*(Math.PI/180),metersToFeet:t=>3.28084*t,feetToMeters:t=>t/3.28084,msToKnots:t=>1.94384*t,knotsToMs:t=>t/1.94384,msToFpm:t=>196.85*t,toBoolean:t=>Boolean(t),divideBy100:t=>t/100},u={category:"flight_sim",name:"Flight Simulator",description:"Canonical telemetry fields for flight simulation games",recommendedUpdateRateHz:10,requiredFields:["latitude","longitude","altitude","indicated_airspeed","heading","vertical_speed","on_ground"],fields:{latitude:{type:"number",description:"Aircraft latitude",unit:"degrees",min:-90,max:90,group:"Position"},longitude:{type:"number",description:"Aircraft longitude",unit:"degrees",min:-180,max:180,group:"Position"},altitude:{type:"number",description:"Aircraft altitude above sea level",unit:"ft",min:-2e3,max:1e5,group:"Position"},altitude_agl:{type:"number",description:"Aircraft altitude above ground level",unit:"ft",min:0,max:1e5,group:"Position"},on_ground:{type:"boolean",description:"Whether aircraft is on the ground",group:"Position"},indicated_airspeed:{type:"number",description:"Indicated airspeed",unit:"kts",min:0,max:1e3,group:"Velocity"},true_airspeed:{type:"number",description:"True airspeed",unit:"kts",min:0,max:1e3,group:"Velocity"},ground_speed:{type:"number",description:"Ground speed",unit:"kts",min:0,max:1e3,group:"Velocity"},mach:{type:"number",description:"Mach number",min:0,max:5,group:"Velocity"},vertical_speed:{type:"number",description:"Vertical speed",unit:"ft/min",min:-2e4,max:2e4,group:"Velocity"},g_force:{type:"number",description:"Current G-force",unit:"G",min:-10,max:10,group:"Velocity"},heading:{type:"number",description:"Aircraft magnetic heading",unit:"degrees",min:0,max:360,group:"Attitude"},true_heading:{type:"number",description:"Aircraft true heading",unit:"degrees",min:0,max:360,group:"Attitude"},pitch:{type:"number",description:"Aircraft pitch angle",unit:"degrees",min:-90,max:90,group:"Attitude"},roll:{type:"number",description:"Aircraft roll/bank angle",unit:"degrees",min:-180,max:180,group:"Attitude"},yaw:{type:"number",description:"Aircraft yaw angle",unit:"degrees",min:-180,max:180,group:"Attitude"},throttle_0:{type:"number",description:"Engine 0 throttle position",unit:"%",min:0,max:100,group:"Engine"},throttle_1:{type:"number",description:"Engine 1 throttle position",unit:"%",min:0,max:100,group:"Engine"},throttle_2:{type:"number",description:"Engine 2 throttle position",unit:"%",min:0,max:100,group:"Engine"},throttle_3:{type:"number",description:"Engine 3 throttle position",unit:"%",min:0,max:100,group:"Engine"},rpm_0:{type:"number",description:"Engine 0 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},rpm_1:{type:"number",description:"Engine 1 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},rpm_2:{type:"number",description:"Engine 2 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},rpm_3:{type:"number",description:"Engine 3 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},n1_0:{type:"number",description:"Engine 0 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n1_1:{type:"number",description:"Engine 1 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n1_2:{type:"number",description:"Engine 2 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n1_3:{type:"number",description:"Engine 3 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_0:{type:"number",description:"Engine 0 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_1:{type:"number",description:"Engine 1 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_2:{type:"number",description:"Engine 2 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_3:{type:"number",description:"Engine 3 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},egt_0:{type:"number",description:"Engine 0 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},egt_1:{type:"number",description:"Engine 1 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},egt_2:{type:"number",description:"Engine 2 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},egt_3:{type:"number",description:"Engine 3 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},fuel_quantity:{type:"number",description:"Total fuel quantity",unit:"lbs",min:0,max:6e5,group:"Fuel"},fuel_flow_0:{type:"number",description:"Engine 0 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},fuel_flow_1:{type:"number",description:"Engine 1 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},fuel_flow_2:{type:"number",description:"Engine 2 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},fuel_flow_3:{type:"number",description:"Engine 3 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},autopilot_master:{type:"boolean",description:"Autopilot master engaged",group:"Autopilot"},autopilot_altitude_hold:{type:"boolean",description:"Altitude hold engaged",group:"Autopilot"},autopilot_heading_hold:{type:"boolean",description:"Heading hold engaged",group:"Autopilot"},autopilot_vs_hold:{type:"boolean",description:"Vertical speed hold engaged",group:"Autopilot"},autopilot_speed_hold:{type:"boolean",description:"Speed hold engaged",group:"Autopilot"},autopilot_approach:{type:"boolean",description:"Approach mode engaged",group:"Autopilot"},autopilot_nav:{type:"boolean",description:"NAV mode engaged",group:"Autopilot"},flight_director:{type:"boolean",description:"Flight director active",group:"Autopilot"},autopilot_flc:{type:"boolean",description:"Flight level change mode engaged",group:"Autopilot"},autopilot_altitude_target:{type:"number",description:"Autopilot target altitude",unit:"ft",min:0,max:6e4,group:"Autopilot"},autopilot_heading_target:{type:"number",description:"Autopilot target heading",unit:"degrees",min:0,max:360,group:"Autopilot"},autopilot_vs_target:{type:"number",description:"Autopilot target vertical speed",unit:"ft/min",min:-1e4,max:1e4,group:"Autopilot"},autopilot_speed_target:{type:"number",description:"Autopilot target airspeed",unit:"kts",min:0,max:600,group:"Autopilot"},flaps:{type:"number",description:"Flaps position",unit:"%",min:0,max:100,group:"Controls"},spoilers:{type:"number",description:"Spoilers position",unit:"%",min:0,max:100,group:"Controls"},gear_down:{type:"boolean",description:"Landing gear extended",group:"Controls"},parking_brake:{type:"boolean",description:"Parking brake engaged",group:"Controls"},brake_left:{type:"number",description:"Left brake position",unit:"%",min:0,max:100,group:"Controls"},brake_right:{type:"number",description:"Right brake position",unit:"%",min:0,max:100,group:"Controls"},light_landing:{type:"boolean",description:"Landing lights on",group:"Lights"},light_taxi:{type:"boolean",description:"Taxi lights on",group:"Lights"},light_beacon:{type:"boolean",description:"Beacon lights on",group:"Lights"},light_nav:{type:"boolean",description:"Navigation lights on",group:"Lights"},light_strobe:{type:"boolean",description:"Strobe lights on",group:"Lights"},outside_air_temp:{type:"number",description:"Outside air temperature",unit:"°C",min:-80,max:60,group:"Environment"},barometric_pressure:{type:"number",description:"Barometric pressure setting",unit:"inHg",min:27,max:32,group:"Environment"},wind_direction:{type:"number",description:"Wind direction",unit:"degrees",min:0,max:360,group:"Environment"},wind_speed:{type:"number",description:"Wind speed",unit:"kts",min:0,max:200,group:"Environment"},stall_warning:{type:"boolean",description:"Stall warning active",group:"Warnings"},overspeed_warning:{type:"boolean",description:"Overspeed warning active",group:"Warnings"},sim_paused:{type:"boolean",description:"Simulation is paused",group:"Simulation"},gps_wp_distance:{type:"number",description:"Distance to next GPS waypoint",unit:"nm",min:0,max:1e4,group:"Navigation"},gps_wp_ete:{type:"number",description:"Estimated time enroute to next GPS waypoint",unit:"seconds",min:0,max:86400,group:"Navigation"}},commands:{autopilot_on:{description:"Engage autopilot master",group:"Autopilot"},autopilot_off:{description:"Disengage autopilot master",group:"Autopilot"},autopilot_toggle:{description:"Toggle autopilot master",group:"Autopilot"},autopilot_altitude_hold_on:{description:"Engage altitude hold",group:"Autopilot"},autopilot_altitude_hold_off:{description:"Disengage altitude hold",group:"Autopilot"},autopilot_heading_hold_on:{description:"Engage heading hold",group:"Autopilot"},autopilot_heading_hold_off:{description:"Disengage heading hold",group:"Autopilot"},autopilot_vs_hold_on:{description:"Engage vertical speed hold",group:"Autopilot"},autopilot_vs_hold_off:{description:"Disengage vertical speed hold",group:"Autopilot"},autopilot_nav_on:{description:"Engage NAV mode",group:"Autopilot"},autopilot_nav_off:{description:"Disengage NAV mode",group:"Autopilot"},autopilot_approach_on:{description:"Engage approach mode",group:"Autopilot"},autopilot_approach_off:{description:"Disengage approach mode",group:"Autopilot"},flight_director_on:{description:"Engage flight director",group:"Autopilot"},flight_director_off:{description:"Disengage flight director",group:"Autopilot"},autopilot_flc_on:{description:"Engage flight level change mode",group:"Autopilot"},autopilot_flc_off:{description:"Disengage flight level change mode",group:"Autopilot"},autopilot_flc_toggle:{description:"Toggle flight level change mode",group:"Autopilot"},set_autopilot_altitude:{description:"Set autopilot target altitude",group:"Autopilot",paramType:"number",paramDescription:"Target altitude in feet",paramMin:0,paramMax:6e4},set_autopilot_heading:{description:"Set autopilot target heading",group:"Autopilot",paramType:"number",paramDescription:"Target heading in degrees",paramMin:0,paramMax:360},set_autopilot_vs:{description:"Set autopilot target vertical speed",group:"Autopilot",paramType:"number",paramDescription:"Target vertical speed in ft/min",paramMin:-1e4,paramMax:1e4},set_autopilot_speed:{description:"Set autopilot target airspeed",group:"Autopilot",paramType:"number",paramDescription:"Target airspeed in knots",paramMin:0,paramMax:600},gear_up:{description:"Retract landing gear",group:"Controls"},gear_down:{description:"Extend landing gear",group:"Controls"},gear_toggle:{description:"Toggle landing gear",group:"Controls"},flaps_up:{description:"Retract flaps one notch",group:"Controls"},flaps_down:{description:"Extend flaps one notch",group:"Controls"},flaps_full:{description:"Extend flaps fully",group:"Controls"},flaps_retract:{description:"Fully retract flaps",group:"Controls"},set_flaps:{description:"Set flaps to specific position",group:"Controls",paramType:"number",paramDescription:"Flaps position (0-100%)",paramMin:0,paramMax:100},spoilers_arm:{description:"Arm spoilers",group:"Controls"},spoilers_deploy:{description:"Deploy spoilers",group:"Controls"},spoilers_retract:{description:"Retract spoilers",group:"Controls"},spoilers_toggle:{description:"Toggle spoilers",group:"Controls"},parking_brake_toggle:{description:"Toggle parking brake",group:"Controls"},parking_brake_on:{description:"Engage parking brake",group:"Controls"},parking_brake_off:{description:"Release parking brake",group:"Controls"},set_throttle:{description:"Set all throttles",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_0:{description:"Set engine 0 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_1:{description:"Set engine 1 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_2:{description:"Set engine 2 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_3:{description:"Set engine 3 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},throttle_full:{description:"Set throttles to full",group:"Engine"},throttle_idle:{description:"Set throttles to idle",group:"Engine"},throttle_cutoff:{description:"Cut throttles completely",group:"Engine"},landing_lights_on:{description:"Turn on landing lights",group:"Lights"},landing_lights_off:{description:"Turn off landing lights",group:"Lights"},landing_lights_toggle:{description:"Toggle landing lights",group:"Lights"},taxi_lights_on:{description:"Turn on taxi lights",group:"Lights"},taxi_lights_off:{description:"Turn off taxi lights",group:"Lights"},taxi_lights_toggle:{description:"Toggle taxi lights",group:"Lights"},beacon_lights_on:{description:"Turn on beacon lights",group:"Lights"},beacon_lights_off:{description:"Turn off beacon lights",group:"Lights"},beacon_lights_toggle:{description:"Toggle beacon lights",group:"Lights"},nav_lights_on:{description:"Turn on navigation lights",group:"Lights"},nav_lights_off:{description:"Turn off navigation lights",group:"Lights"},nav_lights_toggle:{description:"Toggle navigation lights",group:"Lights"},strobe_lights_on:{description:"Turn on strobe lights",group:"Lights"},strobe_lights_off:{description:"Turn off strobe lights",group:"Lights"},strobe_lights_toggle:{description:"Toggle strobe lights",group:"Lights"},pause:{description:"Pause simulation",group:"Simulation"},unpause:{description:"Unpause simulation",group:"Simulation"},pause_toggle:{description:"Toggle simulation pause",group:"Simulation"}}},h={flight_sim:u,racing_sim:u};function f(t){return h[t]}var y={gameId:"msfs",name:"Microsoft Flight Simulator",category:"flight_sim",fieldMappings:{latitude:{canonical:"latitude"},longitude:{canonical:"longitude"},indicated_altitude:{canonical:"altitude"},plane_altitude:{canonical:"altitude"},on_ground:{canonical:"on_ground",transform:"toBoolean"},altitude_agl:{canonical:"altitude_agl"},indicated_airspeed:{canonical:"indicated_airspeed"},true_airspeed:{canonical:"true_airspeed"},airspeed_mach:{canonical:"mach"},airspeed_indicated:{canonical:"indicated_airspeed"},ground_speed:{canonical:"ground_speed"},ground_velocity:{canonical:"ground_speed"},vertical_speed:{canonical:"vertical_speed"},gforce:{canonical:"g_force"},heading_gyro:{canonical:"heading"},heading_indicator:{canonical:"heading"},true_heading:{canonical:"true_heading"},attitude_indicator_pitch:{canonical:"pitch"},attitude_indicator_roll:{canonical:"roll"},yaw_rate:{canonical:"yaw"},eng_throttle_1:{canonical:"throttle_0",transform:"divideBy100"},eng_throttle_2:{canonical:"throttle_1",transform:"divideBy100"},eng_throttle_3:{canonical:"throttle_2",transform:"divideBy100"},eng_throttle_4:{canonical:"throttle_3",transform:"divideBy100"},eng_rpm_1:{canonical:"rpm_0"},eng_rpm_2:{canonical:"rpm_1"},eng_rpm_3:{canonical:"rpm_2"},eng_rpm_4:{canonical:"rpm_3"},turb_eng_n1_1:{canonical:"n1_0"},turb_eng_n1_2:{canonical:"n1_1"},turb_eng_n1_3:{canonical:"n1_2"},turb_eng_n1_4:{canonical:"n1_3"},turb_eng_n2_1:{canonical:"n2_0"},turb_eng_n2_2:{canonical:"n2_1"},turb_eng_n2_3:{canonical:"n2_2"},turb_eng_n2_4:{canonical:"n2_3"},turb_eng_itt_1:{canonical:"egt_0"},turb_eng_itt_2:{canonical:"egt_1"},turb_eng_itt_3:{canonical:"egt_2"},turb_eng_itt_4:{canonical:"egt_3"},fuel_quantity_pounds:{canonical:"fuel_quantity"},fuel_flow_pph_1:{canonical:"fuel_flow_0"},fuel_flow_pph_2:{canonical:"fuel_flow_1"},fuel_flow_pph_3:{canonical:"fuel_flow_2"},fuel_flow_pph_4:{canonical:"fuel_flow_3"},autopilot_master:{canonical:"autopilot_master",transform:"toBoolean"},autopilot_altitude_lock:{canonical:"autopilot_altitude_hold",transform:"toBoolean"},autopilot_heading_lock:{canonical:"autopilot_heading_hold",transform:"toBoolean"},autopilot_vertical_hold:{canonical:"autopilot_vs_hold",transform:"toBoolean"},autopilot_airspeed_hold:{canonical:"autopilot_speed_hold",transform:"toBoolean"},autopilot_approach_hold:{canonical:"autopilot_approach",transform:"toBoolean"},autopilot_nav1_lock:{canonical:"autopilot_nav",transform:"toBoolean"},autopilot_flight_director:{canonical:"flight_director",transform:"toBoolean"},autopilot_flc:{canonical:"autopilot_flc",transform:"toBoolean"},autopilot_altitude_set:{canonical:"autopilot_altitude_target"},autopilot_heading_set:{canonical:"autopilot_heading_target"},autopilot_vertical_speed_set:{canonical:"autopilot_vs_target"},autopilot_airspeed_set:{canonical:"autopilot_speed_target"},flaps_handle_percent:{canonical:"flaps"},spoilers_handle_percent:{canonical:"spoilers"},gear_handle_position:{canonical:"gear_down",transform:"toBoolean"},parking_brake:{canonical:"parking_brake",transform:"toBoolean"},brake_left_position:{canonical:"brake_left"},brake_right_position:{canonical:"brake_right"},light_landing:{canonical:"light_landing",transform:"toBoolean"},light_taxi:{canonical:"light_taxi",transform:"toBoolean"},light_beacon:{canonical:"light_beacon",transform:"toBoolean"},light_nav:{canonical:"light_nav",transform:"toBoolean"},light_strobe:{canonical:"light_strobe",transform:"toBoolean"},ambient_temperature:{canonical:"outside_air_temp"},kohlsman_setting_hg:{canonical:"barometric_pressure"},ambient_wind_direction:{canonical:"wind_direction"},ambient_wind_velocity:{canonical:"wind_speed"},stall_warning:{canonical:"stall_warning",transform:"toBoolean"},overspeed_warning:{canonical:"overspeed_warning",transform:"toBoolean"},sim_paused:{canonical:"sim_paused",transform:"toBoolean"},gps_wp_distance:{canonical:"gps_wp_distance"},gps_wp_ete:{canonical:"gps_wp_ete"}},commandMappings:{autopilot_on:{gameCommand:"AP_MASTER_ON",type:"command"},autopilot_off:{gameCommand:"AP_MASTER_OFF",type:"command"},autopilot_toggle:{gameCommand:"AP_MASTER",type:"command"},autopilot_altitude_hold_on:{gameCommand:"AP_ALT_HOLD_ON",type:"command"},autopilot_altitude_hold_off:{gameCommand:"AP_ALT_HOLD_OFF",type:"command"},autopilot_heading_hold_on:{gameCommand:"AP_HDG_HOLD_ON",type:"command"},autopilot_heading_hold_off:{gameCommand:"AP_HDG_HOLD_OFF",type:"command"},autopilot_vs_hold_on:{gameCommand:"AP_VS_HOLD_ON",type:"command"},autopilot_vs_hold_off:{gameCommand:"AP_VS_HOLD_OFF",type:"command"},autopilot_nav_on:{gameCommand:"AP_NAV1_HOLD_ON",type:"command"},autopilot_nav_off:{gameCommand:"AP_NAV1_HOLD_OFF",type:"command"},autopilot_approach_on:{gameCommand:"AP_APR_HOLD_ON",type:"command"},autopilot_approach_off:{gameCommand:"AP_APR_HOLD_OFF",type:"command"},flight_director_on:{gameCommand:"TOGGLE_FLIGHT_DIRECTOR",type:"command"},flight_director_off:{gameCommand:"TOGGLE_FLIGHT_DIRECTOR",type:"command"},autopilot_flc_on:{gameCommand:"FLIGHT_LEVEL_CHANGE_ON",type:"command"},autopilot_flc_off:{gameCommand:"FLIGHT_LEVEL_CHANGE_OFF",type:"command"},autopilot_flc_toggle:{gameCommand:"FLIGHT_LEVEL_CHANGE",type:"command"},set_autopilot_altitude:{gameCommand:"AP_ALT_VAR_SET_ENGLISH",type:"command"},set_autopilot_heading:{gameCommand:"HEADING_BUG_SET",type:"command"},set_autopilot_vs:{gameCommand:"AP_VS_VAR_SET_ENGLISH",type:"command"},set_autopilot_speed:{gameCommand:"AP_SPD_VAR_SET",type:"command"},gear_up:{gameCommand:"GEAR_UP",type:"command"},gear_down:{gameCommand:"GEAR_DOWN",type:"command"},gear_toggle:{gameCommand:"GEAR_TOGGLE",type:"command"},flaps_up:{gameCommand:"FLAPS_DECR",type:"command"},flaps_down:{gameCommand:"FLAPS_INCR",type:"command"},flaps_full:{gameCommand:"FLAPS_DOWN",type:"command"},flaps_retract:{gameCommand:"FLAPS_UP",type:"command"},set_flaps:{gameCommand:"FLAPS_SET",type:"command"},spoilers_arm:{gameCommand:"SPOILERS_ARM_TOGGLE",type:"command"},spoilers_deploy:{gameCommand:"SPOILERS_ON",type:"command"},spoilers_retract:{gameCommand:"SPOILERS_OFF",type:"command"},spoilers_toggle:{gameCommand:"SPOILERS_TOGGLE",type:"command"},parking_brake_toggle:{gameCommand:"PARKING_BRAKES",type:"command"},parking_brake_on:{gameCommand:"PARKING_BRAKE_SET",type:"command"},parking_brake_off:{gameCommand:"PARKING_BRAKE_SET",type:"command"},set_throttle:{gameCommand:"THROTTLE_SET",type:"command"},set_throttle_0:{gameCommand:"THROTTLE1_SET",type:"command"},set_throttle_1:{gameCommand:"THROTTLE2_SET",type:"command"},set_throttle_2:{gameCommand:"THROTTLE3_SET",type:"command"},set_throttle_3:{gameCommand:"THROTTLE4_SET",type:"command"},throttle_full:{gameCommand:"THROTTLE_FULL",type:"command"},throttle_idle:{gameCommand:"THROTTLE_CUT",type:"command"},throttle_cutoff:{gameCommand:"THROTTLE_CUT",type:"command"},landing_lights_on:{gameCommand:"LANDING_LIGHTS_ON",type:"command"},landing_lights_off:{gameCommand:"LANDING_LIGHTS_OFF",type:"command"},landing_lights_toggle:{gameCommand:"LANDING_LIGHTS_TOGGLE",type:"command"},taxi_lights_on:{gameCommand:"TAXI_LIGHTS_ON",type:"command"},taxi_lights_off:{gameCommand:"TAXI_LIGHTS_OFF",type:"command"},taxi_lights_toggle:{gameCommand:"TAXI_LIGHTS_TOGGLE",type:"command"},beacon_lights_on:{gameCommand:"BEACON_LIGHTS_ON",type:"command"},beacon_lights_off:{gameCommand:"BEACON_LIGHTS_OFF",type:"command"},beacon_lights_toggle:{gameCommand:"BEACON_LIGHTS_TOGGLE",type:"command"},nav_lights_on:{gameCommand:"NAV_LIGHTS_ON",type:"command"},nav_lights_off:{gameCommand:"NAV_LIGHTS_OFF",type:"command"},nav_lights_toggle:{gameCommand:"NAV_LIGHTS_TOGGLE",type:"command"},strobe_lights_on:{gameCommand:"STROBES_ON",type:"command"},strobe_lights_off:{gameCommand:"STROBES_OFF",type:"command"},strobe_lights_toggle:{gameCommand:"STROBES_TOGGLE",type:"command"},pause:{gameCommand:"PAUSE_ON",type:"command"},unpause:{gameCommand:"PAUSE_OFF",type:"command"},pause_toggle:{gameCommand:"PAUSE_TOGGLE",type:"command"}}};var b={gameId:"xplane",name:"X-Plane 12",category:"flight_sim",fieldMappings:{lat:{canonical:"latitude"},lon:{canonical:"longitude"},alt_msl:{canonical:"altitude"},alt_agl:{canonical:"altitude_agl"},on_ground:{canonical:"on_ground",transform:"toBoolean"},ias:{canonical:"indicated_airspeed"},tas:{canonical:"true_airspeed"},gs:{canonical:"ground_speed"},mach:{canonical:"mach"},vvi:{canonical:"vertical_speed"},g_load:{canonical:"g_force"},hdg_mag:{canonical:"heading"},hdg_true:{canonical:"true_heading"},pitch:{canonical:"pitch"},roll:{canonical:"roll"},yaw:{canonical:"yaw"},throttle_0:{canonical:"throttle_0"},throttle_1:{canonical:"throttle_1"},throttle_2:{canonical:"throttle_2"},throttle_3:{canonical:"throttle_3"},rpm_0:{canonical:"rpm_0"},rpm_1:{canonical:"rpm_1"},rpm_2:{canonical:"rpm_2"},rpm_3:{canonical:"rpm_3"},n1_0:{canonical:"n1_0"},n1_1:{canonical:"n1_1"},n1_2:{canonical:"n1_2"},n1_3:{canonical:"n1_3"},n2_0:{canonical:"n2_0"},n2_1:{canonical:"n2_1"},n2_2:{canonical:"n2_2"},n2_3:{canonical:"n2_3"},egt_0:{canonical:"egt_0"},egt_1:{canonical:"egt_1"},egt_2:{canonical:"egt_2"},egt_3:{canonical:"egt_3"},fuel_total_lbs:{canonical:"fuel_quantity"},ff_0:{canonical:"fuel_flow_0"},ff_1:{canonical:"fuel_flow_1"},ff_2:{canonical:"fuel_flow_2"},ff_3:{canonical:"fuel_flow_3"},ap_master:{canonical:"autopilot_master",transform:"toBoolean"},ap_alt_hold:{canonical:"autopilot_altitude_hold",transform:"toBoolean"},ap_hdg_hold:{canonical:"autopilot_heading_hold",transform:"toBoolean"},ap_vs_hold:{canonical:"autopilot_vs_hold",transform:"toBoolean"},ap_spd_hold:{canonical:"autopilot_speed_hold",transform:"toBoolean"},ap_apr:{canonical:"autopilot_approach",transform:"toBoolean"},ap_nav:{canonical:"autopilot_nav",transform:"toBoolean"},fd_on:{canonical:"flight_director",transform:"toBoolean"},ap_alt_set:{canonical:"autopilot_altitude_target"},ap_hdg_set:{canonical:"autopilot_heading_target"},ap_vs_set:{canonical:"autopilot_vs_target"},ap_spd_set:{canonical:"autopilot_speed_target"},flap_ratio:{canonical:"flaps"},spoiler_ratio:{canonical:"spoilers"},gear_deploy:{canonical:"gear_down",transform:"toBoolean"},park_brake:{canonical:"parking_brake",transform:"toBoolean"},brake_left:{canonical:"brake_left"},brake_right:{canonical:"brake_right"},land_lights:{canonical:"light_landing",transform:"toBoolean"},taxi_lights:{canonical:"light_taxi",transform:"toBoolean"},beacon:{canonical:"light_beacon",transform:"toBoolean"},nav_lights:{canonical:"light_nav",transform:"toBoolean"},strobe:{canonical:"light_strobe",transform:"toBoolean"},oat:{canonical:"outside_air_temp"},baro_set:{canonical:"barometric_pressure"},wind_dir:{canonical:"wind_direction"},wind_spd:{canonical:"wind_speed"},stall:{canonical:"stall_warning",transform:"toBoolean"},overspeed:{canonical:"overspeed_warning",transform:"toBoolean"},paused:{canonical:"sim_paused",transform:"toBoolean"},gps_wp_distance:{canonical:"gps_wp_distance"},gps_wp_ete:{canonical:"gps_wp_ete"}},commandMappings:{autopilot_on:{gameCommand:"sim/autopilot/servos_on",type:"command"},autopilot_off:{gameCommand:"sim/autopilot/servos_off_any",type:"command"},autopilot_toggle:{gameCommand:"sim/autopilot/servos_toggle",type:"command"},autopilot_altitude_hold_on:{gameCommand:"sim/autopilot/altitude_hold",type:"command"},autopilot_altitude_hold_off:{gameCommand:"sim/autopilot/altitude_hold",type:"command"},autopilot_heading_hold_on:{gameCommand:"sim/autopilot/heading",type:"command"},autopilot_heading_hold_off:{gameCommand:"sim/autopilot/heading",type:"command"},autopilot_vs_hold_on:{gameCommand:"sim/autopilot/vertical_speed",type:"command"},autopilot_vs_hold_off:{gameCommand:"sim/autopilot/vertical_speed",type:"command"},autopilot_nav_on:{gameCommand:"sim/autopilot/NAV",type:"command"},autopilot_nav_off:{gameCommand:"sim/autopilot/NAV",type:"command"},autopilot_approach_on:{gameCommand:"sim/autopilot/approach",type:"command"},autopilot_approach_off:{gameCommand:"sim/autopilot/approach",type:"command"},flight_director_on:{gameCommand:"sim/autopilot/fdir_on",type:"command"},flight_director_off:{gameCommand:"sim/autopilot/fdir_toggle",type:"command"},autopilot_flc_on:{gameCommand:"sim/autopilot/level_change",type:"command"},autopilot_flc_off:{gameCommand:"sim/autopilot/level_change",type:"command"},autopilot_flc_toggle:{gameCommand:"sim/autopilot/level_change",type:"command"},set_autopilot_altitude:{gameCommand:"sim/cockpit/autopilot/altitude",type:"dataref"},set_autopilot_heading:{gameCommand:"sim/cockpit/autopilot/heading_mag",type:"dataref"},set_autopilot_vs:{gameCommand:"sim/cockpit/autopilot/vertical_velocity",type:"dataref"},set_autopilot_speed:{gameCommand:"sim/cockpit/autopilot/airspeed",type:"dataref"},gear_up:{gameCommand:"sim/flight_controls/landing_gear_up",type:"command"},gear_down:{gameCommand:"sim/flight_controls/landing_gear_down",type:"command"},gear_toggle:{gameCommand:"sim/flight_controls/landing_gear_toggle",type:"command"},flaps_up:{gameCommand:"sim/flight_controls/flaps_up",type:"command"},flaps_down:{gameCommand:"sim/flight_controls/flaps_down",type:"command"},flaps_full:{gameCommand:"sim/flight_controls/flaps_down",type:"command"},flaps_retract:{gameCommand:"sim/flight_controls/flaps_up",type:"command"},set_flaps:{gameCommand:"sim/cockpit2/controls/flap_ratio",type:"dataref"},spoilers_arm:{gameCommand:"sim/flight_controls/speed_brakes_down_one",type:"command"},spoilers_deploy:{gameCommand:"sim/flight_controls/speed_brakes_down_all",type:"command"},spoilers_retract:{gameCommand:"sim/flight_controls/speed_brakes_up_all",type:"command"},spoilers_toggle:{gameCommand:"sim/flight_controls/speed_brakes_toggle",type:"command"},parking_brake_toggle:{gameCommand:"sim/flight_controls/brakes_toggle_max",type:"command"},parking_brake_on:{gameCommand:"sim/flight_controls/brakes_max",type:"command"},parking_brake_off:{gameCommand:"sim/flight_controls/brakes_regular",type:"command"},set_throttle:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio_all",type:"dataref"},set_throttle_0:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[0]",type:"dataref"},set_throttle_1:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[1]",type:"dataref"},set_throttle_2:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[2]",type:"dataref"},set_throttle_3:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[3]",type:"dataref"},throttle_full:{gameCommand:"sim/engines/throttle_up",type:"command"},throttle_idle:{gameCommand:"sim/engines/throttle_down",type:"command"},throttle_cutoff:{gameCommand:"sim/starters/shut_down",type:"command"},landing_lights_on:{gameCommand:"sim/lights/landing_lights_on",type:"command"},landing_lights_off:{gameCommand:"sim/lights/landing_lights_off",type:"command"},landing_lights_toggle:{gameCommand:"sim/lights/landing_lights_toggle",type:"command"},taxi_lights_on:{gameCommand:"sim/lights/taxi_lights_on",type:"command"},taxi_lights_off:{gameCommand:"sim/lights/taxi_lights_off",type:"command"},taxi_lights_toggle:{gameCommand:"sim/lights/taxi_lights_toggle",type:"command"},beacon_lights_on:{gameCommand:"sim/lights/beacon_lights_on",type:"command"},beacon_lights_off:{gameCommand:"sim/lights/beacon_lights_off",type:"command"},beacon_lights_toggle:{gameCommand:"sim/lights/beacon_lights_toggle",type:"command"},nav_lights_on:{gameCommand:"sim/lights/nav_lights_on",type:"command"},nav_lights_off:{gameCommand:"sim/lights/nav_lights_off",type:"command"},nav_lights_toggle:{gameCommand:"sim/lights/nav_lights_toggle",type:"command"},strobe_lights_on:{gameCommand:"sim/lights/strobe_lights_on",type:"command"},strobe_lights_off:{gameCommand:"sim/lights/strobe_lights_off",type:"command"},strobe_lights_toggle:{gameCommand:"sim/lights/strobe_lights_toggle",type:"command"},pause:{gameCommand:"sim/operation/pause_on",type:"command"},unpause:{gameCommand:"sim/operation/pause_off",type:"command"},pause_toggle:{gameCommand:"sim/operation/pause_toggle",type:"command"}}};const C={msfs:{gameId:y.gameId,name:y.name,category:y.category,fieldMappings:y.fieldMappings,commandMappings:y.commandMappings,extraFields:{pitot_heat:{type:"boolean",description:"Pitot heat active",group:"Systems"},fuel_quantity_gallons:{type:"number",description:"Total fuel in gallons",unit:"gal",min:0,max:1e5,group:"Fuel"},fuel_flow_gph_1:{type:"number",description:"Engine 1 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},fuel_flow_gph_2:{type:"number",description:"Engine 2 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},fuel_flow_gph_3:{type:"number",description:"Engine 3 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},fuel_flow_gph_4:{type:"number",description:"Engine 4 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},flaps_left_percent:{type:"number",description:"Left flaps position",unit:"%",min:0,max:100,group:"Controls"},flaps_right_percent:{type:"number",description:"Right flaps position",unit:"%",min:0,max:100,group:"Controls"},spoilers_left_percent:{type:"number",description:"Left spoilers position",unit:"%",min:0,max:100,group:"Controls"},spoilers_right_percent:{type:"number",description:"Right spoilers position",unit:"%",min:0,max:100,group:"Controls"},gear_left_position:{type:"number",description:"Left gear position",unit:"%",min:0,max:100,group:"Controls"},gear_center_position:{type:"number",description:"Center gear position",unit:"%",min:0,max:100,group:"Controls"},gear_right_position:{type:"number",description:"Right gear position",unit:"%",min:0,max:100,group:"Controls"},ambient_pressure:{type:"number",description:"Ambient pressure",unit:"inHg",min:20,max:35,group:"Environment"},sea_level_pressure:{type:"number",description:"Sea level pressure",unit:"inHg",min:27,max:32,group:"Environment"},aircraft_wind_x:{type:"number",description:"Wind component X-axis",unit:"kts",min:-200,max:200,group:"Environment"},aircraft_wind_y:{type:"number",description:"Wind component Y-axis",unit:"kts",min:-200,max:200,group:"Environment"},aircraft_wind_z:{type:"number",description:"Wind component Z-axis",unit:"kts",min:-200,max:200,group:"Environment"}}},xplane:{gameId:b.gameId,name:b.name,category:b.category,fieldMappings:b.fieldMappings,commandMappings:b.commandMappings,extraFields:{replay_mode:{type:"boolean",description:"Replay mode active",group:"Simulation"},time_local:{type:"number",description:"Local time in seconds since midnight",unit:"sec",min:0,max:86400,group:"Simulation"},time_zulu:{type:"number",description:"Zulu time in seconds since midnight",unit:"sec",min:0,max:86400,group:"Simulation"}}}};function w(t){return C[t]}function k(t,e){const o={};for(const[n,i]of Object.entries(t)){const t=e.fieldMappings[n];if(t){let e=i;if(t.transform&&t.transform in d){e=(0,d[t.transform])(i)}o[t.canonical]=e}else e.extraFields?.[n]&&(o[`${e.gameId}:${n}`]=i)}return o}class T{constructor(t,e){this._config=e,this._socket=t,this._callbacks=[],this._fields=e.fields?[...e.fields]:null,this._gameSchema=w(e.gameId)}async establishConnection(){if(!this._socket||!this._config.userId||!this._config.gameId)throw new Error("Missing arguments in establishConnection");return new Promise(t=>{let e;e=this._fields?{userId:this._config.userId,gameId:this._config.gameId,fields:this._fields}:`${this._config.userId}:${this._config.gameId}`,this._socket.timeout(5e3).emit("listen",e,(e,o)=>e?t({status:"failed",reason:"Listen request timed out."}):"success"===o.status?t({status:"success"}):t({status:"failed",reason:o.reason}))})}setupEventListener(){return this._socket.on("update",t=>{const e=t?.data,o=e&&this._gameSchema?k(e,this._gameSchema):e;let n=o;if(this._fields&&this._fields.length>0&&o){n={};for(const t of this._fields)t in o&&(n[t]=o[t])}this.emit("update",{...t,raw:e,data:n})}),this._socket.on("key-events",t=>{const{gameId:e,eventType:o,data:n}=t||{};e===this._config.gameId&&o&&n&&this.emit(o,n)}),this}async subscribe(t){if(!Array.isArray(t)||0===t.length)throw new Error("fields must be a non-empty array");if(this._fields)for(const e of t)this._fields.includes(e)||this._fields.push(e);else this._fields=[...t];return this._updateSubscription()}async unsubscribe(t){if(!Array.isArray(t)||0===t.length)throw new Error("fields must be a non-empty array");if(!this._fields)throw new Error("Cannot unsubscribe when receiving all fields. Use subscribe() first to set explicit field list.");return this._fields=this._fields.filter(e=>!t.includes(e)),this._updateSubscription()}getFields(){return this._fields?[...this._fields]:null}async sendCommand(t,e){if(!t||"string"!=typeof t)throw new Error("command must be a non-empty string");return new Promise(o=>{const n={userId:this._config.userId,gameId:this._config.gameId,data:{fieldName:t,value:e}};this._socket.timeout(5e3).emit("set",n,(t,e)=>o(t?{status:"failed",reason:"Command request timed out."}:e))})}async _updateSubscription(){return new Promise(t=>{const e={userId:this._config.userId,gameId:this._config.gameId,fields:this._fields};this._socket.timeout(5e3).emit("listen-update",e,(e,o)=>t(e?{status:"failed",reason:"Update request timed out."}:o))})}}n(T.prototype);class E{constructor(t,e){this._config=e,this._socket=t,this._gameSchema=w(e.gameId),this._broadcasters=[]}async establishConnection(){if(!this._socket||!this._config.clientId||!this._config.gameId)throw new Error("Missing arguments in establishConnection");return new Promise(t=>{const e={clientId:this._config.clientId,gameId:this._config.gameId};this._socket.timeout(5e3).emit("presenceSubscribe",e,(e,o)=>{if(e)return t({status:"failed",reason:"Presence request timed out."});if("success"===o?.status){const e=Array.isArray(o.broadcasters)?o.broadcasters.map(t=>this._normalizeSnapshot(t)):[];return this._broadcasters=e,t({status:"success",broadcasters:e})}return t({status:"failed",reason:o?.reason||"Presence subscription failed."})})})}setupEventListener(){return this._socket.on("presence-update",t=>{const e=this._normalizeSnapshot(t);this._upsertBroadcaster(e),this.emit("update",e)}),this._socket.on("presence-remove",({userId:t})=>{t&&(this._broadcasters=this._broadcasters.filter(e=>e.userId!==t),this.emit("remove",{userId:t}))}),this._socket.on("connect",()=>{this.emit("connect")}),this._socket.on("disconnect",t=>{this.emit("disconnect",t)}),this}getBroadcasters(){return[...this._broadcasters]}disconnect(){this._socket&&this._socket.disconnect()}_normalizeSnapshot(t){if(!t||"object"!=typeof t)return t;const e=t.data,o=e&&this._gameSchema?k(e,this._gameSchema):e;return{...t,data:o,raw:e}}_upsertBroadcaster(t){if(!t||!t.userId)return;const e=this._broadcasters.findIndex(e=>e.userId===t.userId);if(e>=0){const o=[...this._broadcasters];return o[e]=t,void(this._broadcasters=o)}this._broadcasters=[...this._broadcasters,t]}}n(E.prototype);const A={msfs:!0,xplane:!0};class x extends _{constructor(t){super(t),this._socket=null,this._socketUrl=t.socketUrl||"https://socks.gameglue.gg",this._connectPromise=null}async createListener(t){if(!t)throw new Error("Not a valid listener config");if(!t.gameId||!A[t.gameId])throw new Error("Not a valid Game ID");if(!t.userId)throw new Error("User ID not supplied");if(t.fields&&!Array.isArray(t.fields))throw new Error("fields must be an array");await this._ensureConnected();const e=new T(this._socket,t),o=await e.establishConnection();if(this._socket.io.on("reconnect_attempt",()=>{this._updateSocketAuth(this.getAccessToken())}),this._socket.io.on("reconnect",()=>{e.establishConnection()}),"success"!==o.status)throw new Error(`There was a problem setting up the listener. Reason: ${o.reason}`);return e.setupEventListener()}async createPresenceListener(t){if(!t)throw new Error("Not a valid presence listener config");if(!t.gameId||!A[t.gameId])throw new Error("Not a valid Game ID");if(!t.clientId)throw new Error("Client ID not supplied");const e=o.io(this._socketUrl,{transports:["websocket"]});await new Promise((t,o)=>{e.on("connect",t),e.on("connect_error",t=>{m(t)&&p("WebSocket Connection",this._socketUrl),o(new Error(`Socket connection failed: ${t.message}`))})});const n=new E(e,t),i=await n.establishConnection();if(e.io.on("reconnect",()=>{n.establishConnection()}),"success"!==i.status)throw new Error(`There was a problem setting up the presence listener. Reason: ${i.reason}`);return n.setupEventListener()}async _ensureConnected(){if(!this._socket?.connected)if(this._connectPromise)await this._connectPromise;else{this._connectPromise=this._connect();try{await this._connectPromise}finally{this._connectPromise=null}}}_connect(){return new Promise((t,e)=>{const n=this.getAccessToken();n?(this._socket=o.io(this._socketUrl,{transports:["websocket"],auth:{token:n}}),this._socket.on("connect",()=>{t()}),this._socket.on("connect_error",t=>{m(t)&&p("WebSocket Connection",this._socketUrl),e(new Error(`Socket connection failed: ${t.message}`))}),this.onTokenRefreshed(t=>{this._updateSocketAuth(t)})):e(new Error("Not authenticated - call isAuthenticated() first"))})}_updateSocketAuth(t){this._socket&&(this._socket.auth.token=t)}}"undefined"!=typeof window&&(window.GameGlue=x,window.GameGlueSchemas={getGameSchema:w,getCategorySchema:f,normalizeTelemetry:k}),exports.GameGlue=x,exports.default=x,exports.getCategorySchema=f,exports.getGameSchema=w,exports.normalizeTelemetry=k;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("oidc-client-ts"),e=require("jwt-decode"),o=require("socket.io-client"),n=require("event-emitter");const i={},a=(t,e)=>l()?localStorage.setItem(t,e):i[t]=e,r=t=>l()?localStorage.getItem(t):i[t],s=t=>l()?localStorage.removeItem(t):delete i[t],l=()=>!("object"==typeof process&&"[object process]"===String(process));function m(t){if(!t)return!1;const e=(t.message||t.toString()||"").toLowerCase();return e.includes("cors")||e.includes("cross-origin")||e.includes("network error")||e.includes("failed to fetch")||e.includes("networkerror")||e.includes("load failed")||e.includes("xhr poll error")||e.includes("websocket error")||e.includes("transport")&&e.includes("error")}function p(t,e){console.error(`\n╔══════════════════════════════════════════════════════════════════════════════╗\n║ GameGlue SDK: Possible CORS Error Detected ║\n╠══════════════════════════════════════════════════════════════════════════════╣\n║ Context: ${t.padEnd(66)}║\n║ URL: ${(e||"unknown").substring(0,70).padEnd(70)}║\n╠══════════════════════════════════════════════════════════════════════════════╣\n║ This error typically means the server rejected the request due to CORS. ║\n║ ║\n║ To fix this, add your origin to your app's allowed Web Origins: ║\n║ ║\n║ 1. Go to the GameGlue Developer Portal (https://developer.gameglue.gg) ║\n║ 2. Select your app ║\n║ 3. Add your origin to "Web Origins" and save ║\n║ ║\n║ IMPORTANT: Protocol and port must match exactly. ║\n║ http://localhost:3000 and https://localhost:3000 are different origins. ║\n║ http://localhost:3000 and http://localhost:5000 are different origins. ║\n╚══════════════════════════════════════════════════════════════════════════════╝\n`)}let c=null;class _{constructor(e){const o=e.authUrl||"https://auth.gameglue.gg/realms/GameGlue";this._oidcSettings={authority:o,client_id:e.clientId,redirect_uri:g(e.redirect_uri||window.location.href),post_logout_redirect_uri:g(window.location.href),response_type:"code",scope:`openid ${(e.scopes||[]).join(" ")}`,response_mode:"fragment",filterProtocolClaims:!0},this._oidcClient=new t.OidcClient(this._oidcSettings),this._refreshCallback=()=>{},this._refreshTimeout=null}async isAuthenticated(){return this._hasCallbackParams()&&await this._processCallback(),this._hasValidTokens()}login(){this._oidcClient.createSigninRequest({state:{bar:15}}).then(t=>{window.location=t.url}).catch(t=>{m(t)&&p("Login Request",this._oidcSettings.authority),console.error("Failed to create signin request:",t)})}logout(t={}){if(s("gg-auth-token"),s("gg-refresh-token"),clearTimeout(this._refreshTimeout),!1!==t.redirect){const t=`${this._oidcSettings.authority}/protocol/openid-connect/logout?post_logout_redirect_uri=${encodeURIComponent(this._oidcSettings.post_logout_redirect_uri)}`;window.location.href=t}}getUser(){const t=this._getAccessToken();if(!t)throw new Error("Not authenticated");return e(t).sub}getAccessToken(){return this._getAccessToken()}onTokenRefreshed(t){this._refreshCallback=t}_hasCallbackParams(){return location.hash.includes("state=")&&(location.hash.includes("code=")||location.hash.includes("error="))}_clearCallbackUrl(){window.history.replaceState("",document.title,window.location.pathname+window.location.search)}async _processCallback(){if(c)await c;else{c=this._doProcessCallback();try{await c}finally{c=null}}}async _doProcessCallback(){try{const t=await this._oidcClient.processSigninResponse(window.location.href);if(t.error)throw this._clearCallbackUrl(),new Error(t.error);if(!t.access_token)throw this._clearCallbackUrl(),new Error("No access token received");this._setAccessToken(t.access_token),this._setRefreshToken(t.refresh_token),this._clearCallbackUrl()}catch(t){if(this._hasValidTokens())return void this._clearCallbackUrl();throw this._clearCallbackUrl(),t}}_hasValidTokens(){const t=this._getAccessToken();if(!t)return!1;try{const o=e(t);return new Date(1e3*o.exp)>new Date}catch{return!1}}_getAccessToken(){const t=r("gg-auth-token");return t&&this._setTokenRefreshTimeout(t),t||void 0}_setAccessToken(t){return this._setTokenRefreshTimeout(t),a("gg-auth-token",t)}_setRefreshToken(t){return a("gg-refresh-token",t)}_getRefreshToken(){return r("gg-refresh-token")}_setTokenRefreshTimeout(t){if(t){clearTimeout(this._refreshTimeout);try{const o=1e3*e(t).exp-Date.now()-5e3;o>0&&(this._refreshTimeout=setTimeout(()=>{this._attemptRefresh()},o))}catch{}}}async _attemptRefresh(){const t=`${this._oidcSettings.authority}/protocol/openid-connect/token`,e=this._oidcSettings.client_id,o=this._getRefreshToken();try{const n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,grant_type:"refresh_token",refresh_token:o})});if(200===n.status){const t=await n.json();this._setAccessToken(t.access_token),this._setRefreshToken(t.refresh_token),this._refreshCallback(t.access_token)}}catch(e){m(e)&&p("Token Refresh",t),console.error("Token refresh failed:",e)}}}function g(t){return t.endsWith("/")?t.replace(/\/+$/,""):t}const d={radiansToDegrees:t=>t*(180/Math.PI),degreesToRadians:t=>t*(Math.PI/180),metersToFeet:t=>3.28084*t,feetToMeters:t=>t/3.28084,msToKnots:t=>1.94384*t,knotsToMs:t=>t/1.94384,msToFpm:t=>196.85*t,toBoolean:t=>Boolean(t),divideBy100:t=>t/100},u={category:"flight_sim",name:"Flight Simulator",description:"Canonical telemetry fields for flight simulation games",recommendedUpdateRateHz:10,requiredFields:["latitude","longitude","altitude","indicated_airspeed","heading","vertical_speed","on_ground"],fields:{latitude:{type:"number",description:"Aircraft latitude",unit:"degrees",min:-90,max:90,group:"Position"},longitude:{type:"number",description:"Aircraft longitude",unit:"degrees",min:-180,max:180,group:"Position"},altitude:{type:"number",description:"Aircraft altitude above sea level",unit:"ft",min:-2e3,max:1e5,group:"Position"},altitude_agl:{type:"number",description:"Aircraft altitude above ground level",unit:"ft",min:0,max:1e5,group:"Position"},on_ground:{type:"boolean",description:"Whether aircraft is on the ground",group:"Position"},indicated_airspeed:{type:"number",description:"Indicated airspeed",unit:"kts",min:0,max:1e3,group:"Velocity"},true_airspeed:{type:"number",description:"True airspeed",unit:"kts",min:0,max:1e3,group:"Velocity"},ground_speed:{type:"number",description:"Ground speed",unit:"kts",min:0,max:1e3,group:"Velocity"},mach:{type:"number",description:"Mach number",min:0,max:5,group:"Velocity"},vertical_speed:{type:"number",description:"Vertical speed",unit:"ft/min",min:-2e4,max:2e4,group:"Velocity"},g_force:{type:"number",description:"Current G-force",unit:"G",min:-10,max:10,group:"Velocity"},heading:{type:"number",description:"Aircraft magnetic heading",unit:"degrees",min:0,max:360,group:"Attitude"},true_heading:{type:"number",description:"Aircraft true heading",unit:"degrees",min:0,max:360,group:"Attitude"},pitch:{type:"number",description:"Aircraft pitch angle",unit:"degrees",min:-90,max:90,group:"Attitude"},roll:{type:"number",description:"Aircraft roll/bank angle",unit:"degrees",min:-180,max:180,group:"Attitude"},yaw:{type:"number",description:"Aircraft yaw angle",unit:"degrees",min:-180,max:180,group:"Attitude"},throttle_0:{type:"number",description:"Engine 0 throttle position",unit:"%",min:0,max:100,group:"Engine"},throttle_1:{type:"number",description:"Engine 1 throttle position",unit:"%",min:0,max:100,group:"Engine"},throttle_2:{type:"number",description:"Engine 2 throttle position",unit:"%",min:0,max:100,group:"Engine"},throttle_3:{type:"number",description:"Engine 3 throttle position",unit:"%",min:0,max:100,group:"Engine"},rpm_0:{type:"number",description:"Engine 0 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},rpm_1:{type:"number",description:"Engine 1 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},rpm_2:{type:"number",description:"Engine 2 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},rpm_3:{type:"number",description:"Engine 3 RPM",unit:"RPM",min:0,max:1e4,group:"Engine"},n1_0:{type:"number",description:"Engine 0 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n1_1:{type:"number",description:"Engine 1 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n1_2:{type:"number",description:"Engine 2 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n1_3:{type:"number",description:"Engine 3 N1 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_0:{type:"number",description:"Engine 0 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_1:{type:"number",description:"Engine 1 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_2:{type:"number",description:"Engine 2 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},n2_3:{type:"number",description:"Engine 3 N2 (turbine)",unit:"%",min:0,max:120,group:"Engine"},egt_0:{type:"number",description:"Engine 0 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},egt_1:{type:"number",description:"Engine 1 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},egt_2:{type:"number",description:"Engine 2 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},egt_3:{type:"number",description:"Engine 3 exhaust gas temperature",unit:"°C",min:0,max:1200,group:"Engine"},fuel_quantity:{type:"number",description:"Total fuel quantity",unit:"lbs",min:0,max:6e5,group:"Fuel"},fuel_flow_0:{type:"number",description:"Engine 0 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},fuel_flow_1:{type:"number",description:"Engine 1 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},fuel_flow_2:{type:"number",description:"Engine 2 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},fuel_flow_3:{type:"number",description:"Engine 3 fuel flow",unit:"lbs/hr",min:0,max:3e4,group:"Fuel"},autopilot_master:{type:"boolean",description:"Autopilot master engaged",group:"Autopilot"},autopilot_altitude_hold:{type:"boolean",description:"Altitude hold engaged",group:"Autopilot"},autopilot_heading_hold:{type:"boolean",description:"Heading hold engaged",group:"Autopilot"},autopilot_vs_hold:{type:"boolean",description:"Vertical speed hold engaged",group:"Autopilot"},autopilot_speed_hold:{type:"boolean",description:"Speed hold engaged",group:"Autopilot"},autopilot_approach:{type:"boolean",description:"Approach mode engaged",group:"Autopilot"},autopilot_nav:{type:"boolean",description:"NAV mode engaged",group:"Autopilot"},flight_director:{type:"boolean",description:"Flight director active",group:"Autopilot"},autopilot_flc:{type:"boolean",description:"Flight level change mode engaged",group:"Autopilot"},autopilot_altitude_target:{type:"number",description:"Autopilot target altitude",unit:"ft",min:0,max:6e4,group:"Autopilot"},autopilot_heading_target:{type:"number",description:"Autopilot target heading",unit:"degrees",min:0,max:360,group:"Autopilot"},autopilot_vs_target:{type:"number",description:"Autopilot target vertical speed",unit:"ft/min",min:-1e4,max:1e4,group:"Autopilot"},autopilot_speed_target:{type:"number",description:"Autopilot target airspeed",unit:"kts",min:0,max:600,group:"Autopilot"},flaps:{type:"number",description:"Flaps position",unit:"%",min:0,max:100,group:"Controls"},spoilers:{type:"number",description:"Spoilers position",unit:"%",min:0,max:100,group:"Controls"},gear_down:{type:"boolean",description:"Landing gear extended",group:"Controls"},parking_brake:{type:"boolean",description:"Parking brake engaged",group:"Controls"},brake_left:{type:"number",description:"Left brake position",unit:"%",min:0,max:100,group:"Controls"},brake_right:{type:"number",description:"Right brake position",unit:"%",min:0,max:100,group:"Controls"},light_landing:{type:"boolean",description:"Landing lights on",group:"Lights"},light_taxi:{type:"boolean",description:"Taxi lights on",group:"Lights"},light_beacon:{type:"boolean",description:"Beacon lights on",group:"Lights"},light_nav:{type:"boolean",description:"Navigation lights on",group:"Lights"},light_strobe:{type:"boolean",description:"Strobe lights on",group:"Lights"},outside_air_temp:{type:"number",description:"Outside air temperature",unit:"°C",min:-80,max:60,group:"Environment"},barometric_pressure:{type:"number",description:"Barometric pressure setting",unit:"inHg",min:27,max:32,group:"Environment"},wind_direction:{type:"number",description:"Wind direction",unit:"degrees",min:0,max:360,group:"Environment"},wind_speed:{type:"number",description:"Wind speed",unit:"kts",min:0,max:200,group:"Environment"},stall_warning:{type:"boolean",description:"Stall warning active",group:"Warnings"},overspeed_warning:{type:"boolean",description:"Overspeed warning active",group:"Warnings"},sim_paused:{type:"boolean",description:"Simulation is paused",group:"Simulation"},gps_wp_distance:{type:"number",description:"Distance to next GPS waypoint",unit:"nm",min:0,max:1e4,group:"Navigation"},gps_wp_ete:{type:"number",description:"Estimated time enroute to next GPS waypoint",unit:"seconds",min:0,max:86400,group:"Navigation"}},commands:{autopilot_on:{description:"Engage autopilot master",group:"Autopilot"},autopilot_off:{description:"Disengage autopilot master",group:"Autopilot"},autopilot_toggle:{description:"Toggle autopilot master",group:"Autopilot"},autopilot_altitude_hold_on:{description:"Engage altitude hold",group:"Autopilot"},autopilot_altitude_hold_off:{description:"Disengage altitude hold",group:"Autopilot"},autopilot_heading_hold_on:{description:"Engage heading hold",group:"Autopilot"},autopilot_heading_hold_off:{description:"Disengage heading hold",group:"Autopilot"},autopilot_vs_hold_on:{description:"Engage vertical speed hold",group:"Autopilot"},autopilot_vs_hold_off:{description:"Disengage vertical speed hold",group:"Autopilot"},autopilot_nav_on:{description:"Engage NAV mode",group:"Autopilot"},autopilot_nav_off:{description:"Disengage NAV mode",group:"Autopilot"},autopilot_approach_on:{description:"Engage approach mode",group:"Autopilot"},autopilot_approach_off:{description:"Disengage approach mode",group:"Autopilot"},flight_director_on:{description:"Engage flight director",group:"Autopilot"},flight_director_off:{description:"Disengage flight director",group:"Autopilot"},autopilot_flc_on:{description:"Engage flight level change mode",group:"Autopilot"},autopilot_flc_off:{description:"Disengage flight level change mode",group:"Autopilot"},autopilot_flc_toggle:{description:"Toggle flight level change mode",group:"Autopilot"},set_autopilot_altitude:{description:"Set autopilot target altitude",group:"Autopilot",paramType:"number",paramDescription:"Target altitude in feet",paramMin:0,paramMax:6e4},set_autopilot_heading:{description:"Set autopilot target heading",group:"Autopilot",paramType:"number",paramDescription:"Target heading in degrees",paramMin:0,paramMax:360},set_autopilot_vs:{description:"Set autopilot target vertical speed",group:"Autopilot",paramType:"number",paramDescription:"Target vertical speed in ft/min",paramMin:-1e4,paramMax:1e4},set_autopilot_speed:{description:"Set autopilot target airspeed",group:"Autopilot",paramType:"number",paramDescription:"Target airspeed in knots",paramMin:0,paramMax:600},gear_up:{description:"Retract landing gear",group:"Controls"},gear_down:{description:"Extend landing gear",group:"Controls"},gear_toggle:{description:"Toggle landing gear",group:"Controls"},flaps_up:{description:"Retract flaps one notch",group:"Controls"},flaps_down:{description:"Extend flaps one notch",group:"Controls"},flaps_full:{description:"Extend flaps fully",group:"Controls"},flaps_retract:{description:"Fully retract flaps",group:"Controls"},set_flaps:{description:"Set flaps to specific position",group:"Controls",paramType:"number",paramDescription:"Flaps position (0-100%)",paramMin:0,paramMax:100},spoilers_arm:{description:"Arm spoilers",group:"Controls"},spoilers_deploy:{description:"Deploy spoilers",group:"Controls"},spoilers_retract:{description:"Retract spoilers",group:"Controls"},spoilers_toggle:{description:"Toggle spoilers",group:"Controls"},parking_brake_toggle:{description:"Toggle parking brake",group:"Controls"},parking_brake_on:{description:"Engage parking brake",group:"Controls"},parking_brake_off:{description:"Release parking brake",group:"Controls"},set_throttle:{description:"Set all throttles",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_0:{description:"Set engine 0 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_1:{description:"Set engine 1 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_2:{description:"Set engine 2 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},set_throttle_3:{description:"Set engine 3 throttle",group:"Engine",paramType:"number",paramDescription:"Throttle position (0-100%)",paramMin:0,paramMax:100},throttle_full:{description:"Set throttles to full",group:"Engine"},throttle_idle:{description:"Set throttles to idle",group:"Engine"},throttle_cutoff:{description:"Cut throttles completely",group:"Engine"},landing_lights_on:{description:"Turn on landing lights",group:"Lights"},landing_lights_off:{description:"Turn off landing lights",group:"Lights"},landing_lights_toggle:{description:"Toggle landing lights",group:"Lights"},taxi_lights_on:{description:"Turn on taxi lights",group:"Lights"},taxi_lights_off:{description:"Turn off taxi lights",group:"Lights"},taxi_lights_toggle:{description:"Toggle taxi lights",group:"Lights"},beacon_lights_on:{description:"Turn on beacon lights",group:"Lights"},beacon_lights_off:{description:"Turn off beacon lights",group:"Lights"},beacon_lights_toggle:{description:"Toggle beacon lights",group:"Lights"},nav_lights_on:{description:"Turn on navigation lights",group:"Lights"},nav_lights_off:{description:"Turn off navigation lights",group:"Lights"},nav_lights_toggle:{description:"Toggle navigation lights",group:"Lights"},strobe_lights_on:{description:"Turn on strobe lights",group:"Lights"},strobe_lights_off:{description:"Turn off strobe lights",group:"Lights"},strobe_lights_toggle:{description:"Toggle strobe lights",group:"Lights"},pause:{description:"Pause simulation",group:"Simulation"},unpause:{description:"Unpause simulation",group:"Simulation"},pause_toggle:{description:"Toggle simulation pause",group:"Simulation"}}},h={flight_sim:u,racing_sim:u};function f(t){return h[t]}var y={gameId:"msfs",name:"Microsoft Flight Simulator",category:"flight_sim",fieldMappings:{latitude:{canonical:"latitude"},longitude:{canonical:"longitude"},indicated_altitude:{canonical:"altitude"},plane_altitude:{canonical:"altitude"},on_ground:{canonical:"on_ground",transform:"toBoolean"},altitude_agl:{canonical:"altitude_agl"},indicated_airspeed:{canonical:"indicated_airspeed"},true_airspeed:{canonical:"true_airspeed"},airspeed_mach:{canonical:"mach"},airspeed_indicated:{canonical:"indicated_airspeed"},ground_speed:{canonical:"ground_speed"},ground_velocity:{canonical:"ground_speed"},vertical_speed:{canonical:"vertical_speed"},gforce:{canonical:"g_force"},heading_gyro:{canonical:"heading"},heading_indicator:{canonical:"heading"},true_heading:{canonical:"true_heading"},attitude_indicator_pitch:{canonical:"pitch"},attitude_indicator_roll:{canonical:"roll"},yaw_rate:{canonical:"yaw"},eng_throttle_1:{canonical:"throttle_0",transform:"divideBy100"},eng_throttle_2:{canonical:"throttle_1",transform:"divideBy100"},eng_throttle_3:{canonical:"throttle_2",transform:"divideBy100"},eng_throttle_4:{canonical:"throttle_3",transform:"divideBy100"},eng_rpm_1:{canonical:"rpm_0"},eng_rpm_2:{canonical:"rpm_1"},eng_rpm_3:{canonical:"rpm_2"},eng_rpm_4:{canonical:"rpm_3"},turb_eng_n1_1:{canonical:"n1_0"},turb_eng_n1_2:{canonical:"n1_1"},turb_eng_n1_3:{canonical:"n1_2"},turb_eng_n1_4:{canonical:"n1_3"},turb_eng_n2_1:{canonical:"n2_0"},turb_eng_n2_2:{canonical:"n2_1"},turb_eng_n2_3:{canonical:"n2_2"},turb_eng_n2_4:{canonical:"n2_3"},turb_eng_itt_1:{canonical:"egt_0"},turb_eng_itt_2:{canonical:"egt_1"},turb_eng_itt_3:{canonical:"egt_2"},turb_eng_itt_4:{canonical:"egt_3"},fuel_quantity_pounds:{canonical:"fuel_quantity"},fuel_flow_pph_1:{canonical:"fuel_flow_0"},fuel_flow_pph_2:{canonical:"fuel_flow_1"},fuel_flow_pph_3:{canonical:"fuel_flow_2"},fuel_flow_pph_4:{canonical:"fuel_flow_3"},autopilot_master:{canonical:"autopilot_master",transform:"toBoolean"},autopilot_altitude_lock:{canonical:"autopilot_altitude_hold",transform:"toBoolean"},autopilot_heading_lock:{canonical:"autopilot_heading_hold",transform:"toBoolean"},autopilot_vertical_hold:{canonical:"autopilot_vs_hold",transform:"toBoolean"},autopilot_airspeed_hold:{canonical:"autopilot_speed_hold",transform:"toBoolean"},autopilot_approach_hold:{canonical:"autopilot_approach",transform:"toBoolean"},autopilot_nav1_lock:{canonical:"autopilot_nav",transform:"toBoolean"},autopilot_flight_director:{canonical:"flight_director",transform:"toBoolean"},autopilot_flc:{canonical:"autopilot_flc",transform:"toBoolean"},autopilot_altitude_set:{canonical:"autopilot_altitude_target"},autopilot_heading_set:{canonical:"autopilot_heading_target"},autopilot_vertical_speed_set:{canonical:"autopilot_vs_target"},autopilot_airspeed_set:{canonical:"autopilot_speed_target"},flaps_handle_percent:{canonical:"flaps"},spoilers_handle_percent:{canonical:"spoilers"},gear_handle_position:{canonical:"gear_down",transform:"toBoolean"},parking_brake:{canonical:"parking_brake",transform:"toBoolean"},brake_left_position:{canonical:"brake_left"},brake_right_position:{canonical:"brake_right"},light_landing:{canonical:"light_landing",transform:"toBoolean"},light_taxi:{canonical:"light_taxi",transform:"toBoolean"},light_beacon:{canonical:"light_beacon",transform:"toBoolean"},light_nav:{canonical:"light_nav",transform:"toBoolean"},light_strobe:{canonical:"light_strobe",transform:"toBoolean"},ambient_temperature:{canonical:"outside_air_temp"},kohlsman_setting_hg:{canonical:"barometric_pressure"},ambient_wind_direction:{canonical:"wind_direction"},ambient_wind_velocity:{canonical:"wind_speed"},stall_warning:{canonical:"stall_warning",transform:"toBoolean"},overspeed_warning:{canonical:"overspeed_warning",transform:"toBoolean"},sim_paused:{canonical:"sim_paused",transform:"toBoolean"},gps_wp_distance:{canonical:"gps_wp_distance"},gps_wp_ete:{canonical:"gps_wp_ete"}},commandMappings:{autopilot_on:{gameCommand:"AP_MASTER_ON",type:"command"},autopilot_off:{gameCommand:"AP_MASTER_OFF",type:"command"},autopilot_toggle:{gameCommand:"AP_MASTER",type:"command"},autopilot_altitude_hold_on:{gameCommand:"AP_ALT_HOLD_ON",type:"command"},autopilot_altitude_hold_off:{gameCommand:"AP_ALT_HOLD_OFF",type:"command"},autopilot_heading_hold_on:{gameCommand:"AP_HDG_HOLD_ON",type:"command"},autopilot_heading_hold_off:{gameCommand:"AP_HDG_HOLD_OFF",type:"command"},autopilot_vs_hold_on:{gameCommand:"AP_VS_HOLD_ON",type:"command"},autopilot_vs_hold_off:{gameCommand:"AP_VS_HOLD_OFF",type:"command"},autopilot_nav_on:{gameCommand:"AP_NAV1_HOLD_ON",type:"command"},autopilot_nav_off:{gameCommand:"AP_NAV1_HOLD_OFF",type:"command"},autopilot_approach_on:{gameCommand:"AP_APR_HOLD_ON",type:"command"},autopilot_approach_off:{gameCommand:"AP_APR_HOLD_OFF",type:"command"},flight_director_on:{gameCommand:"TOGGLE_FLIGHT_DIRECTOR",type:"command"},flight_director_off:{gameCommand:"TOGGLE_FLIGHT_DIRECTOR",type:"command"},autopilot_flc_on:{gameCommand:"FLIGHT_LEVEL_CHANGE_ON",type:"command"},autopilot_flc_off:{gameCommand:"FLIGHT_LEVEL_CHANGE_OFF",type:"command"},autopilot_flc_toggle:{gameCommand:"FLIGHT_LEVEL_CHANGE",type:"command"},set_autopilot_altitude:{gameCommand:"AP_ALT_VAR_SET_ENGLISH",type:"command"},set_autopilot_heading:{gameCommand:"HEADING_BUG_SET",type:"command"},set_autopilot_vs:{gameCommand:"AP_VS_VAR_SET_ENGLISH",type:"command"},set_autopilot_speed:{gameCommand:"AP_SPD_VAR_SET",type:"command"},gear_up:{gameCommand:"GEAR_UP",type:"command"},gear_down:{gameCommand:"GEAR_DOWN",type:"command"},gear_toggle:{gameCommand:"GEAR_TOGGLE",type:"command"},flaps_up:{gameCommand:"FLAPS_DECR",type:"command"},flaps_down:{gameCommand:"FLAPS_INCR",type:"command"},flaps_full:{gameCommand:"FLAPS_DOWN",type:"command"},flaps_retract:{gameCommand:"FLAPS_UP",type:"command"},set_flaps:{gameCommand:"FLAPS_SET",type:"command"},spoilers_arm:{gameCommand:"SPOILERS_ARM_TOGGLE",type:"command"},spoilers_deploy:{gameCommand:"SPOILERS_ON",type:"command"},spoilers_retract:{gameCommand:"SPOILERS_OFF",type:"command"},spoilers_toggle:{gameCommand:"SPOILERS_TOGGLE",type:"command"},parking_brake_toggle:{gameCommand:"PARKING_BRAKES",type:"command"},parking_brake_on:{gameCommand:"PARKING_BRAKE_SET",type:"command"},parking_brake_off:{gameCommand:"PARKING_BRAKE_SET",type:"command"},set_throttle:{gameCommand:"THROTTLE_SET",type:"command"},set_throttle_0:{gameCommand:"THROTTLE1_SET",type:"command"},set_throttle_1:{gameCommand:"THROTTLE2_SET",type:"command"},set_throttle_2:{gameCommand:"THROTTLE3_SET",type:"command"},set_throttle_3:{gameCommand:"THROTTLE4_SET",type:"command"},throttle_full:{gameCommand:"THROTTLE_FULL",type:"command"},throttle_idle:{gameCommand:"THROTTLE_CUT",type:"command"},throttle_cutoff:{gameCommand:"THROTTLE_CUT",type:"command"},landing_lights_on:{gameCommand:"LANDING_LIGHTS_ON",type:"command"},landing_lights_off:{gameCommand:"LANDING_LIGHTS_OFF",type:"command"},landing_lights_toggle:{gameCommand:"LANDING_LIGHTS_TOGGLE",type:"command"},taxi_lights_on:{gameCommand:"TAXI_LIGHTS_ON",type:"command"},taxi_lights_off:{gameCommand:"TAXI_LIGHTS_OFF",type:"command"},taxi_lights_toggle:{gameCommand:"TAXI_LIGHTS_TOGGLE",type:"command"},beacon_lights_on:{gameCommand:"BEACON_LIGHTS_ON",type:"command"},beacon_lights_off:{gameCommand:"BEACON_LIGHTS_OFF",type:"command"},beacon_lights_toggle:{gameCommand:"BEACON_LIGHTS_TOGGLE",type:"command"},nav_lights_on:{gameCommand:"NAV_LIGHTS_ON",type:"command"},nav_lights_off:{gameCommand:"NAV_LIGHTS_OFF",type:"command"},nav_lights_toggle:{gameCommand:"NAV_LIGHTS_TOGGLE",type:"command"},strobe_lights_on:{gameCommand:"STROBES_ON",type:"command"},strobe_lights_off:{gameCommand:"STROBES_OFF",type:"command"},strobe_lights_toggle:{gameCommand:"STROBES_TOGGLE",type:"command"},pause:{gameCommand:"PAUSE_ON",type:"command"},unpause:{gameCommand:"PAUSE_OFF",type:"command"},pause_toggle:{gameCommand:"PAUSE_TOGGLE",type:"command"}}};var b={gameId:"xplane",name:"X-Plane 12",category:"flight_sim",fieldMappings:{lat:{canonical:"latitude"},lon:{canonical:"longitude"},alt_msl:{canonical:"altitude"},alt_agl:{canonical:"altitude_agl"},on_ground:{canonical:"on_ground",transform:"toBoolean"},ias:{canonical:"indicated_airspeed"},tas:{canonical:"true_airspeed"},gs:{canonical:"ground_speed"},mach:{canonical:"mach"},vvi:{canonical:"vertical_speed"},g_load:{canonical:"g_force"},hdg_mag:{canonical:"heading"},hdg_true:{canonical:"true_heading"},pitch:{canonical:"pitch"},roll:{canonical:"roll"},yaw:{canonical:"yaw"},throttle_0:{canonical:"throttle_0"},throttle_1:{canonical:"throttle_1"},throttle_2:{canonical:"throttle_2"},throttle_3:{canonical:"throttle_3"},rpm_0:{canonical:"rpm_0"},rpm_1:{canonical:"rpm_1"},rpm_2:{canonical:"rpm_2"},rpm_3:{canonical:"rpm_3"},n1_0:{canonical:"n1_0"},n1_1:{canonical:"n1_1"},n1_2:{canonical:"n1_2"},n1_3:{canonical:"n1_3"},n2_0:{canonical:"n2_0"},n2_1:{canonical:"n2_1"},n2_2:{canonical:"n2_2"},n2_3:{canonical:"n2_3"},egt_0:{canonical:"egt_0"},egt_1:{canonical:"egt_1"},egt_2:{canonical:"egt_2"},egt_3:{canonical:"egt_3"},fuel_total_lbs:{canonical:"fuel_quantity"},ff_0:{canonical:"fuel_flow_0"},ff_1:{canonical:"fuel_flow_1"},ff_2:{canonical:"fuel_flow_2"},ff_3:{canonical:"fuel_flow_3"},ap_master:{canonical:"autopilot_master",transform:"toBoolean"},ap_alt_hold:{canonical:"autopilot_altitude_hold",transform:"toBoolean"},ap_hdg_hold:{canonical:"autopilot_heading_hold",transform:"toBoolean"},ap_vs_hold:{canonical:"autopilot_vs_hold",transform:"toBoolean"},ap_spd_hold:{canonical:"autopilot_speed_hold",transform:"toBoolean"},ap_apr:{canonical:"autopilot_approach",transform:"toBoolean"},ap_nav:{canonical:"autopilot_nav",transform:"toBoolean"},fd_on:{canonical:"flight_director",transform:"toBoolean"},ap_alt_set:{canonical:"autopilot_altitude_target"},ap_hdg_set:{canonical:"autopilot_heading_target"},ap_vs_set:{canonical:"autopilot_vs_target"},ap_spd_set:{canonical:"autopilot_speed_target"},flap_ratio:{canonical:"flaps"},spoiler_ratio:{canonical:"spoilers"},gear_deploy:{canonical:"gear_down",transform:"toBoolean"},park_brake:{canonical:"parking_brake",transform:"toBoolean"},brake_left:{canonical:"brake_left"},brake_right:{canonical:"brake_right"},land_lights:{canonical:"light_landing",transform:"toBoolean"},taxi_lights:{canonical:"light_taxi",transform:"toBoolean"},beacon:{canonical:"light_beacon",transform:"toBoolean"},nav_lights:{canonical:"light_nav",transform:"toBoolean"},strobe:{canonical:"light_strobe",transform:"toBoolean"},oat:{canonical:"outside_air_temp"},baro_set:{canonical:"barometric_pressure"},wind_dir:{canonical:"wind_direction"},wind_spd:{canonical:"wind_speed"},stall:{canonical:"stall_warning",transform:"toBoolean"},overspeed:{canonical:"overspeed_warning",transform:"toBoolean"},paused:{canonical:"sim_paused",transform:"toBoolean"},gps_wp_distance:{canonical:"gps_wp_distance"},gps_wp_ete:{canonical:"gps_wp_ete"}},commandMappings:{autopilot_on:{gameCommand:"sim/autopilot/servos_on",type:"command"},autopilot_off:{gameCommand:"sim/autopilot/servos_off_any",type:"command"},autopilot_toggle:{gameCommand:"sim/autopilot/servos_toggle",type:"command"},autopilot_altitude_hold_on:{gameCommand:"sim/autopilot/altitude_hold",type:"command"},autopilot_altitude_hold_off:{gameCommand:"sim/autopilot/altitude_hold",type:"command"},autopilot_heading_hold_on:{gameCommand:"sim/autopilot/heading",type:"command"},autopilot_heading_hold_off:{gameCommand:"sim/autopilot/heading",type:"command"},autopilot_vs_hold_on:{gameCommand:"sim/autopilot/vertical_speed",type:"command"},autopilot_vs_hold_off:{gameCommand:"sim/autopilot/vertical_speed",type:"command"},autopilot_nav_on:{gameCommand:"sim/autopilot/NAV",type:"command"},autopilot_nav_off:{gameCommand:"sim/autopilot/NAV",type:"command"},autopilot_approach_on:{gameCommand:"sim/autopilot/approach",type:"command"},autopilot_approach_off:{gameCommand:"sim/autopilot/approach",type:"command"},flight_director_on:{gameCommand:"sim/autopilot/fdir_on",type:"command"},flight_director_off:{gameCommand:"sim/autopilot/fdir_toggle",type:"command"},autopilot_flc_on:{gameCommand:"sim/autopilot/level_change",type:"command"},autopilot_flc_off:{gameCommand:"sim/autopilot/level_change",type:"command"},autopilot_flc_toggle:{gameCommand:"sim/autopilot/level_change",type:"command"},set_autopilot_altitude:{gameCommand:"sim/cockpit/autopilot/altitude",type:"dataref"},set_autopilot_heading:{gameCommand:"sim/cockpit/autopilot/heading_mag",type:"dataref"},set_autopilot_vs:{gameCommand:"sim/cockpit/autopilot/vertical_velocity",type:"dataref"},set_autopilot_speed:{gameCommand:"sim/cockpit/autopilot/airspeed",type:"dataref"},gear_up:{gameCommand:"sim/flight_controls/landing_gear_up",type:"command"},gear_down:{gameCommand:"sim/flight_controls/landing_gear_down",type:"command"},gear_toggle:{gameCommand:"sim/flight_controls/landing_gear_toggle",type:"command"},flaps_up:{gameCommand:"sim/flight_controls/flaps_up",type:"command"},flaps_down:{gameCommand:"sim/flight_controls/flaps_down",type:"command"},flaps_full:{gameCommand:"sim/flight_controls/flaps_down",type:"command"},flaps_retract:{gameCommand:"sim/flight_controls/flaps_up",type:"command"},set_flaps:{gameCommand:"sim/cockpit2/controls/flap_ratio",type:"dataref"},spoilers_arm:{gameCommand:"sim/flight_controls/speed_brakes_down_one",type:"command"},spoilers_deploy:{gameCommand:"sim/flight_controls/speed_brakes_down_all",type:"command"},spoilers_retract:{gameCommand:"sim/flight_controls/speed_brakes_up_all",type:"command"},spoilers_toggle:{gameCommand:"sim/flight_controls/speed_brakes_toggle",type:"command"},parking_brake_toggle:{gameCommand:"sim/flight_controls/brakes_toggle_max",type:"command"},parking_brake_on:{gameCommand:"sim/flight_controls/brakes_max",type:"command"},parking_brake_off:{gameCommand:"sim/flight_controls/brakes_regular",type:"command"},set_throttle:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio_all",type:"dataref"},set_throttle_0:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[0]",type:"dataref"},set_throttle_1:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[1]",type:"dataref"},set_throttle_2:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[2]",type:"dataref"},set_throttle_3:{gameCommand:"sim/cockpit2/engine/actuators/throttle_ratio[3]",type:"dataref"},throttle_full:{gameCommand:"sim/engines/throttle_up",type:"command"},throttle_idle:{gameCommand:"sim/engines/throttle_down",type:"command"},throttle_cutoff:{gameCommand:"sim/starters/shut_down",type:"command"},landing_lights_on:{gameCommand:"sim/lights/landing_lights_on",type:"command"},landing_lights_off:{gameCommand:"sim/lights/landing_lights_off",type:"command"},landing_lights_toggle:{gameCommand:"sim/lights/landing_lights_toggle",type:"command"},taxi_lights_on:{gameCommand:"sim/lights/taxi_lights_on",type:"command"},taxi_lights_off:{gameCommand:"sim/lights/taxi_lights_off",type:"command"},taxi_lights_toggle:{gameCommand:"sim/lights/taxi_lights_toggle",type:"command"},beacon_lights_on:{gameCommand:"sim/lights/beacon_lights_on",type:"command"},beacon_lights_off:{gameCommand:"sim/lights/beacon_lights_off",type:"command"},beacon_lights_toggle:{gameCommand:"sim/lights/beacon_lights_toggle",type:"command"},nav_lights_on:{gameCommand:"sim/lights/nav_lights_on",type:"command"},nav_lights_off:{gameCommand:"sim/lights/nav_lights_off",type:"command"},nav_lights_toggle:{gameCommand:"sim/lights/nav_lights_toggle",type:"command"},strobe_lights_on:{gameCommand:"sim/lights/strobe_lights_on",type:"command"},strobe_lights_off:{gameCommand:"sim/lights/strobe_lights_off",type:"command"},strobe_lights_toggle:{gameCommand:"sim/lights/strobe_lights_toggle",type:"command"},pause:{gameCommand:"sim/operation/pause_on",type:"command"},unpause:{gameCommand:"sim/operation/pause_off",type:"command"},pause_toggle:{gameCommand:"sim/operation/pause_toggle",type:"command"}}};const C={msfs:{gameId:y.gameId,name:y.name,category:y.category,fieldMappings:y.fieldMappings,commandMappings:y.commandMappings,extraFields:{pitot_heat:{type:"boolean",description:"Pitot heat active",group:"Systems"},fuel_quantity_gallons:{type:"number",description:"Total fuel in gallons",unit:"gal",min:0,max:1e5,group:"Fuel"},fuel_flow_gph_1:{type:"number",description:"Engine 1 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},fuel_flow_gph_2:{type:"number",description:"Engine 2 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},fuel_flow_gph_3:{type:"number",description:"Engine 3 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},fuel_flow_gph_4:{type:"number",description:"Engine 4 fuel flow in GPH",unit:"gal/hr",min:0,max:5e3,group:"Fuel"},flaps_left_percent:{type:"number",description:"Left flaps position",unit:"%",min:0,max:100,group:"Controls"},flaps_right_percent:{type:"number",description:"Right flaps position",unit:"%",min:0,max:100,group:"Controls"},spoilers_left_percent:{type:"number",description:"Left spoilers position",unit:"%",min:0,max:100,group:"Controls"},spoilers_right_percent:{type:"number",description:"Right spoilers position",unit:"%",min:0,max:100,group:"Controls"},gear_left_position:{type:"number",description:"Left gear position",unit:"%",min:0,max:100,group:"Controls"},gear_center_position:{type:"number",description:"Center gear position",unit:"%",min:0,max:100,group:"Controls"},gear_right_position:{type:"number",description:"Right gear position",unit:"%",min:0,max:100,group:"Controls"},ambient_pressure:{type:"number",description:"Ambient pressure",unit:"inHg",min:20,max:35,group:"Environment"},sea_level_pressure:{type:"number",description:"Sea level pressure",unit:"inHg",min:27,max:32,group:"Environment"},aircraft_wind_x:{type:"number",description:"Wind component X-axis",unit:"kts",min:-200,max:200,group:"Environment"},aircraft_wind_y:{type:"number",description:"Wind component Y-axis",unit:"kts",min:-200,max:200,group:"Environment"},aircraft_wind_z:{type:"number",description:"Wind component Z-axis",unit:"kts",min:-200,max:200,group:"Environment"}}},xplane:{gameId:b.gameId,name:b.name,category:b.category,fieldMappings:b.fieldMappings,commandMappings:b.commandMappings,extraFields:{replay_mode:{type:"boolean",description:"Replay mode active",group:"Simulation"},time_local:{type:"number",description:"Local time in seconds since midnight",unit:"sec",min:0,max:86400,group:"Simulation"},time_zulu:{type:"number",description:"Zulu time in seconds since midnight",unit:"sec",min:0,max:86400,group:"Simulation"}}}};function w(t){return C[t]}function k(t,e){const o={};for(const[n,i]of Object.entries(t)){const t=e.fieldMappings[n];if(t){let e=i;if(t.transform&&t.transform in d){e=(0,d[t.transform])(i)}o[t.canonical]=e}else e.extraFields?.[n]&&(o[`${e.gameId}:${n}`]=i)}return o}class T{constructor(t,e){this._config=e,this._socket=t,this._callbacks=[],this._fields=e.fields?[...e.fields]:null,this._gameSchema=w(e.gameId)}async establishConnection(){if(!this._socket||!this._config.userId||!this._config.gameId)throw new Error("Missing arguments in establishConnection");return new Promise(t=>{let e;e=this._fields?{userId:this._config.userId,gameId:this._config.gameId,fields:this._fields}:`${this._config.userId}:${this._config.gameId}`,this._socket.timeout(5e3).emit("listen",e,(e,o)=>e?t({status:"failed",reason:"Listen request timed out."}):"success"===o.status?t({status:"success"}):t({status:"failed",reason:o.reason}))})}setupEventListener(){return this._socket.on("update",t=>{if(t?.gameId&&t.gameId!==this._config.gameId)return;const e=t?.data,o=e&&this._gameSchema?k(e,this._gameSchema):e;let n=o;if(this._fields&&this._fields.length>0&&o){n={};for(const t of this._fields)t in o&&(n[t]=o[t])}this.emit("update",{...t,raw:e,data:n})}),this._socket.on("key-events",t=>{const{gameId:e,eventType:o,data:n}=t||{};e===this._config.gameId&&o&&n&&this.emit(o,n)}),this}async subscribe(t){if(!Array.isArray(t)||0===t.length)throw new Error("fields must be a non-empty array");if(this._fields)for(const e of t)this._fields.includes(e)||this._fields.push(e);else this._fields=[...t];return this._updateSubscription()}async unsubscribe(t){if(!Array.isArray(t)||0===t.length)throw new Error("fields must be a non-empty array");if(!this._fields)throw new Error("Cannot unsubscribe when receiving all fields. Use subscribe() first to set explicit field list.");return this._fields=this._fields.filter(e=>!t.includes(e)),this._updateSubscription()}getFields(){return this._fields?[...this._fields]:null}async sendCommand(t,e){if(!t||"string"!=typeof t)throw new Error("command must be a non-empty string");return new Promise(o=>{const n={userId:this._config.userId,gameId:this._config.gameId,data:{fieldName:t,value:e}};this._socket.timeout(5e3).emit("set",n,(t,e)=>o(t?{status:"failed",reason:"Command request timed out."}:e))})}async _updateSubscription(){return new Promise(t=>{const e={userId:this._config.userId,gameId:this._config.gameId,fields:this._fields};this._socket.timeout(5e3).emit("listen-update",e,(e,o)=>t(e?{status:"failed",reason:"Update request timed out."}:o))})}}n(T.prototype);class E{constructor(t,e){this._config=e,this._socket=t,this._gameSchema=w(e.gameId),this._broadcasters=[]}async establishConnection(){if(!this._socket||!this._config.clientId||!this._config.gameId)throw new Error("Missing arguments in establishConnection");return new Promise(t=>{const e={clientId:this._config.clientId,gameId:this._config.gameId};this._socket.timeout(5e3).emit("presenceSubscribe",e,(e,o)=>{if(e)return t({status:"failed",reason:"Presence request timed out."});if("success"===o?.status){const e=Array.isArray(o.broadcasters)?o.broadcasters.map(t=>this._normalizeSnapshot(t)):[];return this._broadcasters=e,t({status:"success",broadcasters:e})}return t({status:"failed",reason:o?.reason||"Presence subscription failed."})})})}setupEventListener(){return this._socket.on("presence-update",t=>{const e=this._normalizeSnapshot(t);this._upsertBroadcaster(e),this.emit("update",e)}),this._socket.on("presence-remove",({userId:t})=>{t&&(this._broadcasters=this._broadcasters.filter(e=>e.userId!==t),this.emit("remove",{userId:t}))}),this._socket.on("connect",()=>{this.emit("connect")}),this._socket.on("disconnect",t=>{this.emit("disconnect",t)}),this}getBroadcasters(){return[...this._broadcasters]}disconnect(){this._socket&&this._socket.disconnect()}_normalizeSnapshot(t){if(!t||"object"!=typeof t)return t;const e=t.data,o=e&&this._gameSchema?k(e,this._gameSchema):e;return{...t,data:o,raw:e}}_upsertBroadcaster(t){if(!t||!t.userId)return;const e=this._broadcasters.findIndex(e=>e.userId===t.userId);if(e>=0){const o=[...this._broadcasters];return o[e]=t,void(this._broadcasters=o)}this._broadcasters=[...this._broadcasters,t]}}n(E.prototype);const A={msfs:!0,xplane:!0};class x extends _{constructor(t){super(t),this._socket=null,this._socketUrl=t.socketUrl||"https://socks.gameglue.gg",this._connectPromise=null}async createListener(t){if(!t)throw new Error("Not a valid listener config");if(!t.gameId||!A[t.gameId])throw new Error("Not a valid Game ID");if(!t.userId)throw new Error("User ID not supplied");if(t.fields&&!Array.isArray(t.fields))throw new Error("fields must be an array");await this._ensureConnected();const e=new T(this._socket,t),o=await e.establishConnection();if(this._socket.io.on("reconnect_attempt",()=>{this._updateSocketAuth(this.getAccessToken())}),this._socket.io.on("reconnect",()=>{e.establishConnection()}),"success"!==o.status)throw new Error(`There was a problem setting up the listener. Reason: ${o.reason}`);return e.setupEventListener()}async createPresenceListener(t){if(!t)throw new Error("Not a valid presence listener config");if(!t.gameId||!A[t.gameId])throw new Error("Not a valid Game ID");if(!t.clientId)throw new Error("Client ID not supplied");const e=o.io(this._socketUrl,{transports:["websocket"]});await new Promise((t,o)=>{e.on("connect",t),e.on("connect_error",t=>{m(t)&&p("WebSocket Connection",this._socketUrl),o(new Error(`Socket connection failed: ${t.message}`))})});const n=new E(e,t),i=await n.establishConnection();if(e.io.on("reconnect",()=>{n.establishConnection()}),"success"!==i.status)throw new Error(`There was a problem setting up the presence listener. Reason: ${i.reason}`);return n.setupEventListener()}async _ensureConnected(){if(!this._socket?.connected)if(this._connectPromise)await this._connectPromise;else{this._connectPromise=this._connect();try{await this._connectPromise}finally{this._connectPromise=null}}}_connect(){return new Promise((t,e)=>{const n=this.getAccessToken();n?(this._socket=o.io(this._socketUrl,{transports:["websocket"],auth:{token:n}}),this._socket.on("connect",()=>{t()}),this._socket.on("connect_error",t=>{m(t)&&p("WebSocket Connection",this._socketUrl),e(new Error(`Socket connection failed: ${t.message}`))}),this.onTokenRefreshed(t=>{this._updateSocketAuth(t)})):e(new Error("Not authenticated - call isAuthenticated() first"))})}_updateSocketAuth(t){this._socket&&(this._socket.auth.token=t)}}"undefined"!=typeof window&&(window.GameGlue=x,window.GameGlueSchemas={getGameSchema:w,getCategorySchema:f,normalizeTelemetry:k}),exports.GameGlue=x,exports.default=x,exports.getCategorySchema=f,exports.getGameSchema=w,exports.normalizeTelemetry=k;
2
2
  //# sourceMappingURL=gg.cjs.js.map