@irsdk-node/native 4.0.2 → 4.1.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.
Files changed (72) hide show
  1. package/README.md +46 -46
  2. package/binding.gyp +28 -19
  3. package/dist/INativeSDK.d.ts +28 -0
  4. package/dist/INativeSDK.js +2 -0
  5. package/dist/MockSdk.d.ts +43 -0
  6. package/dist/MockSdk.js +70 -0
  7. package/dist/mock-data/loader.d.ts +3 -0
  8. package/dist/mock-data/loader.js +41 -0
  9. package/dist/mock-data/session.json +4305 -0
  10. package/dist/mock-data/telemetry.json +4986 -0
  11. package/{src/index.d.ts → index.d.ts} +5 -35
  12. package/index.js +36 -0
  13. package/lib/irsdk_client.cpp +495 -495
  14. package/lib/irsdk_client.h +139 -139
  15. package/lib/irsdk_defines.h +528 -528
  16. package/{src → lib}/irsdk_node.cc +404 -375
  17. package/{src → lib}/irsdk_node.h +49 -50
  18. package/lib/irsdk_node_mocked.cc +226 -0
  19. package/lib/irsdk_utils.cpp +377 -377
  20. package/lib/yaml_parser.cpp +176 -176
  21. package/lib/yaml_parser.h +34 -34
  22. package/package.json +37 -29
  23. package/prebuilds/darwin-arm64/@irsdk-node+native.node +0 -0
  24. package/prebuilds/linux-x64/@irsdk-node+native.node +0 -0
  25. package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
  26. package/build/Debug/irsdk_node.exp +0 -0
  27. package/build/Debug/irsdk_node.lib +0 -0
  28. package/build/Debug/irsdk_node.node +0 -0
  29. package/build/Debug/irsdk_node.pdb +0 -0
  30. package/build/Debug/obj/irsdk_node/irsdk_node.node.recipe +0 -11
  31. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
  32. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
  33. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
  34. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/Cl.items.tlog +0 -4
  35. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +0 -2
  36. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
  37. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
  38. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.secondary.1.tlog +0 -3
  39. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
  40. package/build/Debug/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
  41. package/build/Debug/obj/irsdk_node/lib/yaml_parser.obj +0 -0
  42. package/build/Debug/obj/irsdk_node/src/irsdk_node.obj +0 -0
  43. package/build/Debug/obj/irsdk_node/vcpkg.applocal.log +0 -1
  44. package/build/Debug/obj/irsdk_node/win_delay_load_hook.obj +0 -0
  45. package/build/Release/irsdk_node.exp +0 -0
  46. package/build/Release/irsdk_node.iobj +0 -0
  47. package/build/Release/irsdk_node.ipdb +0 -0
  48. package/build/Release/irsdk_node.lib +0 -0
  49. package/build/Release/irsdk_node.node +0 -0
  50. package/build/Release/irsdk_node.pdb +0 -0
  51. package/build/Release/obj/irsdk_node/irsdk_node.node.recipe +0 -11
  52. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
  53. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
  54. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
  55. package/build/Release/obj/irsdk_node/irsdk_node.tlog/Cl.items.tlog +0 -4
  56. package/build/Release/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +0 -2
  57. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
  58. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
  59. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.secondary.1.tlog +0 -5
  60. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
  61. package/build/Release/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
  62. package/build/Release/obj/irsdk_node/lib/yaml_parser.obj +0 -0
  63. package/build/Release/obj/irsdk_node/src/irsdk_node.obj +0 -0
  64. package/build/Release/obj/irsdk_node/vcpkg.applocal.log +0 -1
  65. package/build/Release/obj/irsdk_node/win_delay_load_hook.obj +0 -0
  66. package/build/binding.sln +0 -19
  67. package/build/config.gypi +0 -426
  68. package/build/irsdk_node.vcxproj +0 -157
  69. package/build/irsdk_node.vcxproj.filters +0 -73
  70. package/dist/index.d.ts +0 -1
  71. package/dist/index.js +0 -13
  72. package/src/index.js +0 -11
package/README.md CHANGED
@@ -1,46 +1,46 @@
1
- # @irsdk-node/native
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.
4
-
5
- While you can use this package directly, it is highly recommended to use the [irsdk-node](../irsdk-node) package instead.
6
-
7
- ## Why an optional dependency?
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.
10
-
11
- ## Debugging
12
-
13
- - `yarn build-cpp:debug`: Builds the native module in debug mode.
14
-
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:
16
-
17
- ```diff
18
- // In `src/irsdk-node.ts`
19
- + import { DebugSDK } from '@irsdk-node/native';
20
- - import { NativeSDK } from '@irsdk-node/native';
21
- ```
22
-
23
- ## Generating types
24
-
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.
26
-
27
- Please refer to the readme in the types package for more info.
28
-
29
- ## Commands
30
-
31
- ```sh
32
- # Build the module.
33
- $ yarn build
34
-
35
- # Build either the release or debug build.
36
- $ yarn build-cpp:[release|debug]
37
-
38
- # Run util script for generating typescript types
39
- $ yarn generate-types
40
-
41
- # Clean the build directories
42
- $ yarn clean
43
-
44
- # Lint package
45
- $ yarn lint
46
- ```
1
+ # @irsdk-node/native
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.
4
+
5
+ While you can use this package directly, it is highly recommended to use the [irsdk-node](../irsdk-node) package instead.
6
+
7
+ ## Why an optional dependency?
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.
10
+
11
+ ## Debugging
12
+
13
+ - `yarn build-cpp:debug`: Builds the native module in debug mode.
14
+
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:
16
+
17
+ ```diff
18
+ // In `src/irsdk-node.ts`
19
+ + import { DebugSDK } from '@irsdk-node/native';
20
+ - import { NativeSDK } from '@irsdk-node/native';
21
+ ```
22
+
23
+ ## Generating types
24
+
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.
26
+
27
+ Please refer to the readme in the types package for more info.
28
+
29
+ ## Commands
30
+
31
+ ```sh
32
+ # Build the module.
33
+ $ yarn build
34
+
35
+ # Build either the release or debug build.
36
+ $ yarn build-cpp:[release|debug]
37
+
38
+ # Run util script for generating typescript types
39
+ $ yarn generate-types
40
+
41
+ # Clean the build directories
42
+ $ yarn clean
43
+
44
+ # Lint package
45
+ $ yarn lint
46
+ ```
package/binding.gyp CHANGED
@@ -1,19 +1,28 @@
1
- {
2
- "targets": [
3
- {
4
- "target_name": "irsdk_node",
5
- "sources": [
6
- "src/irsdk_node.cc",
7
- "lib/irsdk_utils.cpp",
8
- "lib/yaml_parser.cpp",
9
- "lib/irsdk_defines.h"
10
- ],
11
- "defines": [
12
- "NAPI_DISABLE_CPP_EXCEPTIONS",
13
- ],
14
- "include_dirs": [
15
- "<!(node -p \"require('node-addon-api').include_dir\")",
16
- ]
17
- }
18
- ]
19
- }
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "irsdk_node",
5
+ "sources": [
6
+ "lib/yaml_parser.cpp",
7
+ ],
8
+ "conditions": [
9
+ ["OS=='win'", {
10
+ "sources": [
11
+ "lib/irsdk_node.cc",
12
+ "lib/irsdk_utils.cpp",
13
+ "lib/irsdk_defines.h"
14
+ ]
15
+ }],
16
+ ["OS!='win'", {
17
+ "sources": ["lib/irsdk_node_mocked.cc"]
18
+ }]
19
+ ],
20
+ "defines": [
21
+ "NAPI_DISABLE_CPP_EXCEPTIONS",
22
+ ],
23
+ "include_dirs": [
24
+ "<!(node -p \"require('node-addon-api').include_dir\")",
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,28 @@
1
+ import { BroadcastMessages, CameraState, ChatCommand, FFBCommand, PitCommand, ReloadTexturesCommand, ReplayPositionCommand, ReplaySearchCommand, ReplayStateCommand, TelemetryCommand, TelemetryVariable, TelemetryVarList, VideoCaptureCommand } from '@irsdk-node/types';
2
+ export interface INativeSDK {
3
+ readonly currDataVersion: number;
4
+ readonly isMocked: boolean;
5
+ enableLogging: boolean;
6
+ startSDK(): boolean;
7
+ stopSDK(): void;
8
+ isRunning(): boolean;
9
+ waitForData(timeout?: number): boolean;
10
+ getSessionData(): string;
11
+ getTelemetryData(): TelemetryVarList;
12
+ getTelemetryVariable<T>(index: number): TelemetryVariable<T>;
13
+ getTelemetryVariable<T>(name: string): TelemetryVariable<T>;
14
+ broadcast(message: BroadcastMessages.CameraSwitchPos, pos: number, group: number, camera: number): void;
15
+ broadcast(message: BroadcastMessages.CameraSwitchNum, driver: number, group: number, camera: number): void;
16
+ broadcast(message: BroadcastMessages.CameraSetState, state: CameraState): void;
17
+ broadcast(message: BroadcastMessages.ReplaySetPlaySpeed, speed: number, slowMotion: number): void;
18
+ broadcast(message: BroadcastMessages.ReplaySetPlayPosition, pos: ReplayPositionCommand, frame: number): void;
19
+ broadcast(message: BroadcastMessages.ReplaySearch, mode: ReplaySearchCommand): void;
20
+ broadcast(message: BroadcastMessages.ReplaySetState, state: ReplayStateCommand): void;
21
+ broadcast(message: BroadcastMessages.ReloadTextures, command: ReloadTexturesCommand, carIndex?: number): void;
22
+ broadcast(message: BroadcastMessages.ChatCommand, command: ChatCommand, macro?: number): void;
23
+ broadcast(message: BroadcastMessages.PitCommand, command: PitCommand, param?: number): void;
24
+ broadcast(message: BroadcastMessages.TelemCommand, command: TelemetryCommand): void;
25
+ broadcast(message: BroadcastMessages.FFBCommand, command: FFBCommand, value: number): void;
26
+ broadcast(message: BroadcastMessages.ReplaySearchSessionTime, session: number, time: number): void;
27
+ broadcast(message: BroadcastMessages.VideoCapture, command: VideoCaptureCommand): void;
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,43 @@
1
+ import { BroadcastMessages, CameraState, ChatCommand, FFBCommand, PitCommand, ReloadTexturesCommand, ReplayPositionCommand, ReplaySearchCommand, ReplayStateCommand, TelemetryCommand, TelemetryVariable, TelemetryVarList, VideoCaptureCommand } from '@irsdk-node/types';
2
+ import type { INativeSDK } from './INativeSDK';
3
+ type TelemetryVarKey = keyof TelemetryVarList;
4
+ type TelemetryResultTypes = boolean | number | string;
5
+ /**
6
+ * Mock SDK class intended for use on non-win32 platforms for development.
7
+ * Implements the native sdk interface supplemented with mock data suitable for
8
+ * iterating on projects with.
9
+ *
10
+ * @todo - This should really be handled differently, for example via a wrapper
11
+ * class around the native class that gets exposed.
12
+ */
13
+ export declare class MockSDK implements INativeSDK {
14
+ currDataVersion: number;
15
+ isMocked: boolean;
16
+ enableLogging: boolean;
17
+ private _isRunning;
18
+ constructor();
19
+ private _loadMockData;
20
+ startSDK(): boolean;
21
+ stopSDK(): void;
22
+ isRunning(): boolean;
23
+ waitForData(_timeout?: number): boolean;
24
+ getSessionData(): string;
25
+ getTelemetryData(): TelemetryVarList;
26
+ getTelemetryVariable<T extends TelemetryResultTypes>(index: number): TelemetryVariable<T[]>;
27
+ getTelemetryVariable<T extends TelemetryResultTypes>(name: TelemetryVarKey): TelemetryVariable<T[]>;
28
+ broadcast(message: BroadcastMessages.CameraSwitchPos, pos: number, group: number, camera: number): void;
29
+ broadcast(message: BroadcastMessages.CameraSwitchNum, driver: number, group: number, camera: number): void;
30
+ broadcast(message: BroadcastMessages.CameraSetState, state: CameraState): void;
31
+ broadcast(message: BroadcastMessages.ReplaySetPlaySpeed, speed: number, slowMotion: number): void;
32
+ broadcast(message: BroadcastMessages.ReplaySetPlayPosition, pos: ReplayPositionCommand, frame: number): void;
33
+ broadcast(message: BroadcastMessages.ReplaySearch, mode: ReplaySearchCommand): void;
34
+ broadcast(message: BroadcastMessages.ReplaySetState, state: ReplayStateCommand): void;
35
+ broadcast(message: BroadcastMessages.ReloadTextures, command: ReloadTexturesCommand, carIndex?: number): void;
36
+ broadcast(message: BroadcastMessages.ChatCommand, command: ChatCommand, macro?: number): void;
37
+ broadcast(message: BroadcastMessages.PitCommand, command: PitCommand, param?: number): void;
38
+ broadcast(message: BroadcastMessages.TelemCommand, command: TelemetryCommand): void;
39
+ broadcast(message: BroadcastMessages.FFBCommand, command: FFBCommand, value: number): void;
40
+ broadcast(message: BroadcastMessages.ReplaySearchSessionTime, session: number, time: number): void;
41
+ broadcast(message: BroadcastMessages.VideoCapture, command: VideoCaptureCommand): void;
42
+ }
43
+ export {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockSDK = void 0;
4
+ const loader_1 = require("./mock-data/loader");
5
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6
+ let MOCK_TELEMETRY = null;
7
+ let MOCK_SESSION = null;
8
+ /**
9
+ * Mock SDK class intended for use on non-win32 platforms for development.
10
+ * Implements the native sdk interface supplemented with mock data suitable for
11
+ * iterating on projects with.
12
+ *
13
+ * @todo - This should really be handled differently, for example via a wrapper
14
+ * class around the native class that gets exposed.
15
+ */
16
+ class MockSDK {
17
+ currDataVersion = 1;
18
+ isMocked = true;
19
+ enableLogging = false;
20
+ _isRunning = false;
21
+ constructor() {
22
+ this._loadMockData().catch((reason) => {
23
+ console.error('Error loading mock data for mock SDK:', reason);
24
+ });
25
+ console.warn('Attempting to access iRacing SDK on unsupported platform!', '\nReturning mock SDK for testing purposes. (Only win32 supported)');
26
+ }
27
+ async _loadMockData() {
28
+ const [session, telemetry] = await Promise.all([
29
+ !MOCK_SESSION ? (0, loader_1.loadMockSessionData)() : Promise.resolve(MOCK_SESSION),
30
+ !MOCK_TELEMETRY ? (0, loader_1.loadMockTelemetry)() : Promise.resolve(MOCK_TELEMETRY),
31
+ ]);
32
+ MOCK_SESSION = session;
33
+ MOCK_TELEMETRY = telemetry;
34
+ }
35
+ startSDK() {
36
+ this._isRunning = true;
37
+ return true;
38
+ }
39
+ stopSDK() {
40
+ this._isRunning = false;
41
+ }
42
+ isRunning() {
43
+ return this._isRunning;
44
+ }
45
+ waitForData(_timeout) {
46
+ return this._isRunning;
47
+ }
48
+ getSessionData() {
49
+ return MOCK_SESSION ?? '';
50
+ }
51
+ getTelemetryData() {
52
+ if (!MOCK_TELEMETRY) {
53
+ throw new Error('Attempted accessing mock telemetry before it was loaded.');
54
+ }
55
+ return MOCK_TELEMETRY;
56
+ }
57
+ getTelemetryVariable(name) {
58
+ if (!MOCK_TELEMETRY) {
59
+ throw new Error('Attempted accessing mock telemetry before it was loaded.');
60
+ }
61
+ if (typeof name === 'number') {
62
+ return Object.values(MOCK_TELEMETRY)[name];
63
+ }
64
+ return MOCK_TELEMETRY[name];
65
+ }
66
+ broadcast(...args) {
67
+ console.log('Mocking SDK call:', ...args);
68
+ }
69
+ }
70
+ exports.MockSDK = MockSDK;
@@ -0,0 +1,3 @@
1
+ import { TelemetryVarList } from '@irsdk-node/types';
2
+ export declare const loadMockSessionData: () => Promise<string>;
3
+ export declare const loadMockTelemetry: () => Promise<TelemetryVarList>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ // eslint-disable @typescript-eslint/no-unsafe-return
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.loadMockTelemetry = exports.loadMockSessionData = void 0;
31
+ const js_yaml_1 = __importDefault(require("js-yaml"));
32
+ const loadMockSessionData = async () => {
33
+ const json = await Promise.resolve().then(() => __importStar(require('./session.json')));
34
+ return js_yaml_1.default.dump(json.default);
35
+ };
36
+ exports.loadMockSessionData = loadMockSessionData;
37
+ const loadMockTelemetry = async () => {
38
+ const json = await Promise.resolve().then(() => __importStar(require('./telemetry.json')));
39
+ return json.default;
40
+ };
41
+ exports.loadMockTelemetry = loadMockTelemetry;