gameglue 4.0.1 → 4.0.2
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 +21 -21
- package/README.md +275 -275
- package/babel.config.cjs +5 -5
- package/coverage/auth.js.html +525 -525
- package/coverage/base.css +224 -224
- package/coverage/block-navigation.js +87 -87
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +175 -175
- package/coverage/index.js.html +309 -309
- package/coverage/lcov-report/auth.js.html +525 -525
- package/coverage/lcov-report/base.css +224 -224
- package/coverage/lcov-report/block-navigation.js +87 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +175 -175
- package/coverage/lcov-report/index.js.html +309 -309
- package/coverage/lcov-report/listener.js.html +528 -528
- package/coverage/lcov-report/prettify.css +1 -1
- package/coverage/lcov-report/prettify.js +2 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -210
- package/coverage/lcov-report/user.js.html +117 -117
- package/coverage/lcov-report/utils.js.html +117 -117
- package/coverage/lcov.info +391 -391
- package/coverage/listener.js.html +528 -528
- package/coverage/prettify.css +1 -1
- package/coverage/prettify.js +2 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -210
- package/coverage/user.js.html +117 -117
- package/coverage/utils.js.html +117 -117
- package/dist/gg.cjs.js +1 -1
- package/dist/gg.cjs.js.map +1 -1
- package/dist/gg.esm.js +1 -1
- package/dist/gg.esm.js.map +1 -1
- package/dist/gg.umd.js +1 -1
- package/dist/gg.umd.js.map +1 -1
- package/examples/certs/cert.pem +19 -19
- package/examples/certs/key.pem +28 -28
- package/examples/flight-dashboard.html +431 -431
- package/examples/server.js +99 -99
- package/examples/telemetry-validator.html +1410 -1410
- package/jest.config.cjs +33 -33
- package/package.json +56 -56
- package/rollup.config.js +57 -57
- package/src/auth.js +255 -255
- package/src/auth.spec.js +481 -481
- package/src/index.js +168 -168
- package/src/listener.js +196 -196
- package/src/listener.spec.js +598 -598
- package/src/presence_listener.js +112 -112
- package/src/test/fixtures.js +106 -106
- package/src/test/setup.js +51 -51
- package/src/utils.js +63 -63
- package/src/utils.spec.js +78 -78
- package/types/index.d.ts +338 -338
- package/webpack.config.js +15 -15
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 GameGlue
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 GameGlue
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,275 +1,275 @@
|
|
|
1
|
-
# GameGlue SDK
|
|
2
|
-
|
|
3
|
-
The official JavaScript SDK for [GameGlue](https://gameglue.gg) - build game addons with nothing more than HTML and JavaScript.
|
|
4
|
-
|
|
5
|
-
## What is GameGlue?
|
|
6
|
-
|
|
7
|
-
GameGlue streams real-time telemetry from PC games to your web applications. The SDK supports **bidirectional data flow** - receive telemetry updates and send commands back to control the game.
|
|
8
|
-
|
|
9
|
-
**Supported Games:**
|
|
10
|
-
- Microsoft Flight Simulator (MSFS)
|
|
11
|
-
- X-Plane 12
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
# npm
|
|
17
|
-
npm install gameglue
|
|
18
|
-
|
|
19
|
-
# yarn
|
|
20
|
-
yarn add gameglue
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Or use the CDN:
|
|
24
|
-
|
|
25
|
-
```html
|
|
26
|
-
<script src="https://unpkg.com/gameglue/dist/gg.umd.js"></script>
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Quick Start
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
import GameGlue from 'gameglue';
|
|
33
|
-
|
|
34
|
-
const gg = new GameGlue({
|
|
35
|
-
clientId: '<your-client-id>',
|
|
36
|
-
redirect_uri: window.location.origin,
|
|
37
|
-
scopes: ['msfs:read', 'msfs:write'] // or ['xplane:read', 'xplane:write']
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Check authentication (handles OAuth callback automatically)
|
|
41
|
-
if (!await gg.isAuthenticated()) {
|
|
42
|
-
gg.login();
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Create a listener
|
|
47
|
-
const listener = await gg.createListener({
|
|
48
|
-
userId: gg.getUser(),
|
|
49
|
-
gameId: 'msfs' // or 'xplane'
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Receive telemetry
|
|
53
|
-
listener.on('update', (evt) => {
|
|
54
|
-
console.log('Altitude:', evt.data.indicated_altitude);
|
|
55
|
-
console.log('Airspeed:', evt.data.airspeed_indicated);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Send commands
|
|
59
|
-
await listener.sendCommand('autopilot_on', true);
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Getting Started
|
|
63
|
-
|
|
64
|
-
1. Sign up at [developer.gameglue.gg](https://developer.gameglue.gg)
|
|
65
|
-
2. Register your application in the Developer Hub
|
|
66
|
-
3. Install the SDK and initialize with your client ID
|
|
67
|
-
|
|
68
|
-
## Telemetry Updates
|
|
69
|
-
|
|
70
|
-
Subscribe to real-time telemetry with `listener.on('update', ...)`:
|
|
71
|
-
|
|
72
|
-
```javascript
|
|
73
|
-
listener.on('update', (evt) => {
|
|
74
|
-
// evt.data contains normalized field names (work across all sims)
|
|
75
|
-
console.log('Altitude:', evt.data.indicated_altitude);
|
|
76
|
-
console.log('Heading:', evt.data.heading_indicator);
|
|
77
|
-
|
|
78
|
-
// evt.raw contains the original game-specific field names
|
|
79
|
-
console.log('Raw data:', evt.raw);
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Field Subscriptions
|
|
84
|
-
|
|
85
|
-
Subscribe to specific fields only (reduces bandwidth):
|
|
86
|
-
|
|
87
|
-
```javascript
|
|
88
|
-
const listener = await gg.createListener({
|
|
89
|
-
userId: gg.getUser(),
|
|
90
|
-
gameId: 'msfs',
|
|
91
|
-
fields: ['indicated_altitude', 'airspeed_indicated', 'heading_indicator']
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Manage subscriptions dynamically:
|
|
96
|
-
|
|
97
|
-
```javascript
|
|
98
|
-
// Add fields
|
|
99
|
-
await listener.subscribe(['vertical_speed', 'autopilot_master']);
|
|
100
|
-
|
|
101
|
-
// Remove fields
|
|
102
|
-
await listener.unsubscribe(['heading_indicator']);
|
|
103
|
-
|
|
104
|
-
// Check current subscriptions
|
|
105
|
-
const fields = listener.getFields(); // Returns array or null (all fields)
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
**Note:** You cannot unsubscribe if you initialized the listener with all fields (`fields: null` or omitted). Use `subscribe()` first to set an explicit field list.
|
|
109
|
-
|
|
110
|
-
## Key Events
|
|
111
|
-
|
|
112
|
-
Beyond raw telemetry, the SDK provides computed events for significant flight moments:
|
|
113
|
-
|
|
114
|
-
### Landing Events
|
|
115
|
-
|
|
116
|
-
```javascript
|
|
117
|
-
listener.on('landing', (evt) => {
|
|
118
|
-
console.log(`${evt.quality} landing at ${Math.abs(evt.landing_rate)} fpm`);
|
|
119
|
-
console.log(`Bounces: ${evt.bounce_count}`);
|
|
120
|
-
});
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Landing quality ratings: `butter` (<60 fpm), `smooth` (60-120), `normal` (120-180), `firm` (180-300), `hard` (300-600), `crash` (>600)
|
|
124
|
-
|
|
125
|
-
### Takeoff Events
|
|
126
|
-
|
|
127
|
-
```javascript
|
|
128
|
-
listener.on('takeoff', (evt) => {
|
|
129
|
-
console.log(`Rotation at ${evt.rotation_speed} kts`);
|
|
130
|
-
console.log(`Pitch: ${evt.pitch_at_liftoff}°`);
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Flight Phase Events
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
listener.on('flight_phase', (evt) => {
|
|
138
|
-
console.log(`Phase: ${evt.previous_phase} → ${evt.phase}`);
|
|
139
|
-
});
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Phases: `parked`, `taxi_out`, `takeoff_roll`, `initial_climb`, `climb`, `cruise`, `descent`, `approach`, `final`, `landing_roll`, `taxi_in`
|
|
143
|
-
|
|
144
|
-
## Sending Commands
|
|
145
|
-
|
|
146
|
-
Send commands to control the simulator:
|
|
147
|
-
|
|
148
|
-
```javascript
|
|
149
|
-
const result = await listener.sendCommand('autopilot_on', true);
|
|
150
|
-
|
|
151
|
-
if (result.status === 'success') {
|
|
152
|
-
console.log('Command sent');
|
|
153
|
-
} else {
|
|
154
|
-
console.error('Failed:', result.reason);
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Commands use normalized names that work across simulators:
|
|
159
|
-
|
|
160
|
-
```javascript
|
|
161
|
-
// Autopilot
|
|
162
|
-
await listener.sendCommand('autopilot_on', true);
|
|
163
|
-
await listener.sendCommand('autopilot_heading_hold_on', true);
|
|
164
|
-
await listener.sendCommand('set_autopilot_altitude', 35000);
|
|
165
|
-
|
|
166
|
-
// Gear and Flaps
|
|
167
|
-
await listener.sendCommand('gear_toggle', true);
|
|
168
|
-
await listener.sendCommand('flaps_down', true);
|
|
169
|
-
|
|
170
|
-
// Lights
|
|
171
|
-
await listener.sendCommand('landing_lights_on', true);
|
|
172
|
-
await listener.sendCommand('nav_lights_toggle', true);
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
See the [full command reference](https://docs.gameglue.gg/games/msfs#writable-commands) for all available commands.
|
|
176
|
-
|
|
177
|
-
## Authentication
|
|
178
|
-
|
|
179
|
-
```javascript
|
|
180
|
-
// Check if authenticated (handles OAuth callback automatically)
|
|
181
|
-
const isAuth = await gg.isAuthenticated();
|
|
182
|
-
|
|
183
|
-
// Redirect to login
|
|
184
|
-
gg.login();
|
|
185
|
-
|
|
186
|
-
// Get user ID
|
|
187
|
-
const userId = gg.getUser();
|
|
188
|
-
|
|
189
|
-
// Get access token
|
|
190
|
-
const token = gg.getAccessToken();
|
|
191
|
-
|
|
192
|
-
// Logout (clear local tokens only)
|
|
193
|
-
gg.logout({ redirect: false });
|
|
194
|
-
|
|
195
|
-
// Logout and redirect to Keycloak logout
|
|
196
|
-
gg.logout();
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Scopes
|
|
200
|
-
|
|
201
|
-
| Scope | Description |
|
|
202
|
-
|-------|-------------|
|
|
203
|
-
| `msfs:read` | Read MSFS telemetry |
|
|
204
|
-
| `msfs:write` | Send commands to MSFS |
|
|
205
|
-
| `xplane:read` | Read X-Plane telemetry |
|
|
206
|
-
| `xplane:write` | Send commands to X-Plane |
|
|
207
|
-
|
|
208
|
-
## API Reference
|
|
209
|
-
|
|
210
|
-
### GameGlue
|
|
211
|
-
|
|
212
|
-
| Method | Description |
|
|
213
|
-
|--------|-------------|
|
|
214
|
-
| `new GameGlue(config)` | Initialize SDK with `clientId`, `redirect_uri`, `scopes` |
|
|
215
|
-
| `isAuthenticated()` | Check auth status. Handles OAuth callback if present. Returns `Promise<boolean>` |
|
|
216
|
-
| `login()` | Redirect to GameGlue login |
|
|
217
|
-
| `logout(options?)` | Log out. Pass `{ redirect: false }` to only clear local tokens |
|
|
218
|
-
| `getUser()` | Returns authenticated user's ID |
|
|
219
|
-
| `getAccessToken()` | Returns current access token |
|
|
220
|
-
| `createListener(config)` | Create listener for game telemetry |
|
|
221
|
-
| `onTokenRefreshed(callback)` | Register callback for token refresh events |
|
|
222
|
-
|
|
223
|
-
### Listener
|
|
224
|
-
|
|
225
|
-
| Method | Description |
|
|
226
|
-
|--------|-------------|
|
|
227
|
-
| `on('update', callback)` | Subscribe to telemetry updates |
|
|
228
|
-
| `on('landing', callback)` | Subscribe to landing events |
|
|
229
|
-
| `on('takeoff', callback)` | Subscribe to takeoff events |
|
|
230
|
-
| `on('flight_phase', callback)` | Subscribe to flight phase changes |
|
|
231
|
-
| `sendCommand(command, value)` | Send command to simulator |
|
|
232
|
-
| `subscribe(fields)` | Add fields to subscription |
|
|
233
|
-
| `unsubscribe(fields)` | Remove fields from subscription |
|
|
234
|
-
| `getFields()` | Get current subscribed fields (null = all) |
|
|
235
|
-
|
|
236
|
-
## TypeScript
|
|
237
|
-
|
|
238
|
-
The SDK includes TypeScript definitions:
|
|
239
|
-
|
|
240
|
-
```typescript
|
|
241
|
-
import GameGlue, {
|
|
242
|
-
LandingEvent,
|
|
243
|
-
TakeoffEvent,
|
|
244
|
-
FlightPhaseEvent,
|
|
245
|
-
UpdateEvent
|
|
246
|
-
} from 'gameglue';
|
|
247
|
-
|
|
248
|
-
listener.on('landing', (evt: LandingEvent) => {
|
|
249
|
-
console.log(evt.quality, evt.landing_rate);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
listener.on('update', (evt: UpdateEvent) => {
|
|
253
|
-
console.log(evt.data.indicated_altitude);
|
|
254
|
-
});
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
## Examples
|
|
258
|
-
|
|
259
|
-
See the `examples/` directory:
|
|
260
|
-
- `flight-dashboard.html` - Complete flight dashboard with instruments and autopilot control
|
|
261
|
-
- `telemetry-validator.html` - Developer tool for testing all fields and commands
|
|
262
|
-
|
|
263
|
-
## Documentation
|
|
264
|
-
|
|
265
|
-
Full documentation at [docs.gameglue.gg](https://docs.gameglue.gg):
|
|
266
|
-
- [Quick Start Guide](https://docs.gameglue.gg/quick-start)
|
|
267
|
-
- [Authentication Guide](https://docs.gameglue.gg/guides/authentication)
|
|
268
|
-
- [Key Events Guide](https://docs.gameglue.gg/guides/key-events)
|
|
269
|
-
- [Sending Commands](https://docs.gameglue.gg/guides/sending-commands)
|
|
270
|
-
- [MSFS Reference](https://docs.gameglue.gg/games/msfs)
|
|
271
|
-
- [X-Plane Reference](https://docs.gameglue.gg/games/xplane)
|
|
272
|
-
|
|
273
|
-
## License
|
|
274
|
-
|
|
275
|
-
MIT
|
|
1
|
+
# GameGlue SDK
|
|
2
|
+
|
|
3
|
+
The official JavaScript SDK for [GameGlue](https://gameglue.gg) - build game addons with nothing more than HTML and JavaScript.
|
|
4
|
+
|
|
5
|
+
## What is GameGlue?
|
|
6
|
+
|
|
7
|
+
GameGlue streams real-time telemetry from PC games to your web applications. The SDK supports **bidirectional data flow** - receive telemetry updates and send commands back to control the game.
|
|
8
|
+
|
|
9
|
+
**Supported Games:**
|
|
10
|
+
- Microsoft Flight Simulator (MSFS)
|
|
11
|
+
- X-Plane 12
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# npm
|
|
17
|
+
npm install gameglue
|
|
18
|
+
|
|
19
|
+
# yarn
|
|
20
|
+
yarn add gameglue
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or use the CDN:
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<script src="https://unpkg.com/gameglue/dist/gg.umd.js"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import GameGlue from 'gameglue';
|
|
33
|
+
|
|
34
|
+
const gg = new GameGlue({
|
|
35
|
+
clientId: '<your-client-id>',
|
|
36
|
+
redirect_uri: window.location.origin,
|
|
37
|
+
scopes: ['msfs:read', 'msfs:write'] // or ['xplane:read', 'xplane:write']
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Check authentication (handles OAuth callback automatically)
|
|
41
|
+
if (!await gg.isAuthenticated()) {
|
|
42
|
+
gg.login();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Create a listener
|
|
47
|
+
const listener = await gg.createListener({
|
|
48
|
+
userId: gg.getUser(),
|
|
49
|
+
gameId: 'msfs' // or 'xplane'
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Receive telemetry
|
|
53
|
+
listener.on('update', (evt) => {
|
|
54
|
+
console.log('Altitude:', evt.data.indicated_altitude);
|
|
55
|
+
console.log('Airspeed:', evt.data.airspeed_indicated);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Send commands
|
|
59
|
+
await listener.sendCommand('autopilot_on', true);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Getting Started
|
|
63
|
+
|
|
64
|
+
1. Sign up at [developer.gameglue.gg](https://developer.gameglue.gg)
|
|
65
|
+
2. Register your application in the Developer Hub
|
|
66
|
+
3. Install the SDK and initialize with your client ID
|
|
67
|
+
|
|
68
|
+
## Telemetry Updates
|
|
69
|
+
|
|
70
|
+
Subscribe to real-time telemetry with `listener.on('update', ...)`:
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
listener.on('update', (evt) => {
|
|
74
|
+
// evt.data contains normalized field names (work across all sims)
|
|
75
|
+
console.log('Altitude:', evt.data.indicated_altitude);
|
|
76
|
+
console.log('Heading:', evt.data.heading_indicator);
|
|
77
|
+
|
|
78
|
+
// evt.raw contains the original game-specific field names
|
|
79
|
+
console.log('Raw data:', evt.raw);
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Field Subscriptions
|
|
84
|
+
|
|
85
|
+
Subscribe to specific fields only (reduces bandwidth):
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
const listener = await gg.createListener({
|
|
89
|
+
userId: gg.getUser(),
|
|
90
|
+
gameId: 'msfs',
|
|
91
|
+
fields: ['indicated_altitude', 'airspeed_indicated', 'heading_indicator']
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Manage subscriptions dynamically:
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
// Add fields
|
|
99
|
+
await listener.subscribe(['vertical_speed', 'autopilot_master']);
|
|
100
|
+
|
|
101
|
+
// Remove fields
|
|
102
|
+
await listener.unsubscribe(['heading_indicator']);
|
|
103
|
+
|
|
104
|
+
// Check current subscriptions
|
|
105
|
+
const fields = listener.getFields(); // Returns array or null (all fields)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Note:** You cannot unsubscribe if you initialized the listener with all fields (`fields: null` or omitted). Use `subscribe()` first to set an explicit field list.
|
|
109
|
+
|
|
110
|
+
## Key Events
|
|
111
|
+
|
|
112
|
+
Beyond raw telemetry, the SDK provides computed events for significant flight moments:
|
|
113
|
+
|
|
114
|
+
### Landing Events
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
listener.on('landing', (evt) => {
|
|
118
|
+
console.log(`${evt.quality} landing at ${Math.abs(evt.landing_rate)} fpm`);
|
|
119
|
+
console.log(`Bounces: ${evt.bounce_count}`);
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Landing quality ratings: `butter` (<60 fpm), `smooth` (60-120), `normal` (120-180), `firm` (180-300), `hard` (300-600), `crash` (>600)
|
|
124
|
+
|
|
125
|
+
### Takeoff Events
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
listener.on('takeoff', (evt) => {
|
|
129
|
+
console.log(`Rotation at ${evt.rotation_speed} kts`);
|
|
130
|
+
console.log(`Pitch: ${evt.pitch_at_liftoff}°`);
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Flight Phase Events
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
listener.on('flight_phase', (evt) => {
|
|
138
|
+
console.log(`Phase: ${evt.previous_phase} → ${evt.phase}`);
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Phases: `parked`, `taxi_out`, `takeoff_roll`, `initial_climb`, `climb`, `cruise`, `descent`, `approach`, `final`, `landing_roll`, `taxi_in`
|
|
143
|
+
|
|
144
|
+
## Sending Commands
|
|
145
|
+
|
|
146
|
+
Send commands to control the simulator:
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
const result = await listener.sendCommand('autopilot_on', true);
|
|
150
|
+
|
|
151
|
+
if (result.status === 'success') {
|
|
152
|
+
console.log('Command sent');
|
|
153
|
+
} else {
|
|
154
|
+
console.error('Failed:', result.reason);
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Commands use normalized names that work across simulators:
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
// Autopilot
|
|
162
|
+
await listener.sendCommand('autopilot_on', true);
|
|
163
|
+
await listener.sendCommand('autopilot_heading_hold_on', true);
|
|
164
|
+
await listener.sendCommand('set_autopilot_altitude', 35000);
|
|
165
|
+
|
|
166
|
+
// Gear and Flaps
|
|
167
|
+
await listener.sendCommand('gear_toggle', true);
|
|
168
|
+
await listener.sendCommand('flaps_down', true);
|
|
169
|
+
|
|
170
|
+
// Lights
|
|
171
|
+
await listener.sendCommand('landing_lights_on', true);
|
|
172
|
+
await listener.sendCommand('nav_lights_toggle', true);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
See the [full command reference](https://docs.gameglue.gg/games/msfs#writable-commands) for all available commands.
|
|
176
|
+
|
|
177
|
+
## Authentication
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
// Check if authenticated (handles OAuth callback automatically)
|
|
181
|
+
const isAuth = await gg.isAuthenticated();
|
|
182
|
+
|
|
183
|
+
// Redirect to login
|
|
184
|
+
gg.login();
|
|
185
|
+
|
|
186
|
+
// Get user ID
|
|
187
|
+
const userId = gg.getUser();
|
|
188
|
+
|
|
189
|
+
// Get access token
|
|
190
|
+
const token = gg.getAccessToken();
|
|
191
|
+
|
|
192
|
+
// Logout (clear local tokens only)
|
|
193
|
+
gg.logout({ redirect: false });
|
|
194
|
+
|
|
195
|
+
// Logout and redirect to Keycloak logout
|
|
196
|
+
gg.logout();
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Scopes
|
|
200
|
+
|
|
201
|
+
| Scope | Description |
|
|
202
|
+
|-------|-------------|
|
|
203
|
+
| `msfs:read` | Read MSFS telemetry |
|
|
204
|
+
| `msfs:write` | Send commands to MSFS |
|
|
205
|
+
| `xplane:read` | Read X-Plane telemetry |
|
|
206
|
+
| `xplane:write` | Send commands to X-Plane |
|
|
207
|
+
|
|
208
|
+
## API Reference
|
|
209
|
+
|
|
210
|
+
### GameGlue
|
|
211
|
+
|
|
212
|
+
| Method | Description |
|
|
213
|
+
|--------|-------------|
|
|
214
|
+
| `new GameGlue(config)` | Initialize SDK with `clientId`, `redirect_uri`, `scopes` |
|
|
215
|
+
| `isAuthenticated()` | Check auth status. Handles OAuth callback if present. Returns `Promise<boolean>` |
|
|
216
|
+
| `login()` | Redirect to GameGlue login |
|
|
217
|
+
| `logout(options?)` | Log out. Pass `{ redirect: false }` to only clear local tokens |
|
|
218
|
+
| `getUser()` | Returns authenticated user's ID |
|
|
219
|
+
| `getAccessToken()` | Returns current access token |
|
|
220
|
+
| `createListener(config)` | Create listener for game telemetry |
|
|
221
|
+
| `onTokenRefreshed(callback)` | Register callback for token refresh events |
|
|
222
|
+
|
|
223
|
+
### Listener
|
|
224
|
+
|
|
225
|
+
| Method | Description |
|
|
226
|
+
|--------|-------------|
|
|
227
|
+
| `on('update', callback)` | Subscribe to telemetry updates |
|
|
228
|
+
| `on('landing', callback)` | Subscribe to landing events |
|
|
229
|
+
| `on('takeoff', callback)` | Subscribe to takeoff events |
|
|
230
|
+
| `on('flight_phase', callback)` | Subscribe to flight phase changes |
|
|
231
|
+
| `sendCommand(command, value)` | Send command to simulator |
|
|
232
|
+
| `subscribe(fields)` | Add fields to subscription |
|
|
233
|
+
| `unsubscribe(fields)` | Remove fields from subscription |
|
|
234
|
+
| `getFields()` | Get current subscribed fields (null = all) |
|
|
235
|
+
|
|
236
|
+
## TypeScript
|
|
237
|
+
|
|
238
|
+
The SDK includes TypeScript definitions:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import GameGlue, {
|
|
242
|
+
LandingEvent,
|
|
243
|
+
TakeoffEvent,
|
|
244
|
+
FlightPhaseEvent,
|
|
245
|
+
UpdateEvent
|
|
246
|
+
} from 'gameglue';
|
|
247
|
+
|
|
248
|
+
listener.on('landing', (evt: LandingEvent) => {
|
|
249
|
+
console.log(evt.quality, evt.landing_rate);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
listener.on('update', (evt: UpdateEvent) => {
|
|
253
|
+
console.log(evt.data.indicated_altitude);
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Examples
|
|
258
|
+
|
|
259
|
+
See the `examples/` directory:
|
|
260
|
+
- `flight-dashboard.html` - Complete flight dashboard with instruments and autopilot control
|
|
261
|
+
- `telemetry-validator.html` - Developer tool for testing all fields and commands
|
|
262
|
+
|
|
263
|
+
## Documentation
|
|
264
|
+
|
|
265
|
+
Full documentation at [docs.gameglue.gg](https://docs.gameglue.gg):
|
|
266
|
+
- [Quick Start Guide](https://docs.gameglue.gg/quick-start)
|
|
267
|
+
- [Authentication Guide](https://docs.gameglue.gg/guides/authentication)
|
|
268
|
+
- [Key Events Guide](https://docs.gameglue.gg/guides/key-events)
|
|
269
|
+
- [Sending Commands](https://docs.gameglue.gg/guides/sending-commands)
|
|
270
|
+
- [MSFS Reference](https://docs.gameglue.gg/games/msfs)
|
|
271
|
+
- [X-Plane Reference](https://docs.gameglue.gg/games/xplane)
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
package/babel.config.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
presets: [
|
|
3
|
-
['@babel/preset-env', { targets: { node: 'current' } }]
|
|
4
|
-
]
|
|
5
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
presets: [
|
|
3
|
+
['@babel/preset-env', { targets: { node: 'current' } }]
|
|
4
|
+
]
|
|
5
|
+
};
|