-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demonstrate how to trigger client events
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
}); |