interface: do not leak on reconnect

This commit is contained in:
Liam Fitzgerald 2021-06-22 05:42:18 +10:00
parent d581d1f61d
commit f8d56a86c4
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
2 changed files with 11 additions and 8 deletions

View File

@ -14,13 +14,7 @@ export const bootstrapApi = async () => {
airlock.onError = (e) => {
(async () => {
try {
useLocalState.setState({ subscription: 'reconnecting' });
airlock.reset();
await bootstrapApi();
} catch (e) {
useLocalState.setState({ subscription: 'disconnected' });
}
useLocalState.setState({ subscription: 'disconnected' });
})();
};

View File

@ -52,6 +52,11 @@ export class Urbit {
*/
private outstandingSubscriptions: Map<number, SubscriptionRequestInterface> = new Map();
/**
* Our abort controller, used to close the connection
*/
private abort = new AbortController();
/**
* Ship can be set, in which case we can do some magic stuff like send chats
*/
@ -88,7 +93,8 @@ export class Urbit {
return {
credentials: 'include',
accept: '*',
headers
headers,
signal: this.abort
};
}
@ -258,6 +264,9 @@ export class Urbit {
*
*/
reset() {
this.delete();
this.abort.abort();
this.abort = new AbortController();
this.uid = `${Math.floor(Date.now() / 1000)}-${hexString(6)}`;
this.lastEventId = 0;
this.lastAcknowledgedEventId = 0;