@irsdk-node/native 4.1.0 → 4.1.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Matthew Bengston
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,46 +1,113 @@
1
1
  # @irsdk-node/native
2
2
 
3
- This is the native bindings package for irsdk-node. This provides near 1:1 bindings to the C++ iRacing SDK, and is consumed as an optional dependency of [irsdk-node](../irsdk-node), which provides a handy little wrapper around the API to make it nicer to use and avoid boilerplating.
3
+ This is the native bindings package for irsdk-node. This provides near 1:1 bindings to the C++ iRacing SDK, and is consumed as an optional dependency of [irsdk-node](https://github.com/bengsfort/irsdk-node/tree/main/packages/irsdk-node), which provides a handy little wrapper around the API to make it nicer to use and avoid boilerplating.
4
4
 
5
- While you can use this package directly, it is highly recommended to use the [irsdk-node](../irsdk-node) package instead.
5
+ While you can use this package directly, it is highly recommended to use the [irsdk-node](https://github.com/bengsfort/irsdk-node/tree/main/packages/irsdk-node) package instead. Types for the data exposed via this package can be used independently via [@irsdk-node/types](https://github.com/bengsfort/irsdk-node/tree/main/packages/irsdk-node-native) as well.
6
6
 
7
- ## Why an optional dependency?
7
+ ## Usage
8
+ Install as a dependency.
8
9
 
9
- The [irsdk-node](../irsdk-node) package was split up in to separate packages to solve the issue that this SDK is windows-only, which means that the package wasn't able to be used in any other environment. For most cases this is fine, however it becomes a big issue if you want to do something as simple as use the types in a webview or in an electron renderer process. As an optional dependency, the types and rest of the SDK can be imported as needed wherever.
10
-
11
- ## Debugging
10
+ ```sh
11
+ # Via npm..
12
+ $ npm install @irsdk-node/types
12
13
 
13
- - `yarn build-cpp:debug`: Builds the native module in debug mode.
14
+ # Or yarn..
15
+ $ yarn add @irsdk-node/types
14
16
 
15
- In debug mode, you are going to need to swap to using the `DebugSDK` rather than `NativeSDK`. This uses the debug build rather than the release build, which allows debugging/breakpoints via vscode (you can use the `Debug bridge` run task in vscode to do this). For example:
17
+ # Or pnpm..
18
+ $ pnpm add @irsdk-node/types
19
+ ```
16
20
 
17
- ```diff
18
- // In `src/irsdk-node.ts`
19
- + import { DebugSDK } from '@irsdk-node/native';
20
- - import { NativeSDK } from '@irsdk-node/native';
21
+ Then you can use the SDK bindings directly.
22
+
23
+ ```ts
24
+ import { NativeSDK } from '@irsdk-node/native';
25
+ import {
26
+ SessionData,
27
+ TelemetryVarList,
28
+ TelemetryVariable,
29
+ BroadcastMessages,
30
+ TelemetryCommand,
31
+ } from '@irsdk-node/types';
32
+
33
+ const sdk = new NativeSDK();
34
+
35
+ // Try to start the SDK. This will return false if an iRacing session is not active.
36
+ //
37
+ // In cases where the SDK is not running, you would likely want to poll this fn
38
+ // so you can start grabbing data once a session starts.
39
+ if (!sdk.startSDK()) {
40
+ console.log('iRacing not running');
41
+ process.exit(0);
42
+ }
43
+
44
+ // Start telemetry.
45
+ sdk.broadcast(BroadcastMessages.TelemCommand, TelemetryCommand.Start);
46
+
47
+ // Grab data from the SDK.
48
+ const TICK_RATE = 1 / 60; // 60fps, the max
49
+ if (sdk.waitForData(TICK_RATE)) {
50
+ // This is a YAML string of more static data. Every time this changes,
51
+ // sdk.currDataVersion will be incremented by 1. -1 is the default value.
52
+ //
53
+ // This object is BIG. It is recommended to only fetch when currDataVersion
54
+ // changes to avoid performance issues.
55
+ const sessionData: SessionData = sdk.getSessionData();
56
+
57
+ // Telemetry needs to be massaged using var.varType to their correct types,
58
+ // for example, varType 4 (float32) should be parsed as Float32Array.
59
+ //
60
+ // See irsdk-node codebase for examples.
61
+
62
+ // Returns ALL telemetry variables as a big object.
63
+ const allTelemetry: TelemetryVarList = sdk.getTelemetryData();
64
+
65
+ // Get just one telemetry variable by name or index. Usually by name.
66
+ const incidentCount: TelemetryVariable<number[]> = sdk.getTelemetryVariable('PlayerCarMyIncidentCount');
67
+ }
68
+
69
+ // Close the SDK once you are done.
70
+ sdk.stopSDK();
21
71
  ```
22
72
 
23
- ## Generating types
73
+ ## Distribution
74
+
75
+ To ensure cross-compat between platforms, a mock SDK api is provided for non-windows platforms. This gets built on all supported platforms automatically during deployment via [github actions](../../.github/workflows/do-release.yaml). [Node-gyp](https://www.npmjs.com/package/node-gyp) is used under the hood for building the node.js C++ module, with pre-build functionality provided by [prebuildify](https://www.npmjs.com/package/prebuildify).
76
+
77
+ Prebuildify also will automatically detect the platform and import the correct native module for the platform. If it doesn't exist, during installation it will attempt to build it.
78
+
79
+ ## Contributing
24
80
 
25
- This package contains a utility script for generating Typescript types based on the actual Telemetry values present during runtime. To do so you can run `yarn generate-types` while you have iRacing running and connected to a server. This will generate a new .ts types file in the [@irsdk-node/types](../irsdk-node-types) package.
81
+ ### SDK
82
+
83
+ The SDK in its entirety lives in [lib](./lib/) along with the node.js bindings class. Technically it is always at the 'latest version' of the sdk with regards to the telemetry and session data since those are just pure data, but for other API updates the latest sdk files can just be replaced within that directory to update to the latest (for example `irsdk_client.h`, `irsdk_defines.h`, etc.)
84
+
85
+ ### Generating types
86
+
87
+ This package contains a utility script for generating Typescript types based on the actual Telemetry values present during runtime. To do so you can run `pnpm generate-types` while you have iRacing running and connected to a server. This will generate a new .ts types file in the [@irsdk-node/types](../irsdk-node-types) package.
26
88
 
27
89
  Please refer to the readme in the types package for more info.
28
90
 
29
- ## Commands
91
+ ### Commands
92
+
93
+ These are the primary commands for package development.
30
94
 
31
95
  ```sh
32
- # Build the module.
33
- $ yarn build
96
+ # Build the package.
97
+ $ pnpm build
98
+
99
+ # Build only the typescript.
100
+ $ pnpm build:ts
34
101
 
35
- # Build either the release or debug build.
36
- $ yarn build-cpp:[release|debug]
102
+ # Build the C++ module.
103
+ $ pnpm build:cpp
37
104
 
38
105
  # Run util script for generating typescript types
39
- $ yarn generate-types
106
+ $ pnpm generate-types
40
107
 
41
108
  # Clean the build directories
42
- $ yarn clean
109
+ $ pnpm clean
43
110
 
44
111
  # Lint package
45
- $ yarn lint
112
+ $ pnpm lint
46
113
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@irsdk-node/native",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "author": {
5
5
  "name": "Matt Bengston",
6
6
  "email": "bengsfort@gmail.com",
@@ -38,7 +38,7 @@
38
38
  "node-addon-api": "^8.2.1",
39
39
  "node-gyp": "^10.2.0",
40
40
  "node-gyp-build": "^4.8.4",
41
- "@irsdk-node/types": "^3.0.2"
41
+ "@irsdk-node/types": "^3.0.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/js-yaml": "^4.0.9",