### Install iracing-sdk-js Source: https://context7.com/friss/iracing-sdk-js/llms.txt Install the iracing-sdk-js package using npm or yarn. A working node-gyp setup is required for compiling native C++ bindings. ```bash npm install --save iracing-sdk-js # or yarn add iracing-sdk-js ``` -------------------------------- ### play Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Starts playing the replay. ```APIDOC ### play() Play replay **Kind**: global function ```js iracing.playbackControls.play() ``` ``` -------------------------------- ### Get Initialized SDK Instance Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Retrieves the already initialized instance of the SDK. This is the recommended way to get the SDK instance after initialization. ```javascript const irsdk = require('iracing-sdk-js')const iracing = irsdk.getInstance() ``` -------------------------------- ### Get SDK singleton instance Source: https://context7.com/friss/iracing-sdk-js/llms.txt Retrieve the already-initialized SDK singleton instance. If init() was not called, this bootstraps a default instance. ```javascript const irsdk = require('iracing-sdk-js') // In a separate module, after init() was called elsewhere const iracing = irsdk.getInstance() console.log('Connected:', iracing.connected) ``` -------------------------------- ### Start, Stop, or Restart IBT Telemetry Recording Source: https://context7.com/friss/iracing-sdk-js/llms.txt Use `execTelemetryCmd` to control iRacing's disk-based telemetry logging. Options include 'start', 'stop', and 'restart' to rotate the current file. ```javascript // Start recording iracing.execTelemetryCmd('start') ``` ```javascript // Stop recording iracing.execTelemetryCmd('stop') ``` ```javascript // Rotate: close the current file and open a new one iracing.execTelemetryCmd('restart') ``` -------------------------------- ### iracing.on('Connected') Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listen for the 'Connected' event, which is emitted when the iRacing simulator is started and the SDK establishes a connection. ```APIDOC ## iracing.on('Connected', callback) ### Description iRacing, sim, is started. ### Kind event emitted by [iracing](#iracing) ### Request Example ```js iracing.on('Connected', function (evt) { console.log(evt)}) ``` ``` -------------------------------- ### irsdk.getInstance Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Retrieves the initialized instance of JsIrSdk. Use this method after irsdk.init() has been called to get the active SDK instance. ```APIDOC ## irsdk.getInstance() ### Description Get initialized instance of JsIrSdk. ### Method static ### Parameters None ### Request Example ```javascript const irsdk = require('iracing-sdk-js') const iracing = irsdk.getInstance() ``` ### Response #### Success Response (iracing) Returns the running instance of JsIrSdk. #### Response Example ```javascript // iracing instance object ``` ``` -------------------------------- ### Initialize SDK with Telemetry Update Interval Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Initializes the SDK and sets a custom interval for telemetry updates. Ensure Node.js v21 or later is installed. ```javascript const irsdk = require('iracing-sdk-js')// look for telemetry updates only once per 100 msconst iracing = irsdk.init({telemetryUpdateInterval: 100}) ``` -------------------------------- ### Get iRacing SDK Instance and Constants Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Instantiates the iRacing SDK and accesses its constants. This is typically the first step to use the SDK. ```javascript var IrSdkConsts = require('node-irsdk').getInstance().Consts ``` -------------------------------- ### iracing.execTelemetryCmd(cmd) Source: https://context7.com/friss/iracing-sdk-js/llms.txt Controls iRacing's disk-based telemetry recording (.ibt files). Accepts 'start', 'stop', or 'restart' commands. ```APIDOC ## iracing.execTelemetryCmd(cmd) ### Description Starts, stops, or restarts iRacing's disk-based telemetry logging (`.ibt` files). ### Method `execTelemetryCmd(cmd: 'start' | 'stop' | 'restart')` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Start recording iracing.execTelemetryCmd('start') // Stop recording iracing.execTelemetryCmd('stop') // Rotate: close the current file and open a new one iracing.execTelemetryCmd('restart') ``` ### Response None ### Error Handling None explicitly documented. ``` -------------------------------- ### Execute Telemetry Command Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Controls the iRacing telemetry logging to an IBT file. Use 'start', 'stop', or 'restart' commands. ```javascript iracing.execTelemetryCmd('restart') ``` -------------------------------- ### Search Replay by Timestamp Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Jump to a specific point in the replay using session number and session time in milliseconds. For example, to jump to the 2nd minute of the 3rd session. ```javascript // jump to 2nd minute of 3rd sessioniracing.playbackControls.searchTs(2, 2*60*1000) ``` -------------------------------- ### Handle Connected Event Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listens for the 'Connected' event, which signifies that the iRacing simulator has started and is available. This is useful for initializing actions upon connection. ```javascript iracing.on('Connected', function (evt) { console.log(evt) }) ``` -------------------------------- ### Search Replay Events Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Initiate a search within the replay based on the specified search mode. For example, to find the next incident. ```javascript iracing.playbackControls.search('nextIncident') ``` -------------------------------- ### Access session and race metadata Source: https://context7.com/friss/iracing-sdk-js/llms.txt The 'SessionInfo' event provides parsed data about the current race session, including driver lists, track details, and car setup information. ```javascript iracing.on('SessionInfo', (evt) => { const info = evt.data // Print all drivers in the session info.DriverInfo.Drivers.forEach((driver) => { console.log( `#${driver.CarNumber} ${driver.UserName} (${driver.TeamName})`, `iRating: ${driver.IRating}`, `License: ${driver.LicString}` ) }) // Print track details const w = info.WeekendInfo console.log(`Track: ${w.TrackDisplayName} (${w.TrackLength})`) console.log(`Event: ${w.EventType}, Category: ${w.Category}`) }) ``` -------------------------------- ### Event: SessionInfo Source: https://context7.com/friss/iracing-sdk-js/llms.txt Fires when iRacing updates its session YAML blob, providing a parsed `data` object with details on drivers, cameras, track information, results, and car setups. ```APIDOC ### Event: SessionInfo — Access race/session metadata Fires when iRacing updates its session YAML blob. The parsed `data` object contains driver lists, camera groups, track details, timing results, and car setup info. ```js iracing.on('SessionInfo', (evt) => { const info = evt.data // Print all drivers in the session info.DriverInfo.Drivers.forEach((driver) => { console.log( `#${driver.CarNumber} ${driver.UserName} (${driver.TeamName})`, `iRating: ${driver.IRating}`, `License: ${driver.LicString}` ) }) // Print track details const w = info.WeekendInfo console.log(`Track: ${w.TrackDisplayName} (${w.TrackLength})`) console.log(`Event: ${w.EventType}, Category: ${w.Category}`) }) ``` ``` -------------------------------- ### Inspect telemetry variable descriptions Source: https://context7.com/friss/iracing-sdk-js/llms.txt Use the 'TelemetryDescription' event to get metadata for all available telemetry variables, including their names, units, and descriptions. This is useful for discovering available data fields. ```javascript iracing.on('TelemetryDescription', (data) => { // data is a map of variable name → description object Object.entries(data).forEach(([name, desc]) => { console.log(`${name}: ${desc.unit || '(no unit)'} — ${desc.desc}`) }) // Example output: // Speed: m/s — GPS vehicle speed // RPM: revs/min — Engine rpm // Throttle: % — 0=off throttle to 1=full throttle }) ``` -------------------------------- ### Instantiate JsIrSdk (Not Recommended) Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md This shows how to instantiate the JsIrSdk class directly, but it is not recommended. Use `irsdk.getInstance()` instead. ```javascript const iracing = require('iracing-sdk-js').getInstance() ``` -------------------------------- ### irsdk.getInstance() Source: https://context7.com/friss/iracing-sdk-js/llms.txt Retrieves the singleton SDK instance. If `init()` has not been called, it bootstraps a default instance without polling delays. ```APIDOC ## irsdk.getInstance() — Get the SDK singleton Returns the already-initialized `JsIrSdk` instance. If `init()` was never called, this bootstraps a default instance with no polling delays. ```js const irsdk = require('iracing-sdk-js') // In a separate module, after init() was called elsewhere const iracing = irsdk.getInstance() console.log('Connected:', iracing.connected) ``` ``` -------------------------------- ### irsdk.init([opts]) Source: https://context7.com/friss/iracing-sdk-js/llms.txt Initializes the SDK singleton, creating a JsIrSdk instance. It can accept optional arguments to configure the polling intervals for telemetry and session info updates. ```APIDOC ## irsdk.init([opts]) — Initialize the SDK singleton Creates (or returns an existing) `JsIrSdk` instance. Call once at startup before any `getInstance()` calls. Accepts optional polling intervals for telemetry and session info updates. ```js const irsdk = require('iracing-sdk-js') // Poll telemetry every 16 ms (~60 Hz), session info every 2 s const iracing = irsdk.init({ telemetryUpdateInterval: 16, sessionInfoUpdateInterval: 2000, }) console.log('SDK initialized, waiting for iRacing...') ``` ``` -------------------------------- ### Initialize SDK with custom intervals Source: https://context7.com/friss/iracing-sdk-js/llms.txt Initialize the SDK singleton with custom polling intervals for telemetry and session info updates. Call this once at startup. ```javascript const irsdk = require('iracing-sdk-js') // Poll telemetry every 16 ms (~60 Hz), session info every 2 s const iracing = irsdk.init({ telemetryUpdateInterval: 16, sessionInfoUpdateInterval: 2000, }) console.log('SDK initialized, waiting for iRacing...') ``` -------------------------------- ### irsdk.init Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Initializes the JsIrSdk. This method should be called once before using getInstance. It allows for configuration of update intervals for telemetry and session info, and provides an option for a custom session info parser. ```APIDOC ## irsdk.init([opts]) ### Description Initialize JsIrSdk, can be done once before using getInstance first time. ### Method static ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **opts** (Object) - Optional - Options object. - **opts.telemetryUpdateInterval** (Integer) - Optional - Telemetry update interval in milliseconds. Defaults to 0. - **opts.sessionInfoUpdateInterval** (Integer) - Optional - SessionInfo update interval in milliseconds. Defaults to 0. - **opts.sessionInfoParser** (sessionInfoParser) - Optional - Custom parser for session info. ### Request Example ```javascript const irsdk = require('iracing-sdk-js') // look for telemetry updates only once per 100 ms const iracing = irsdk.init({telemetryUpdateInterval: 100}) ``` ### Response #### Success Response (iracing) Returns the running instance of JsIrSdk. #### Response Example ```javascript // iracing instance object ``` ``` -------------------------------- ### Play Replay Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Initiates playback of the current replay. ```javascript iracing.playbackControls.play() ``` -------------------------------- ### iracing.on('update') Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listen for the generic 'update' event, which is emitted for any general update from the simulator. This can be used as a catch-all for various changes. ```APIDOC ## iracing.on('update', callback) ### Description any update event. ### Kind event emitted by [iracing](#iracing) ### Request Example ```js iracing.on('update', function (evt) { console.log(evt)}) ``` ``` -------------------------------- ### iracing.execCmd Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Executes a command with up to three arguments. This is a general-purpose command execution method for various iRacing commands. ```APIDOC ## iracing.execCmd(msgId, [arg1], [arg2], [arg3]) ### Description Executes a command with up to three arguments. ### Method instance ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **msgId** (any) - Required - The message ID of the command to execute. - **arg1** (any) - Optional - The first argument for the command. - **arg2** (any) - Optional - The second argument for the command. - **arg3** (any) - Optional - The third argument for the command. ### Request Example ```javascript // Example usage would depend on specific msgId and arguments // iracing.execCmd(someMsgId, arg1, arg2, arg3) ``` ### Response No specific response details provided in the source. ``` -------------------------------- ### iracing.execCmd Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Execute any of the available commands, excluding the FFB command. This method allows for a wide range of interactions with the iRacing simulator. ```APIDOC ## iracing.execCmd(msgId, [arg1], [arg2], [arg3]) ### Description Execute any of available commands, excl. FFB command. ### Method instance method of [iracing](#iracing) ### Parameters #### Path Parameters - **msgId** (Integer) - Required - Message id - **arg1** (Integer) - Optional - 1st argument - **arg2** (Integer) - Optional - 2nd argument - **arg3** (Integer) - Optional - 3rd argument ``` -------------------------------- ### iracing.on('SessionInfo') Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listen for the 'SessionInfo' event, which is emitted when session information is updated. This event provides details about the current racing session. ```APIDOC ## iracing.on('SessionInfo', callback) ### Description SessionInfo update. ### Kind event emitted by [iracing](#iracing) ### Request Example ```js iracing.on('SessionInfo', function (evt) { console.log(evt)}) ``` ``` -------------------------------- ### iracing.on('TelemetryDescription') Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listen for the 'TelemetryDescription' event, which is emitted when the telemetry description is available. This event provides details about the available telemetry values. ```APIDOC ## iracing.on('TelemetryDescription', callback) ### Description Telemetry description, contains description of available telemetry values. ### Kind event emitted by [iracing](#iracing) ### Request Example ```js iracing.on('TelemetryDescription', function (data) { console.log(evt)}) ``` ``` -------------------------------- ### `iracing.execPitCmd(cmd, [arg])` — Program pit stop strategy Source: https://context7.com/friss/iracing-sdk-js/llms.txt Sends pit service commands to iRacing, allowing applications to set fuel amounts, request specific tires, or clear pit selections. ```APIDOC ## `iracing.execPitCmd(cmd, [arg])` — Program pit stop strategy Sends pit service commands to iRacing, allowing applications to set fuel amounts, request specific tires, or clear pit selections. ```js // Clear all pit selections first iracing.execPitCmd('clear') // Request full tank (999 L effectively means "fill it") iracing.execPitCmd('fuel', 50) // 50 liters // Request all four tires with specific pressures (kPa) iracing.execPitCmd('lf', 172) // left front, 172 kPa iracing.execPitCmd('rf', 172) // right front iracing.execPitCmd('lr', 165) // left rear iracing.execPitCmd('rr', 165) // right rear // Request windshield tear-off and fast repair iracing.execPitCmd('ws') iracing.execPitCmd('fr') // Disable tire changes, keep fuel iracing.execPitCmd('clearTires') ``` ``` -------------------------------- ### fastForward Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Fast-forwards the replay. An optional speed parameter can be provided. ```APIDOC ### fastForward([speed]) fast-forward replay **Kind**: global function | Param | Type | Default | Description | | --- | --- | --- | --- | | [speed] | Integer | 2 | FF speed, something between 2-16 works | ```js iracing.playbackControls.fastForward() // double speed FF ``` ``` -------------------------------- ### Fast Forward Replay Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Advances the replay playback at a specified speed. Defaults to 2x speed. ```javascript iracing.playbackControls.fastForward() // double speed FF ``` -------------------------------- ### Handle iRacing connection events Source: https://context7.com/friss/iracing-sdk-js/llms.txt Listen for the 'Connected' event to detect when iRacing launches and shared memory becomes available. Use 'once' for cleanup on 'Disconnected'. ```javascript const irsdk = require('iracing-sdk-js') const iracing = irsdk.init({ telemetryUpdateInterval: 100, sessionInfoUpdateInterval: 1000 }) iracing.on('Connected', () => { console.log('iRacing is running!') // Clean up when iRacing shuts down iracing.once('Disconnected', () => { console.log('iRacing closed.') process.exit(0) }) }) ``` -------------------------------- ### Set Camera State with Flags Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Use this to change camera tool states, such as hiding the UI or enabling mouse aim mode. Combine flags using the bitwise OR operator. ```javascript var States = iracing.Consts.CameraState var state = States.CamToolActive | States.UIHidden | States.UseMouseAimMode iracing.camControls.setState(state) ``` -------------------------------- ### Navigate Replay by Frame Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Move to a specific frame in the replay. The frame number can be relative to the current, beginning, or end of the replay. ```javascript iracing.playbackControls.searchFrame(1, 'current') // go to 1 frame forward ``` -------------------------------- ### Event: TelemetryDescription Source: https://context7.com/friss/iracing-sdk-js/llms.txt Fired once per connection, this event provides metadata about each telemetry variable, including its name, unit, and description, useful for discovering available fields. ```APIDOC ### Event: TelemetryDescription — Inspect available telemetry variables Fired once per connection with metadata about every telemetry variable (name, unit, description). Useful for discovering what fields iRacing exposes in the current session. ```js iracing.on('TelemetryDescription', (data) => { // data is a map of variable name → description object Object.entries(data).forEach(([name, desc]) => { console.log(`${name}: ${desc.unit || '(no unit)'} — ${desc.desc}`) }) // Example output: // Speed: m/s — GPS vehicle speed // RPM: revs/min — Engine rpm // Throttle: % — 0=off throttle to 1=full throttle }) ``` ``` -------------------------------- ### setState Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Changes the camera tool state. This can be used to hide the UI or enable mouse aiming. ```APIDOC ### setState(state) Change camera tool state **Kind**: global function | Param | Type | Description | | --- | --- | --- | | state | [CameraState](#IrSdkConsts.CameraState) | new state | ```js // hide UI and enable mouse aimvar States = iracing.Consts.CameraStatevar state = States.CamToolActive | States.UIHidden | States.UseMouseAimModeiracing.camControls.setState(state) ``` ``` -------------------------------- ### iracing.on('Telemetry') Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listen for the 'Telemetry' event, which is emitted with each telemetry update. This event provides real-time telemetry data from the simulator. ```APIDOC ## iracing.on('Telemetry', callback) ### Description Telemetry update. ### Kind event emitted by [iracing](#iracing) ### Request Example ```js iracing.on('Telemetry', function (evt) { console.log(evt)}) ``` ``` -------------------------------- ### IrSdkConsts.RpySrchMode Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Enum for replay search modes. ```APIDOC ## IrSdkConsts.RpySrchMode ### Properties - **ToStart** (0) - **ToEnd** (1) - **PrevSession** (2) - **NextSession** (3) - **PrevLap** (4) - **NextLap** (5) - **PrevFrame** (6) - **NextFrame** (7) - **PrevIncident** (8) - **NextIncident** (9) ``` -------------------------------- ### Execute Chat Command Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Executes a chat command within the simulator. Use this to interact with the chat system, such as closing the chat window. ```javascript iracing.execChatCmd('cancel') // close chat window ``` -------------------------------- ### IrSdkConsts.RpyStateMode Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Enum for replay state modes. ```APIDOC ## IrSdkConsts.RpyStateMode ### Properties - **EraseTape** (0) - Clear any data in the replay tape (works only if replay spooling disabled) ``` -------------------------------- ### `iracing.camControls.switchToPos(position, [camGroupNum], [camNum])` — Focus camera on a race position Source: https://context7.com/friss/iracing-sdk-js/llms.txt Switches the camera to focus on the car running in a given race position (e.g., P1, P2). ```APIDOC ## `iracing.camControls.switchToPos(position, [camGroupNum], [camNum])` — Focus camera on a race position Switches the camera to focus on the car running in a given race position (P1, P2, etc.). ```js // Show the car in P1 iracing.camControls.switchToPos(1) // Show P3 using camera group 5, camera 2 iracing.camControls.switchToPos(3, 5, 2) ``` ``` -------------------------------- ### IrSdkConsts.ChatCommand Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Enum for chat commands. Use these constants to control chat window behavior. ```APIDOC ## IrSdkConsts.ChatCommand **Kind**: static enum of [IrSdkConsts](#IrSdkConsts) **Properties** | Name | Default | Description | | --- | --- | --- | | Macro | 0 | Macro, give macro num (0-15) as argument | | BeginChat | 1 | Open up a new chat window | | Reply | 2 | Reply to last private chat | | Cancel | 3 | Close chat window | ``` -------------------------------- ### Handle Generic Update Events in JavaScript Source: https://context7.com/friss/iracing-sdk-js/llms.txt Use the 'update' event for a unified handler of all SDK events like Connected, Disconnected, Telemetry, SessionInfo, and more. This is useful when you need a single point of contact for all SDK state changes. ```javascript iracing.on('update', (evt) => { switch (evt.type) { case 'Connected': console.log('Connected at', evt.timestamp) break case 'Telemetry': console.log('Speed:', evt.data.Speed, 'm/s') break case 'SessionInfo': console.log('Session updated:', evt.data.WeekendInfo.TrackName) break case 'Disconnected': console.log('Disconnected at', evt.timestamp) break } }) ``` -------------------------------- ### Switch Camera to Position Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Switch the camera to focus on a specific track position, such as P2. Optionally specify camera group and number. ```javascript iracing.camControls.switchToPos(2) // show P2 ``` -------------------------------- ### `iracing.execChatCmd(cmd, [arg])` / `iracing.execChatMacro(num)` — Chat and macros Source: https://context7.com/friss/iracing-sdk-js/llms.txt Opens, closes, or controls the in-sim chat window, and fires pre-configured chat macros (set up in iRacing's app.ini, slots 0–15). ```APIDOC ## `iracing.execChatCmd(cmd, [arg])` / `iracing.execChatMacro(num)` — Chat and macros Opens, closes, or controls the in-sim chat window, and fires pre-configured chat macros (set up in iRacing's app.ini, slots 0–15). ```js // Open a new chat window iracing.execChatCmd('beginChat') // Reply to the last private chat iracing.execChatCmd('reply') // Close/cancel the chat window iracing.execChatCmd('cancel') // Fire macro slot 3 (configured in iRacing) iracing.execChatMacro(3) ``` ``` -------------------------------- ### Event: Connected Source: https://context7.com/friss/iracing-sdk-js/llms.txt Emitted when the SDK detects that iRacing has launched and shared memory is available, indicating that iRacing is running. ```APIDOC ### Event: Connected — React when iRacing starts Emitted when the SDK detects that iRacing has launched and shared memory is available. ```js const irsdk = require('iracing-sdk-js') const iracing = irsdk.init({ telemetryUpdateInterval: 100, sessionInfoUpdateInterval: 1000 }) iracing.on('Connected', () => { console.log('iRacing is running!') // Clean up when iRacing shuts down iracing.once('Disconnected', () => { console.log('iRacing closed.') process.exit(0) }) }) ``` ``` -------------------------------- ### Program Pit Stop Strategy in JavaScript Source: https://context7.com/friss/iracing-sdk-js/llms.txt Send pit service commands to iRacing to set fuel levels, request specific tires with pressures, or clear pit selections. This enables automated pit stop management. ```javascript // Clear all pit selections first iracing.execPitCmd('clear') // Request full tank (999 L effectively means "fill it") iracing.execPitCmd('fuel', 50) // 50 liters // Request all four tires with specific pressures (kPa) iracing.execPitCmd('lf', 172) // left front, 172 kPa iracing.execPitCmd('rf', 172) // right front iracing.execPitCmd('lr', 165) // left rear iracing.execPitCmd('rr', 165) // right rear // Request windshield tear-off and fast repair iracing.execPitCmd('ws') iracing.execPitCmd('fr') // Disable tire changes, keep fuel iracing.execPitCmd('clearTires') ``` -------------------------------- ### iracing.execChatCmd Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Executes a chat command with an optional argument. Used for sending text commands through the in-game chat system. ```APIDOC ## iracing.execChatCmd(cmd, [arg]) ### Description Executes a chat command with an optional argument. ### Method instance ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **cmd** (any) - Required - The chat command to execute. - **arg** (any) - Optional - An argument for the chat command. ### Request Example ```javascript // Example: Sending a chat message // iracing.execChatCmd('chat', 'Hello everyone!') ``` ### Response No specific response details provided in the source. ``` -------------------------------- ### Handle Generic Update Event Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listens for the generic 'update' event, which is emitted for any significant change or update within the simulator. This can be used for general event monitoring. ```javascript iracing.on('update', function (evt) { console.log(evt) }) ``` -------------------------------- ### IrSdkConsts.RpyPosMode Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Enum for replay position modes. ```APIDOC ## IrSdkConsts.RpyPosMode ### Properties - **Begin** (0) - Frame number is relative to beginning - **Current** (1) - Frame number is relative to current frame - **End** (2) - Frame number is relative to end ``` -------------------------------- ### Process live telemetry data Source: https://context7.com/friss/iracing-sdk-js/llms.txt Subscribe to the 'Telemetry' event to receive live data frames. The event includes a timestamp and a 'values' object with various simulator metrics. ```javascript iracing.on('Telemetry', (evt) => { const v = evt.values console.log( `[${evt.timestamp.toISOString()}]`, `Speed: ${(v.Speed * 3.6).toFixed(1)} km/h`, `RPM: ${v.RPM.toFixed(0)}`, `Gear: ${v.Gear}`, `Throttle: ${(v.Throttle * 100).toFixed(0)}%`, `Brake: ${(v.Brake * 100).toFixed(0)}%`, `Lap: ${v.Lap}`, `LapDist%: ${(v.LapDistPct * 100).toFixed(2)}%`, `TrackSurface: ${v.PlayerTrackSurface}`, `Flags: ${v.SessionFlags.join(', ')}` ) }) ``` -------------------------------- ### Reload All Car Textures Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Use this method to reload all car textures. This can be useful after applying custom paints. ```javascript iracing.reloadTextures() // reload all paints ``` -------------------------------- ### pause Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Pauses the replay. ```APIDOC ### pause() Pause replay **Kind**: global function ```js iracing.playbackControls.pause() ``` ``` -------------------------------- ### IrSdkConsts.TelemCommand Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Enum for telemetry commands. Use these constants to control telemetry recording. ```APIDOC ## IrSdkConsts.TelemCommand **Kind**: static enum of [IrSdkConsts](#IrSdkConsts) **Properties** | Name | Default | Description | | --- | --- | --- | | Stop | 0 | Turn telemetry recording off | | Start | 1 | Turn telemetry recording on | | Restart | 2 | Write current file to disk and start a new one | ``` -------------------------------- ### Refresh Car Paints with reloadTextures() or reloadTexture() Source: https://context7.com/friss/iracing-sdk-js/llms.txt Forces iRacing to reload car livery textures from disk. Use `reloadTextures()` to refresh all paints or `reloadTexture(carIdx)` for a specific car. ```javascript // Reload all car paints at once iracing.reloadTextures() ``` ```javascript // Reload only the paint for the car at index 3 iracing.reloadTexture(3) ``` -------------------------------- ### iracing.on('Disconnected') Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listen for the 'Disconnected' event, which is emitted when the iRacing simulator is closed and the SDK connection is terminated. ```APIDOC ## iracing.on('Disconnected', callback) ### Description iRacing, sim, was closed. ### Kind event emitted by [iracing](#iracing) ### Request Example ```js iracing.on('Disconnected', function (evt) { console.log(evt)}) ``` ``` -------------------------------- ### switchToPos Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Switches the camera to focus on a specific position in the race. Optionally, you can specify the camera group and camera number. ```APIDOC ### switchToPos(position, [camGroupNum], [camNum]) Switch camera, focus on position **Kind**: global function | Param | Type | Description | | --- | --- | --- | | position | Integer | [CamFocusAt](#IrSdkConsts.CamFocusAt) | Position to focus on | | [camGroupNum] | Integer | Select camera group | | [camNum] | Integer | Select camera | ```js iracing.camControls.switchToPos(2) // show P2 ``` ``` -------------------------------- ### Set iRacing Camera Tool State Flags in JavaScript Source: https://context7.com/friss/iracing-sdk-js/llms.txt Control the active state of the camera tool using a bitmask. Combine values from `iracing.Consts.CameraState` to enable features like camera tool activation, UI hiding, and mouse-aim mode. ```javascript const States = iracing.Consts.CameraState // Activate camera tool, hide UI, enable mouse-aim mode const newState = States.CamToolActive | States.UIHidden | States.UseMouseAimMode iracing.camControls.setState(newState) // Enable auto-shot selection and temporary edits iracing.camControls.setState(States.UseAutoShotSelection | States.UseTemporaryEdits) ``` -------------------------------- ### iracing.execChatCmd Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Execute a chat command. This method is used for sending commands related to the in-game chat system. ```APIDOC ## iracing.execChatCmd(cmd, [arg]) ### Description Execute chat command. ### Method instance method of [iracing](#iracing) ### Parameters #### Path Parameters - **cmd** ([ChatCommand](#IrSdkConsts.ChatCommand)) - Required - - **arg** (Integer) - Optional - Command argument, if needed ### Request Example ```js iracing.execChatCmd('cancel') // close chat window ``` ``` -------------------------------- ### Handle SessionInfo Update Event Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listens for the 'SessionInfo' event to receive updates on the current session's information. This includes details about the race, track, and drivers. ```javascript iracing.on('SessionInfo', function (evt) { console.log(evt) }) ``` -------------------------------- ### Execute Chat Macro Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Executes a predefined chat macro by its number. Macros can be used for quick communication. ```javascript iracing.execChatMacro(1) // macro 1 ``` -------------------------------- ### iracing.reloadTextures() / iracing.reloadTexture(carIdx) Source: https://context7.com/friss/iracing-sdk-js/llms.txt Forces iRacing to reload car livery textures from disk. Useful after updating paint files externally. ```APIDOC ## iracing.reloadTextures() / iracing.reloadTexture(carIdx) ### Description Forces iRacing to reload car livery textures from disk—useful after a paint file has been updated externally. ### Method `reloadTextures()` or `reloadTexture(carIdx: number)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Reload all car paints at once iracing.reloadTextures() // Reload only the paint for the car at index 3 iracing.reloadTexture(3) ``` ### Response None ### Error Handling None explicitly documented. ``` -------------------------------- ### Rewind Replay Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Rewinds the replay playback at a specified speed. Defaults to 2x speed. ```javascript iracing.playbackControls.rewind() // double speed RW ``` -------------------------------- ### Execute Pit Command Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Executes various pit lane commands, such as clearing settings, fueling, or changing tires. Arguments specify the command details. ```javascript // full tank, no tires, no tear off iracing.execPitCmd('clear') iracing.execPitCmd('fuel', 999) // 999 liters iracing.execPitCmd('lf') // new left front iracing.execPitCmd('lr', 200) // new left rear, 200 kPa ``` -------------------------------- ### iracing.execChatMacro Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Executes a chat macro by its number. Macros are pre-defined chat messages that can be triggered by a number. ```APIDOC ## iracing.execChatMacro(num) ### Description Executes a chat macro by its number. ### Method instance ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **num** (any) - Required - The number of the chat macro to execute. ### Request Example ```javascript // Example: Executing chat macro number 1 // iracing.execChatMacro(1) ``` ### Response No specific response details provided in the source. ``` -------------------------------- ### Handle TelemetryDescription Event Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Listens for the 'TelemetryDescription' event to receive information about available telemetry values. This event provides the schema for telemetry data. ```javascript iracing.on('TelemetryDescription', function (data) { console.log(evt) }) ``` -------------------------------- ### rewind Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Rewinds the replay. An optional speed parameter can be provided. ```APIDOC ### rewind([speed]) rewind replay **Kind**: global function | Param | Type | Default | Description | | --- | --- | --- | --- | | [speed] | Integer | 2 | RW speed, something between 2-16 works | ```js iracing.playbackControls.rewind() // double speed RW ``` ``` -------------------------------- ### Control Replay Playback in JavaScript Source: https://context7.com/friss/iracing-sdk-js/llms.txt Manage iRacing's replay system using methods for play, pause, speed adjustments, slow-motion, and seeking by frame or timestamp. This allows for programmatic control over replay navigation. ```javascript // Standard playback iracing.playbackControls.play() iracing.playbackControls.pause() // Fast-forward at 4× speed, then rewind at 2× (default) iracing.playbackControls.fastForward(4) iracing.playbackControls.rewind() // Slow motion: half speed forward, then half speed backward iracing.playbackControls.slowForward(2) iracing.playbackControls.slowBackward(2) // Search replay for next incident iracing.playbackControls.search('nextIncident') // Jump to the 2-minute mark of session 0 iracing.playbackControls.searchTs(0, 2 * 60 * 1000) // Jump 10 frames forward from current position iracing.playbackControls.searchFrame(10, 'current') // Go to the very beginning iracing.playbackControls.searchFrame(0, 'begin') ``` -------------------------------- ### IrSdkConsts.CameraState Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Camera state enum for composing camera states. ```APIDOC ## IrSdkConsts.CameraState ### Description Camera state is bitfield; use these values to compose a new state. ### Properties - **IsSessionScreen** (1) - Is driver out of the car - **IsScenicActive** (2) - The scenic camera is active (no focus car) - **CamToolActive** (4) - Activate camera tool - **UIHidden** (8) - Hide UI - **UseAutoShotSelection** (16) - Enable auto shot selection - **UseTemporaryEdits** (32) - Enable temporary edits - **UseKeyAcceleration** (64) - Enable key acceleration - **UseKey10xAcceleration** (128) - Enable 10x key acceleration - **UseMouseAimMode** (256) - Enable mouse aim ``` -------------------------------- ### Event: `update` — Generic update bus Source: https://context7.com/friss/iracing-sdk-js/llms.txt A unified event that handles all SDK update types, including Connected, Disconnected, Telemetry, TelemetryDescription, and SessionInfo. This is useful for a single handler for all SDK events. ```APIDOC ## Event: `update` — Generic update bus A single unified event that wraps all update types (`Connected`, `Disconnected`, `Telemetry`, `TelemetryDescription`, `SessionInfo`). Use this when you want one handler for all SDK events. ```js iracing.on('update', (evt) => { switch (evt.type) { case 'Connected': console.log('Connected at', evt.timestamp) break case 'Telemetry': console.log('Speed:', evt.data.Speed, 'm/s') break case 'SessionInfo': console.log('Session updated:', evt.data.WeekendInfo.TrackName) break case 'Disconnected': console.log('Disconnected at', evt.timestamp) break } }) ``` ``` -------------------------------- ### Control In-Sim Chat and Macros in JavaScript Source: https://context7.com/friss/iracing-sdk-js/llms.txt Manage the in-sim chat window by opening, closing, or replying to messages. You can also fire pre-configured chat macros using their slot numbers (0-15). ```javascript // Open a new chat window iracing.execChatCmd('beginChat') // Reply to the last private chat iracing.execChatCmd('reply') // Close/cancel the chat window iracing.execChatCmd('cancel') // Fire macro slot 3 (configured in iRacing) iracing.execChatMacro(3) ``` -------------------------------- ### search Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Searches for specific events or points within the replay based on the provided search mode. ```APIDOC ## search(searchMode) ### Description Searches for specific events or points within the replay. ### Method N/A (JavaScript function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **searchMode** (RpySrchMode) - Required - Specifies what to search for. ### Request Example ```js iracing.playbackControls.search('nextIncident') ``` ### Response N/A ``` -------------------------------- ### Focus Camera on a Race Position in JavaScript Source: https://context7.com/friss/iracing-sdk-js/llms.txt Direct the iRacing camera to focus on the car occupying a specific race position (e.g., P1, P2). Optionally, you can specify the camera group and camera number. ```javascript // Show the car in P1 iracing.camControls.switchToPos(1) // Show P3 using camera group 5, camera 2 iracing.camControls.switchToPos(3, 5, 2) ``` -------------------------------- ### IrSdkConsts.CamFocusAt Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Enum for camera focus targets. Use these when switching cameras instead of car number or position. ```APIDOC ## IrSdkConsts.CamFocusAt When switching camera, these can be used instead of car number / position **Kind**: static enum of [IrSdkConsts](#IrSdkConsts) **Properties** | Name | Default | Description | | --- | --- | --- | | Incident | -3 | | | Leader | -2 | | | Exciting | -1 | | | Driver | 0 | Use car number / position instead of this | ``` -------------------------------- ### iracing.Consts Source: https://context7.com/friss/iracing-sdk-js/llms.txt Provides access to all iRacing SDK enumerations as JavaScript objects for use as constants. ```APIDOC ## iracing.Consts ### Description Exposes all iRacing SDK enumerations as plain JavaScript objects. These can be used as numeric constants or string keys in higher-level command helpers. ### Method `iracing.Consts` ### Parameters None ### Request Example ```javascript const iracing = require('iracing-sdk-js').getInstance() const C = iracing.Consts // BroadcastMsg IDs console.log(C.BroadcastMsg.CamSwitchPos) // 0 console.log(C.BroadcastMsg.PitCommand) // 9 console.log(C.BroadcastMsg.TelemCommand) // 10 // CameraState bitfield values console.log(C.CameraState.UIHidden) // 8 console.log(C.CameraState.CamToolActive) // 4 // Replay search modes console.log(C.RpySrchMode.NextIncident) // 9 console.log(C.RpySrchMode.NextLap) // 5 // Pit command IDs console.log(C.PitCommand.Fuel) // 2 console.log(C.PitCommand.LF) // 3 // CamFocusAt special targets console.log(C.CamFocusAt.Leader) // -2 console.log(C.CamFocusAt.Incident) // -3 // Use raw execCmd with constants iracing.execCmd(C.BroadcastMsg.ReplaySearch, C.RpySrchMode.PrevIncident) ``` ### Response None ### Error Handling None explicitly documented. ``` -------------------------------- ### searchFrame Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Moves the replay playback to a specific frame number. Frame counting can be relative to the beginning, end, or current frame. ```APIDOC ## searchFrame(frameNum, rpyPosMode) ### Description Moves the replay playback to a specific frame number. ### Method N/A (JavaScript function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **frameNum** (Integer) - Required - The frame number. - **rpyPosMode** (RpyPosMode) - Required - Specifies if the frame number is relative to the begin, end, or current frame. ### Request Example ```js iracing.playbackControls.searchFrame(1, 'current') // go to 1 frame forward ``` ### Response N/A ``` -------------------------------- ### `iracing.camControls.setState(state)` — Set camera tool state flags Source: https://context7.com/friss/iracing-sdk-js/llms.txt Controls the camera tool's active state using a bitmask composed from `iracing.Consts.CameraState` values. ```APIDOC ## `iracing.camControls.setState(state)` — Set camera tool state flags Controls the camera tool's active state using a bitmask composed from `iracing.Consts.CameraState` values. ```js const States = iracing.Consts.CameraState // Activate camera tool, hide UI, enable mouse-aim mode const newState = States.CamToolActive | States.UIHidden | States.UseMouseAimMode iracing.camControls.setState(newState) // Enable auto-shot selection and temporary edits iracing.camControls.setState(States.UseAutoShotSelection | States.UseTemporaryEdits) ``` ``` -------------------------------- ### searchTs Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Searches for a specific timestamp within the replay, allowing jumps to precise moments. ```APIDOC ## searchTs(sessionNum, sessionTimeMS) ### Description Searches for a specific timestamp within the replay. ### Method N/A (JavaScript function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **sessionNum** (Integer) - Required - The session number. - **sessionTimeMS** (Integer) - Required - The session time in milliseconds. ### Request Example ```js // jump to 2nd minute of 3rd session iracing.playbackControls.searchTs(2, 2*60*1000) ``` ### Response N/A ``` -------------------------------- ### Control Replay Slow Backward Playback Source: https://github.com/friss/iracing-sdk-js/blob/main/README.md Use this function to play the replay in reverse at a reduced speed. The divider controls the speed. ```javascript iracing.playbackControls.slowBackward(2) // half speed RW ```