node-iracing-sdk 0.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.
package/README.md ADDED
@@ -0,0 +1,336 @@
1
+ # node-iracing-sdk
2
+
3
+ Node.js bindings for the iRacing SDK client with event-driven telemetry, session info parsing, and sim control broadcasts.
4
+
5
+ ## Installation
6
+
7
+ Prerequisites:
8
+ - Windows (the iRacing SDK relies on Windows shared memory APIs).
9
+ - iRacing running and in a session to expose telemetry.
10
+
11
+ ```bash
12
+ npm install node-iracing-sdk
13
+ ```
14
+
15
+ TypeScript types are published separately:
16
+
17
+ ```bash
18
+ npm install --save-dev @types/node-iracing-sdk
19
+ ```
20
+
21
+ ### Prebuilt binaries
22
+
23
+ This package ships prebuilt Windows binaries. `npm install` should not require Visual Studio or node-gyp.
24
+
25
+ ### Building from source
26
+
27
+ If you need to build locally (contributors, unsupported Node ABI), install the Windows build tools
28
+ and run:
29
+
30
+ ```bash
31
+ npm run build
32
+ ```
33
+
34
+ Note: the `packages/runtime/irsdk_1_19/` folder contains iRacing SDK headers and sources required
35
+ to compile the native addon locally. It is intentionally excluded from npm packages and GitHub to
36
+ avoid redistributing the SDK contents. Place the SDK sources in `packages/runtime/irsdk_1_19/`
37
+ before building from source.
38
+
39
+ ## Quick start
40
+
41
+ ```js
42
+ const { IRacingClient } = require('node-iracing-sdk');
43
+
44
+ const client = new IRacingClient({
45
+ pollIntervalMs: 16,
46
+ waitTimeoutMs: 0,
47
+ telemetryVariables: ['Speed', 'RPM', 'Lap', 'Gear']
48
+ });
49
+
50
+ client.on('connect', () => {
51
+ console.log('Connected to iRacing');
52
+ });
53
+
54
+ client.on('disconnect', () => {
55
+ console.log('Disconnected from iRacing');
56
+ });
57
+
58
+ client.on('session', ({ updateCount, sessionInfo }) => {
59
+ console.log('Session info update', updateCount, sessionInfo.WeekendInfo?.TrackName);
60
+ });
61
+
62
+ client.on('telemetry', (data) => {
63
+ console.log('Telemetry', data);
64
+ });
65
+
66
+ client.on('error', (err) => {
67
+ console.error('Telemetry error', err);
68
+ });
69
+
70
+ client.start();
71
+ ```
72
+
73
+ ## API
74
+
75
+ ### Exports
76
+
77
+ ```js
78
+ const { IRacingClient, constants } = require('node-iracing-sdk');
79
+
80
+ // Local development:
81
+ // const { IRacingClient, constants } = require('./');
82
+ ```
83
+
84
+ ### `new IRacingClient(options)`
85
+
86
+ Create a polling client that emits events.
87
+
88
+ Options:
89
+ - `pollIntervalMs` (number): Polling cadence in milliseconds. Default: `16`.
90
+ - `waitTimeoutMs` (number): Timeout passed to native wait call. `0` = non-blocking. Default: `0`.
91
+ - `telemetryVariables` (string[]): List of telemetry variables to read each tick. If omitted, all telemetry values are returned. Default: `undefined`.
92
+ - `emitSessionOnConnect` (boolean): Emit a session snapshot immediately after connect. Default: `true`.
93
+
94
+ ### Events
95
+
96
+ - `connect`: Fired once when the SDK connection becomes active.
97
+ - `disconnect`: Fired once when the SDK connection is lost.
98
+ - `session`: Fired when the session info string changes. Payload:
99
+ - `updateCount` (number): Session info update counter.
100
+ - `sessionInfo` (object): Parsed session info JSON object.
101
+ - `telemetry`: Fired on each telemetry tick with telemetry data (object).
102
+ - `error`: Fired on native or parsing errors (Error).
103
+
104
+ ### Client methods
105
+
106
+ #### `start()`
107
+ Start the polling loop.
108
+
109
+ #### `stop()`
110
+ Stop the polling loop.
111
+
112
+ #### `setTelemetryVariables(names)`
113
+ Replace the list of telemetry variables to read each tick. Passing an empty array disables telemetry emission.
114
+
115
+ #### `isConnected()`
116
+ Returns `true` if the SDK connection is active.
117
+
118
+ #### `getStatusId()`
119
+ Returns the SDK status ID, which increments on reconnects.
120
+
121
+ #### `getSessionInfoObj()`
122
+ Returns the parsed session info object, or `null` if unavailable.
123
+
124
+ #### `readVars(names)`
125
+ Read telemetry values for the provided list of variable names (or the configured list if `names` is omitted).
126
+
127
+ #### `readAllVars()`
128
+ Read all telemetry values into a JS object keyed by variable name. Returns `null` if the SDK is not connected.
129
+
130
+ #### `getVarHeaders()`
131
+ Return telemetry variable metadata from the SDK as an array of objects:
132
+ `{ name, type, count, offset, countAsTime, desc, unit }`.
133
+
134
+ #### `getVarValue(name, entry)`
135
+ Read a single telemetry variable value. Optional `entry` selects array index for multi-entry variables.
136
+
137
+ #### `broadcastMsg(msg, var1, var2, var3)`
138
+ Low-level broadcast wrapper. Sends an iRacing broadcast message with either 2 or 3 integer parameters.
139
+
140
+ #### `broadcastMsgFloat(msg, var1, value)`
141
+ Low-level broadcast wrapper for float values (used by FFB commands).
142
+
143
+ #### `switchCameraByPos(carPos, group, camera)`
144
+ Switch camera using a car position.
145
+
146
+ #### `switchCameraByNum(driverNum, group, camera)`
147
+ Switch camera using a driver number. `driverNum` can be a number or a numeric string to preserve leading zeros (for example `"001"`).
148
+
149
+ #### `setCameraState(cameraState)`
150
+ Set the camera system state (bitflags).
151
+
152
+ #### `replaySetPlaySpeed(speed, slowMotion = 0)`
153
+ Set replay playback speed.
154
+
155
+ #### `replaySetPlayPosition(mode, frameNumber)`
156
+ Set replay playback position using a frame number.
157
+
158
+ #### `replaySearch(mode)`
159
+ Search the replay tape.
160
+
161
+ #### `replaySetState(state)`
162
+ Set replay tape state (e.g., erase).
163
+
164
+ #### `reloadTextures(mode, carIdx = 0)`
165
+ Reload textures for all cars or a specific car index.
166
+
167
+ #### `sendChatCommand(command, subCommand = 0)`
168
+ Send a chat command (macro, begin chat, reply, cancel).
169
+
170
+ #### `sendPitCommand(command, parameter = 0)`
171
+ Send a pit command (fuel, tires, windshield, fast repair, etc.).
172
+
173
+ #### `sendTelemCommand(command)`
174
+ Start/stop/restart telemetry recording.
175
+
176
+ #### `sendFFBCommand(command, value)`
177
+ Send force feedback command (float value).
178
+
179
+ #### `replaySearchSessionTime(sessionNum, sessionTimeMs)`
180
+ Search replay by session time (ms).
181
+
182
+ #### `videoCapture(mode)`
183
+ Trigger video capture actions (screenshot, start/stop, show timer).
184
+
185
+ ### Constants
186
+
187
+ All enum values are exported under `constants` for convenience:
188
+ - `constants.BroadcastMsg`
189
+ - `constants.ChatCommandMode`
190
+ - `constants.PitCommandMode`
191
+ - `constants.TelemCommandMode`
192
+ - `constants.FFBCommandMode`
193
+ - `constants.CameraState`
194
+ - `constants.ReplaySearchMode`
195
+ - `constants.ReplayPositionMode`
196
+ - `constants.ReplayStateMode`
197
+ - `constants.ReloadTexturesMode`
198
+ - `constants.VideoCaptureMode`
199
+ - `constants.CameraFocusMode`
200
+
201
+ ## Examples
202
+
203
+ ### Receive all telemetry values
204
+
205
+ ```js
206
+ const { IRacingClient } = require('node-iracing-sdk');
207
+
208
+ const client = new IRacingClient({
209
+ pollIntervalMs: 16,
210
+ waitTimeoutMs: 0
211
+ });
212
+
213
+ client.on('telemetry', (data) => {
214
+ console.log('All telemetry keys', Object.keys(data));
215
+ });
216
+
217
+ client.start();
218
+ ```
219
+
220
+ ### Read a custom telemetry list
221
+
222
+ ```js
223
+ const { IRacingClient } = require('node-iracing-sdk');
224
+
225
+ const client = new IRacingClient({
226
+ telemetryVariables: ['Speed', 'RPM', 'Gear']
227
+ });
228
+
229
+ client.on('telemetry', (data) => {
230
+ console.log('Speed', data.Speed, 'RPM', data.RPM, 'Gear', data.Gear);
231
+ });
232
+
233
+ client.start();
234
+ ```
235
+
236
+ ### Send a chat macro
237
+
238
+ ```js
239
+ const { IRacingClient, constants } = require('node-iracing-sdk');
240
+
241
+ const client = new IRacingClient();
242
+
243
+ client.on('connect', () => {
244
+ client.sendChatCommand(constants.ChatCommandMode.Macro, 1);
245
+ });
246
+
247
+ client.start();
248
+ ```
249
+
250
+ ### Request fuel and change tires
251
+
252
+ ```js
253
+ const { IRacingClient, constants } = require('node-iracing-sdk');
254
+
255
+ const client = new IRacingClient();
256
+
257
+ client.on('connect', () => {
258
+ client.sendPitCommand(constants.PitCommandMode.Clear);
259
+ client.sendPitCommand(constants.PitCommandMode.Fuel, 20);
260
+ client.sendPitCommand(constants.PitCommandMode.LF, 165);
261
+ client.sendPitCommand(constants.PitCommandMode.RF, 165);
262
+ client.sendPitCommand(constants.PitCommandMode.LR, 165);
263
+ client.sendPitCommand(constants.PitCommandMode.RR, 165);
264
+ });
265
+
266
+ client.start();
267
+ ```
268
+
269
+ ### Switch cameras
270
+
271
+ ```js
272
+ const { IRacingClient, constants } = require('node-iracing-sdk');
273
+
274
+ const client = new IRacingClient();
275
+
276
+ client.on('connect', () => {
277
+ client.switchCameraByNum(0, 1, 1);
278
+ client.setCameraState(constants.CameraState.CamToolActive);
279
+ });
280
+
281
+ client.start();
282
+ ```
283
+
284
+ ### Replay control
285
+
286
+ ```js
287
+ const { IRacingClient, constants } = require('node-iracing-sdk');
288
+
289
+ const client = new IRacingClient();
290
+
291
+ client.on('connect', () => {
292
+ client.replaySetPlaySpeed(1, 0);
293
+ client.replaySearch(constants.ReplaySearchMode.PrevIncident);
294
+ client.replaySetPlayPosition(constants.ReplayPositionMode.Current, 120000);
295
+ });
296
+
297
+ client.start();
298
+ ```
299
+
300
+ ### Video capture
301
+
302
+ ```js
303
+ const { IRacingClient, constants } = require('node-iracing-sdk');
304
+
305
+ const client = new IRacingClient();
306
+
307
+ client.on('connect', () => {
308
+ client.videoCapture(constants.VideoCaptureMode.TriggerScreenShot);
309
+ });
310
+
311
+ client.start();
312
+ ```
313
+
314
+ ### List telemetry variables with metadata
315
+
316
+ ```js
317
+ const { IRacingClient } = require('node-iracing-sdk');
318
+
319
+ const client = new IRacingClient();
320
+
321
+ client.on('connect', () => {
322
+ const vars = client.getVarHeaders();
323
+ console.log('Telemetry var count', vars.length);
324
+ console.log(vars[0]);
325
+ });
326
+
327
+ client.start();
328
+ ```
329
+
330
+ ## Notes
331
+
332
+ - Windows only: the iRacing SDK relies on Windows shared memory APIs.
333
+ - Session info is parsed in the native layer and emitted as a JSON object.
334
+ - Omit `telemetryVariables` to receive all telemetry values each tick.
335
+ - Use `telemetryVariables` to control which telemetry values are polled.
336
+ - If the SDK is disconnected, `readAllVars()` returns `null` and no telemetry events fire.
package/binding.gyp ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "irsdk_native",
5
+ "include_dirs": [
6
+ "irsdk_1_19"
7
+ ],
8
+ "defines": [
9
+ "NAPI_VERSION=10"
10
+ ],
11
+ "cflags_cc": [
12
+ "-std=c++17"
13
+ ],
14
+ "msvs_settings": {
15
+ "VCCLCompilerTool": {
16
+ "AdditionalOptions": ["/std:c++17"]
17
+ }
18
+ },
19
+ "conditions": [
20
+ [
21
+ "OS=='win'",
22
+ {
23
+ "sources": [
24
+ "src/addon.cpp",
25
+ "irsdk_1_19/irsdk_client.cpp",
26
+ "irsdk_1_19/irsdk_utils.cpp",
27
+ "irsdk_1_19/yaml_parser.cpp"
28
+ ]
29
+ },
30
+ {
31
+ "sources": [
32
+ "src/addon_stub.cpp"
33
+ ]
34
+ }
35
+ ]
36
+ ]
37
+ }
38
+ ]
39
+ }