npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@simconnect.js/api

v1.0.7

Published

<img src="https://github.com/tcavenezuela/simconnect.js/assets/8359234/e8a8b35c-fc78-4615-a39f-db1a840bfaa9" alt="simconnect.js" width="250"/>

Downloads

14

Readme

npm version ts release

SimConnect client implementation for NodeJS.

@simconnect.js/api

This package provides a more user-friendly wrapper with predefined simvars values.

Quick start

  1. Install required libraries:
yarn add simconnect.js @simconnect.js/api
  1. Import the module and create a new connection constructor:
import { SIMCONNECT_API } from "@simconnect.js/api";

const simconnect = new SIMCONNECT_API();

simconnect.connect({
    autoReconnect: true,
    retries: Infinity,
    retryInterval: 5,
    onConnect: connect,
    onRetry: (_retries, interval) =>
      console.log(`Connection failed: retrying in ${interval} seconds.`),
    onException: (e) => {
      console.log("exception", e);
    },
  });

async function connect(handle, recvOpen) {
  console.log(`Simulator connected`, recvOpen);

  const [start, stop] = simconnect.schedule(
    (data) => {
      console.log("data", data);
    },
    1000,
    ["PLANE ALTITUDE"],
    true
  );

  const unpauseOff = simconnect.on(SystemEvents.UNPAUSED, () => {
    console.log(`sim unpaused`);
    unpauseOff();
  });

  const unpauseOn = simconnect.on(SystemEvents.PAUSE, () => {
    console.log(`sim paused`);
    unpauseOn();
  });
}

Methods:

connect:

Opens a connection with a running simulator stream:

simconnect.connect({
  autoReconnect: true,
  retries: Infinity,
  retryInterval: 5,
  onConnect: connect,
  onRetry: (_retries, interval) =>
    console.log(`Connection failed: retrying in ${interval} seconds.`),
  onException: (e) => {
    console.log("exception", e);
  },
});

connect method takes several options:

  • autoReconnect[boolean]: Boolean indicator that performs an automatic reconnection when it is detected that the simulator is not connected or stopped being connected.
  • retries[number]: Number of attempts it will make when making a reconnection.
  • retryInterval[number]: Interval in seconds that it will do when it is making a reconnection, example: if you put 5, every 5 seconds it will try to reconnect.
  • onConnect[function]: Callback function that is executed when a succesfully connection is made.
  • onRetry[function]: Callback function that is executed when a retry is made.
  • onException[function]: Callback function that is executed when an exception is made.

on:

Starts listening for a specific simconnect event with a specific handler. Returns a corresponding arg-less off() function to clean up the listener. See the "System events" section below for details on the event definition.

System events (used for on/off handling):

All event names in https://docs.flightsimulator.com/html/Programming_Tools/SimConnect/API_Reference/Events_And_Data/SimConnect_SubscribeToSystemEvent.htm are supported as constants on the SystemEvents object, importable alongside SIMCONNECT_API:

import { SystemEvents, SIMCONNECT_API } from "@simconnect.js/api";

const simconnect = new SIMCONNECT_API();

simconnect.connect({
  retries: Infinity,
  retryInterval: 5,
  onConnect: () => {
    simconnect.on(SystemEvents.PAUSED, () => {
      // ...
    });
  },
});

Note that the event names are keys from the SystemEvents object, using UPPER_SNAKE_CASE, not strings.

off:

Stop listening for a specific simconnect event with a specific handler. You'll typically not need to call this function directly, as you can just use the function that on returns. See the "System events" section above for more details on the event definition.

get:

Accepts a list of simvars (with spaces or underscores) and async-returns a key/value pair object with each simvar as key (with spaces replaced by underscores).

schedule:

Sets up a periodic call to handler every interval milliseconds with the result of get(...propNames). Returns an arg-less off() to end the scheduled call.

set:

Accepts a single simvar and the value its should be set to. This will throw "SimVar ... is not settable" when attempting to set the value for a read-only variable.

trigger:

Triggers a simconnect event, with optional value.

Supported Simvars:

All simvars are supported, barring several simvars with data types for which I need to figure out how to actually deference then, such as LatLonAlt structs, or the (super rare) bool/string combination, as well a any simvar that is officially deprecated, or marked as "legacy, do not use these going forward". If you get an error about an unknown Simvar, look up that variable on the SimConnect variables list and see if it's either deprecated, or part of a collection that is considered legacy.

  • [x] Camera Variables (not verified)
  • [x] Services Variables (not verified)
  • [x] Miscellaneous Variables (not verified)
  • Aircraft SimVars:
    • [x] Aircraft Autopilot/Assistant Variables (not verified)
    • [x] Aircraft Brake/Landing Gear Variables (not verified)
    • [x] Aircraft Control Variables (not verified)
    • [x] Aircraft Electrics Variables (not verified)
    • [x] Aircraft Engine Variables (not verified)
    • [x] Aircraft Flight Model Variables (not verified)
    • [x] Aircraft Fuel Variables (not verified)
    • [x] Aircraft Misc. Variables (not verified)
    • [x] Aircraft Radio Navigation Variables (not verified)
    • [x] Aircraft System Variables (not verified)
    • [x] Helicopter Variables (not verified)

Further more, all environment variables listed over on https://docs.flightsimulator.com/html/Additional_Information/Reverse_Polish_Notation.htm#EnvironmentVariables are supported as well.

Supported SimEvents:

SimEvents are resolved by key name, so as long as you use a valid key name, you can trigger it.

See https://docs.flightsimulator.com/html/Programming_Tools/Event_IDs/Event_IDs.htm for the full list.