@irsdk-node/native 4.1.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,115 @@
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
+ _Currently using **iRacing SDK v1.19**. You can see the latest version of the SDK [on the forums](https://forums.iracing.com/discussion/62/iracing-sdk/p1)._
4
4
 
5
- While you can use this package directly, it is highly recommended to use the [irsdk-node](../irsdk-node) package instead.
5
+ This is the native bindings package for irsdk-node. This provides near 1:1 bindings to the C++ iRacing SDK, and is consumed as a 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.
6
6
 
7
- ## Why an optional dependency?
7
+ 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.
8
8
 
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.
9
+ ## Usage
10
+ Install as a dependency.
10
11
 
11
- ## Debugging
12
+ ```sh
13
+ # Via npm..
14
+ $ npm install @irsdk-node/types
12
15
 
13
- - `yarn build-cpp:debug`: Builds the native module in debug mode.
16
+ # Or yarn..
17
+ $ yarn add @irsdk-node/types
14
18
 
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:
19
+ # Or pnpm..
20
+ $ pnpm add @irsdk-node/types
21
+ ```
16
22
 
17
- ```diff
18
- // In `src/irsdk-node.ts`
19
- + import { DebugSDK } from '@irsdk-node/native';
20
- - import { NativeSDK } from '@irsdk-node/native';
23
+ Then you can use the SDK bindings directly.
24
+
25
+ ```ts
26
+ import { NativeSDK } from '@irsdk-node/native';
27
+ import {
28
+ SessionData,
29
+ TelemetryVarList,
30
+ TelemetryVariable,
31
+ BroadcastMessages,
32
+ TelemetryCommand,
33
+ } from '@irsdk-node/types';
34
+
35
+ const sdk = new NativeSDK();
36
+
37
+ // Try to start the SDK. This will return false if an iRacing session is not active.
38
+ //
39
+ // In cases where the SDK is not running, you would likely want to poll this fn
40
+ // so you can start grabbing data once a session starts.
41
+ if (!sdk.startSDK()) {
42
+ console.log('iRacing not running');
43
+ process.exit(0);
44
+ }
45
+
46
+ // Start telemetry.
47
+ sdk.broadcast(BroadcastMessages.TelemCommand, TelemetryCommand.Start);
48
+
49
+ // Grab data from the SDK.
50
+ const TICK_RATE = 1 / 60; // 60fps, the max
51
+ if (sdk.waitForData(TICK_RATE)) {
52
+ // This is a YAML string of more static data. Every time this changes,
53
+ // sdk.currDataVersion will be incremented by 1. -1 is the default value.
54
+ //
55
+ // This object is BIG. It is recommended to only fetch when currDataVersion
56
+ // changes to avoid performance issues.
57
+ const sessionData: SessionData = sdk.getSessionData();
58
+
59
+ // Telemetry needs to be massaged using var.varType to their correct types,
60
+ // for example, varType 4 (float32) should be parsed as Float32Array.
61
+ //
62
+ // See irsdk-node codebase for examples.
63
+
64
+ // Returns ALL telemetry variables as a big object.
65
+ const allTelemetry: TelemetryVarList = sdk.getTelemetryData();
66
+
67
+ // Get just one telemetry variable by name or index. Usually by name.
68
+ const incidentCount: TelemetryVariable<number[]> = sdk.getTelemetryVariable('PlayerCarMyIncidentCount');
69
+ }
70
+
71
+ // Close the SDK once you are done.
72
+ sdk.stopSDK();
21
73
  ```
22
74
 
23
- ## Generating types
75
+ ## Distribution
76
+
77
+ 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).
78
+
79
+ 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.
80
+
81
+ ## Contributing
24
82
 
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.
83
+ ### SDK
84
+
85
+ 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.)
86
+
87
+ ### Generating types
88
+
89
+ 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
90
 
27
91
  Please refer to the readme in the types package for more info.
28
92
 
29
- ## Commands
93
+ ### Commands
94
+
95
+ These are the primary commands for package development.
30
96
 
31
97
  ```sh
32
- # Build the module.
33
- $ yarn build
98
+ # Build the package.
99
+ $ pnpm build
100
+
101
+ # Build only the typescript.
102
+ $ pnpm build:ts
34
103
 
35
- # Build either the release or debug build.
36
- $ yarn build-cpp:[release|debug]
104
+ # Build the C++ module.
105
+ $ pnpm build:cpp
37
106
 
38
107
  # Run util script for generating typescript types
39
- $ yarn generate-types
108
+ $ pnpm generate-types
40
109
 
41
110
  # Clean the build directories
42
- $ yarn clean
111
+ $ pnpm clean
43
112
 
44
113
  # Lint package
45
- $ yarn lint
114
+ $ pnpm lint
46
115
  ```