@irsdk-node/native 4.0.2 → 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 +9 -0
- package/README.md +113 -46
- package/binding.gyp +28 -19
- package/dist/INativeSDK.d.ts +28 -0
- package/dist/INativeSDK.js +2 -0
- package/dist/MockSdk.d.ts +43 -0
- package/dist/MockSdk.js +70 -0
- package/dist/mock-data/loader.d.ts +3 -0
- package/dist/mock-data/loader.js +41 -0
- package/dist/mock-data/session.json +4305 -0
- package/dist/mock-data/telemetry.json +4986 -0
- package/{src/index.d.ts → index.d.ts} +5 -35
- package/index.js +36 -0
- package/lib/irsdk_client.cpp +495 -495
- package/lib/irsdk_client.h +139 -139
- package/lib/irsdk_defines.h +528 -528
- package/{src → lib}/irsdk_node.cc +404 -375
- package/{src → lib}/irsdk_node.h +49 -50
- package/lib/irsdk_node_mocked.cc +226 -0
- package/lib/irsdk_utils.cpp +377 -377
- package/lib/yaml_parser.cpp +176 -176
- package/lib/yaml_parser.h +34 -34
- package/package.json +37 -29
- package/prebuilds/darwin-arm64/@irsdk-node+native.node +0 -0
- package/prebuilds/linux-x64/@irsdk-node+native.node +0 -0
- package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
- package/build/Debug/irsdk_node.exp +0 -0
- package/build/Debug/irsdk_node.lib +0 -0
- package/build/Debug/irsdk_node.node +0 -0
- package/build/Debug/irsdk_node.pdb +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.node.recipe +0 -11
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/Cl.items.tlog +0 -4
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +0 -2
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.secondary.1.tlog +0 -3
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
- package/build/Debug/obj/irsdk_node/lib/yaml_parser.obj +0 -0
- package/build/Debug/obj/irsdk_node/src/irsdk_node.obj +0 -0
- package/build/Debug/obj/irsdk_node/vcpkg.applocal.log +0 -1
- package/build/Debug/obj/irsdk_node/win_delay_load_hook.obj +0 -0
- package/build/Release/irsdk_node.exp +0 -0
- package/build/Release/irsdk_node.iobj +0 -0
- package/build/Release/irsdk_node.ipdb +0 -0
- package/build/Release/irsdk_node.lib +0 -0
- package/build/Release/irsdk_node.node +0 -0
- package/build/Release/irsdk_node.pdb +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.node.recipe +0 -11
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/Cl.items.tlog +0 -4
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +0 -2
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.secondary.1.tlog +0 -5
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
- package/build/Release/obj/irsdk_node/lib/yaml_parser.obj +0 -0
- package/build/Release/obj/irsdk_node/src/irsdk_node.obj +0 -0
- package/build/Release/obj/irsdk_node/vcpkg.applocal.log +0 -1
- package/build/Release/obj/irsdk_node/win_delay_load_hook.obj +0 -0
- package/build/binding.sln +0 -19
- package/build/config.gypi +0 -426
- package/build/irsdk_node.vcxproj +0 -157
- package/build/irsdk_node.vcxproj.filters +0 -73
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -13
- package/src/index.js +0 -11
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
|
-
# @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](
|
|
4
|
-
|
|
5
|
-
While you can use this package directly, it is highly recommended to use the [irsdk-node](
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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](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
|
+
|
|
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
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
Install as a dependency.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
# Via npm..
|
|
12
|
+
$ npm install @irsdk-node/types
|
|
13
|
+
|
|
14
|
+
# Or yarn..
|
|
15
|
+
$ yarn add @irsdk-node/types
|
|
16
|
+
|
|
17
|
+
# Or pnpm..
|
|
18
|
+
$ pnpm add @irsdk-node/types
|
|
19
|
+
```
|
|
20
|
+
|
|
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();
|
|
71
|
+
```
|
|
72
|
+
|
|
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
|
|
80
|
+
|
|
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.
|
|
88
|
+
|
|
89
|
+
Please refer to the readme in the types package for more info.
|
|
90
|
+
|
|
91
|
+
### Commands
|
|
92
|
+
|
|
93
|
+
These are the primary commands for package development.
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
# Build the package.
|
|
97
|
+
$ pnpm build
|
|
98
|
+
|
|
99
|
+
# Build only the typescript.
|
|
100
|
+
$ pnpm build:ts
|
|
101
|
+
|
|
102
|
+
# Build the C++ module.
|
|
103
|
+
$ pnpm build:cpp
|
|
104
|
+
|
|
105
|
+
# Run util script for generating typescript types
|
|
106
|
+
$ pnpm generate-types
|
|
107
|
+
|
|
108
|
+
# Clean the build directories
|
|
109
|
+
$ pnpm clean
|
|
110
|
+
|
|
111
|
+
# Lint package
|
|
112
|
+
$ pnpm lint
|
|
113
|
+
```
|
package/binding.gyp
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"targets": [
|
|
3
|
-
{
|
|
4
|
-
"target_name": "irsdk_node",
|
|
5
|
-
"sources": [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,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 {};
|
package/dist/MockSdk.js
ADDED
|
@@ -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,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;
|