Skip to content

Commit

Permalink
Merge pull request #19 from tcavenezuela/fix/reset-connected-status
Browse files Browse the repository at this point in the history
fix: restart connected status
  • Loading branch information
carl0shd authored Jun 3, 2024
2 parents c174484 + 0d311bf commit b641d6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/kind-insects-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@simconnect.js/api': patch
---

fix restart status of connected when the connection crash or just capture an exception
7 changes: 6 additions & 1 deletion packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class SIMCONNECT_API {
const { handle, recvOpen } = await open(this.appName, Protocol.FSX_SP2, remote);

if (!handle) {
this.connected = false;
opts.onException('No connection handle to the simulator.');
}

Expand All @@ -75,7 +76,10 @@ export class SIMCONNECT_API {
this.simulatorName = recvOpen.applicationName;
handle.on('event', (event) => this.handleSystemEvent(event));
handle.on('close', () => opts.autoReconnect && this.connect(opts));
handle.on('exception', (e) => opts.onException(SIMCONNECT_EXCEPTION[e.exception]));
handle.on('exception', (e) => {
this.connected = false;
opts.onException(SIMCONNECT_EXCEPTION[e.exception]);
});

opts.onConnect(handle, recvOpen);
} catch (err) {
Expand All @@ -84,6 +88,7 @@ export class SIMCONNECT_API {
opts.onRetry(opts.retries, opts.retryInterval);
setTimeout(() => this.connect(opts), 1000 * opts.retryInterval);
} else {
this.connected = false;
opts.onException('No connection to the simulator.');
}
}
Expand Down

0 comments on commit b641d6e

Please sign in to comment.