-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathclientEvents.ts
49 lines (40 loc) · 1.34 KB
/
clientEvents.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { EventFlag, open, Protocol, SimConnectConstants } from '../../dist';
/**
* Demonstrates how to use client events to interact with the simulator
*/
enum ClientEventID {
INCREMENT,
DECREMENT,
}
open('My app', Protocol.FSX_SP2)
.then(({ recvOpen, handle }) => {
console.log('Connected: ', recvOpen);
handle.mapClientEventToSimEvent(ClientEventID.INCREMENT, 'AP_ALT_VAR_INC');
handle.mapClientEventToSimEvent(ClientEventID.DECREMENT, 'AP_ALT_VAR_DEC');
let step = 0;
let rise = true;
// Increment and decrement the altitude every 50ms
setInterval(() => {
step++;
handle.transmitClientEvent(
SimConnectConstants.OBJECT_ID_USER,
rise ? ClientEventID.INCREMENT : ClientEventID.DECREMENT,
0,
1,
EventFlag.EVENT_FLAG_GROUPID_IS_PRIORITY
);
if (step === 100) {
rise = !rise; // Change direction
step = 0;
}
}, 50);
handle.on('error', error => {
console.log('Error:', error);
});
handle.on('exception', recvException => {
console.log('recvException:', recvException);
});
})
.catch(error => {
console.log('Failed to connect', error);
});