mirror of
https://github.com/urbit/shrub.git
synced 2024-12-21 01:41:37 +03:00
interface: fix reconnect logic
This commit is contained in:
parent
66536bebcd
commit
185ee5f661
@ -12,9 +12,17 @@ import useStorageState from '../state/storage';
|
||||
import gcpManager from '../lib/gcpManager';
|
||||
|
||||
export async function bootstrapApi() {
|
||||
airlock.reset();
|
||||
airlock.onError = (e) => {
|
||||
(async () => {
|
||||
const { reconnect } = useLocalState.getState();
|
||||
const { reconnect, errorCount, set } = useLocalState.getState();
|
||||
console.log(errorCount);
|
||||
if(errorCount > 1) {
|
||||
set(s => {
|
||||
s.subscription = 'disconnected';
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await reconnect();
|
||||
} catch (e) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Urbit from '@urbit/http-api';
|
||||
const api = new Urbit('', '', (window as any).desk);
|
||||
api.ship = window.ship;
|
||||
// api.verbose = true;
|
||||
api.verbose = true;
|
||||
// @ts-ignore TODO window typings
|
||||
window.api = api;
|
||||
|
||||
|
@ -82,19 +82,17 @@ const useLocalState = create<LocalStateZus>(persist((set, get) => ({
|
||||
// resume doesn't work properly
|
||||
reconnect: async () => {
|
||||
const { errorCount } = get();
|
||||
set(s => ({ errorCount: s.errorCount+1, subscription: 'reconnecting' }));
|
||||
|
||||
if(errorCount > 5) {
|
||||
set({ subscription: 'disconnected' });
|
||||
if(errorCount > 1) {
|
||||
return;
|
||||
}
|
||||
await wait(Math.pow(2, errorCount) * 750);
|
||||
set(s => ({ subscription: 'reconnecting', errorCount: s.errorCount + 1 }));
|
||||
console.log(get().errorCount);
|
||||
|
||||
try {
|
||||
airlock.reset();
|
||||
await bootstrapApi();
|
||||
} catch (e) {
|
||||
console.error(`Retrying connection, attempt #${errorCount}`);
|
||||
console.error(e);
|
||||
set({ subscription: 'disconnected' });
|
||||
}
|
||||
},
|
||||
bootstrap: async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user