@irsdk-node/native 5.1.0 → 5.2.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/binding.gyp +5 -13
- package/dist/cjs/index.cjs +24 -9
- package/dist/esm/index.js +23 -9
- package/dist/types/INativeSDK.d.ts +11 -0
- package/dist/types/MockSdk.d.ts +4 -1
- package/dist/types/index.d.ts +1 -0
- package/install.js +4 -0
- package/lib/irsdk_node.cpp +533 -0
- package/lib/irsdk_node.h +93 -36
- package/lib/logger.cpp +68 -0
- package/lib/logger.h +57 -0
- package/lib/root.cpp +11 -0
- package/package.json +6 -6
- package/prebuilds/@irsdk-node+native.node +0 -0
- package/lib/irsdk_node.cc +0 -457
- package/lib/irsdk_node_mocked.cc +0 -226
- 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/lib/irsdk_node_mocked.cc
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
#include "./irsdk_node.h"
|
|
2
|
-
#include "./yaml_parser.h"
|
|
3
|
-
|
|
4
|
-
const char *MOCK_PROP_NAME = "__mocked";
|
|
5
|
-
|
|
6
|
-
// ---------------------------
|
|
7
|
-
// Constructors
|
|
8
|
-
// ---------------------------
|
|
9
|
-
Napi::Object iRacingSdkNode::Init(Napi::Env env, Napi::Object exports)
|
|
10
|
-
{
|
|
11
|
-
Napi::Function func = DefineClass(env, "iRacingSdkNode", {
|
|
12
|
-
// Properties
|
|
13
|
-
InstanceAccessor<&iRacingSdkNode::GetCurrSessionDataVersion>("currDataVersion"),
|
|
14
|
-
InstanceAccessor<&iRacingSdkNode::GetEnableLogging, &iRacingSdkNode::SetEnableLogging>("enableLogging"),
|
|
15
|
-
InstanceAccessor<&iRacingSdkNode::GetIsMocked>("isMocked"),
|
|
16
|
-
|
|
17
|
-
// Methods
|
|
18
|
-
// Control
|
|
19
|
-
InstanceMethod<&iRacingSdkNode::StartSdk>("startSDK"),
|
|
20
|
-
InstanceMethod("stopSDK", &iRacingSdkNode::StopSdk),
|
|
21
|
-
InstanceMethod("waitForData", &iRacingSdkNode::WaitForData),
|
|
22
|
-
InstanceMethod("broadcast", &iRacingSdkNode::BroadcastMessage),
|
|
23
|
-
// Getters
|
|
24
|
-
InstanceMethod("isRunning", &iRacingSdkNode::IsRunning),
|
|
25
|
-
InstanceMethod("getSessionVersionNum", &iRacingSdkNode::GetSessionVersionNum),
|
|
26
|
-
InstanceMethod("getSessionData", &iRacingSdkNode::GetSessionData),
|
|
27
|
-
InstanceMethod("getTelemetryData", &iRacingSdkNode::GetTelemetryData),
|
|
28
|
-
InstanceMethod("getTelemetryVariable", &iRacingSdkNode::GetTelemetryVar),
|
|
29
|
-
// Helpers
|
|
30
|
-
InstanceMethod("__getTelemetryTypes", &iRacingSdkNode::__GetTelemetryTypes),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
Napi::FunctionReference *constructor = new Napi::FunctionReference();
|
|
34
|
-
*constructor = Napi::Persistent(func);
|
|
35
|
-
env.SetInstanceData(constructor);
|
|
36
|
-
|
|
37
|
-
exports.Set("iRacingSdkNode", func);
|
|
38
|
-
return exports;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
iRacingSdkNode::iRacingSdkNode(const Napi::CallbackInfo &info)
|
|
42
|
-
: Napi::ObjectWrap<iRacingSdkNode>(info), _data(NULL), _bufLineLen(0), _sessionStatusID(0), _lastSessionCt(-1), _sessionData(NULL), _loggingEnabled(false)
|
|
43
|
-
{
|
|
44
|
-
printf("Initializing mock iRacingSdkNode\n");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ---------------------------
|
|
48
|
-
// Property implementations
|
|
49
|
-
// ---------------------------
|
|
50
|
-
Napi::Value iRacingSdkNode::GetCurrSessionDataVersion(const Napi::CallbackInfo &info)
|
|
51
|
-
{
|
|
52
|
-
int ver = this->_lastSessionCt;
|
|
53
|
-
return Napi::Number::New(info.Env(), ver);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Napi::Value iRacingSdkNode::GetEnableLogging(const Napi::CallbackInfo &info)
|
|
57
|
-
{
|
|
58
|
-
bool enabled = this->_loggingEnabled;
|
|
59
|
-
return Napi::Boolean::New(info.Env(), enabled);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
void iRacingSdkNode::SetEnableLogging(const Napi::CallbackInfo &info, const Napi::Value &value)
|
|
63
|
-
{
|
|
64
|
-
Napi::Boolean enable;
|
|
65
|
-
if (info.Length() <= 0 || !info[0].IsBoolean())
|
|
66
|
-
{
|
|
67
|
-
enable = Napi::Boolean::New(info.Env(), false);
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
{
|
|
71
|
-
enable = info[0].As<Napi::Boolean>();
|
|
72
|
-
}
|
|
73
|
-
this->_loggingEnabled = enable;
|
|
74
|
-
if (this->_loggingEnabled)
|
|
75
|
-
printf("iRacingSDK Logging enabled\n");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
Napi::Value iRacingSdkNode::GetIsMocked(const Napi::CallbackInfo &info)
|
|
79
|
-
{
|
|
80
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ---------------------------
|
|
84
|
-
// Instance implementations
|
|
85
|
-
// ---------------------------
|
|
86
|
-
// SDK Control
|
|
87
|
-
Napi::Value iRacingSdkNode::StartSdk(const Napi::CallbackInfo &info)
|
|
88
|
-
{
|
|
89
|
-
if (this->_loggingEnabled)
|
|
90
|
-
printf("Starting Mock SDK...\n");
|
|
91
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
Napi::Value iRacingSdkNode::StopSdk(const Napi::CallbackInfo &info)
|
|
95
|
-
{
|
|
96
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
Napi::Value iRacingSdkNode::WaitForData(const Napi::CallbackInfo &info)
|
|
100
|
-
{
|
|
101
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
Napi::Value iRacingSdkNode::BroadcastMessage(const Napi::CallbackInfo &info)
|
|
105
|
-
{
|
|
106
|
-
auto env = info.Env();
|
|
107
|
-
|
|
108
|
-
// Determine message type
|
|
109
|
-
if (info.Length() <= 2 || !info[0].IsNumber())
|
|
110
|
-
{
|
|
111
|
-
return Napi::Boolean::New(env, false);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (info.Length() == 4 && !info[2].IsNumber())
|
|
115
|
-
{
|
|
116
|
-
return Napi::Boolean::New(env, false);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return Napi::Boolean::New(env, true);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// SDK State Getters
|
|
123
|
-
Napi::Value iRacingSdkNode::IsRunning(const Napi::CallbackInfo &info)
|
|
124
|
-
{
|
|
125
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
Napi::Value iRacingSdkNode::GetSessionVersionNum(const Napi::CallbackInfo &info)
|
|
129
|
-
{
|
|
130
|
-
return Napi::Number::New(info.Env(), 1);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
Napi::Value iRacingSdkNode::GetSessionData(const Napi::CallbackInfo &info)
|
|
134
|
-
{
|
|
135
|
-
return Napi::String::New(info.Env(), MOCK_PROP_NAME);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
Napi::Value iRacingSdkNode::GetTelemetryVar(const Napi::CallbackInfo &info)
|
|
139
|
-
{
|
|
140
|
-
Napi::Env env = info.Env();
|
|
141
|
-
|
|
142
|
-
int varIndex;
|
|
143
|
-
if (info.Length() <= 0)
|
|
144
|
-
{
|
|
145
|
-
varIndex = 0;
|
|
146
|
-
}
|
|
147
|
-
else if (!info[0].IsNumber())
|
|
148
|
-
{
|
|
149
|
-
if (info[0].IsString())
|
|
150
|
-
{
|
|
151
|
-
auto obj = Napi::Object::New(env);
|
|
152
|
-
obj.Set(MOCK_PROP_NAME, true);
|
|
153
|
-
return obj;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
varIndex = 0;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
Napi::Value iRacingSdkNode::GetTelemetryData(const Napi::CallbackInfo &info)
|
|
163
|
-
{
|
|
164
|
-
auto env = info.Env();
|
|
165
|
-
auto telemVars = Napi::Object::New(env);
|
|
166
|
-
telemVars.Set(MOCK_PROP_NAME, true);
|
|
167
|
-
return telemVars;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Helpers
|
|
171
|
-
Napi::Value iRacingSdkNode::__GetTelemetryTypes(const Napi::CallbackInfo &info)
|
|
172
|
-
{
|
|
173
|
-
auto env = info.Env();
|
|
174
|
-
auto result = Napi::Object::New(env);
|
|
175
|
-
result.Set(MOCK_PROP_NAME, true);
|
|
176
|
-
return result;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// ---------------------------
|
|
180
|
-
// Helper functions
|
|
181
|
-
// ---------------------------
|
|
182
|
-
bool iRacingSdkNode::GetTelemetryBool(int entry, int index)
|
|
183
|
-
{
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
int iRacingSdkNode::GetTelemetryInt(int entry, int index)
|
|
188
|
-
{
|
|
189
|
-
return 0;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
float iRacingSdkNode::GetTelemetryFloat(int entry, int index)
|
|
193
|
-
{
|
|
194
|
-
return 0.0f;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
double iRacingSdkNode::GetTelemetryDouble(int entry, int index)
|
|
198
|
-
{
|
|
199
|
-
// Each double is 8 bytes
|
|
200
|
-
return 0.0;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
Napi::Object iRacingSdkNode::GetTelemetryVarByIndex(const Napi::Env env, int index)
|
|
204
|
-
{
|
|
205
|
-
auto telemVar = Napi::Object::New(env);
|
|
206
|
-
telemVar.Set(MOCK_PROP_NAME, true);
|
|
207
|
-
return telemVar;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
Napi::Object iRacingSdkNode::GetTelemetryVar(const Napi::Env env, const char *varName)
|
|
211
|
-
{
|
|
212
|
-
auto obj = Napi::Object::New(env);
|
|
213
|
-
obj.Set(MOCK_PROP_NAME, true);
|
|
214
|
-
return obj;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
|
|
218
|
-
{
|
|
219
|
-
iRacingSdkNode::Init(env, exports);
|
|
220
|
-
|
|
221
|
-
exports.Set("mockedSdk", true);
|
|
222
|
-
|
|
223
|
-
return exports;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|