Merge pull request #5041 from urbit/lf/reconnect-fetch

interface: omnibus
This commit is contained in:
matildepark 2021-06-21 15:17:02 -05:00 committed by GitHub
commit 0930dea484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 11 deletions

View File

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

View File

@ -35,7 +35,7 @@ const useMetadataState = createState<MetadataState>(
return state.previews[group]; return state.previews[group];
} }
try { try {
const preview = await airlock.subscribeOnce('metadata-pull-hook', `/preview${group}`); const preview = await airlock.subscribeOnce('metadata-pull-hook', `/preview${group}`, 20 * 1000);
if('metadata-hook-update' in preview) { if('metadata-hook-update' in preview) {
const newState = get(); const newState = get();
newState.set((s) => { newState.set((s) => {

View File

@ -28,8 +28,8 @@ function sidebarSort(
const lastUpdated = (a: string, b: string) => { const lastUpdated = (a: string, b: string) => {
const aAssoc = associations[a]; const aAssoc = associations[a];
const bAssoc = associations[b]; const bAssoc = associations[b];
const aResource = aAssoc.resource; const aResource = aAssoc?.resource;
const bResource = bAssoc.resource; const bResource = bAssoc?.resource;
const aUpdated = a.startsWith('~') const aUpdated = a.startsWith('~')
? (unreads?.[`/ship/~${window.ship}/dm-inbox`]?.[`/${patp2dec(a)}`]?.last || 0) ? (unreads?.[`/ship/~${window.ship}/dm-inbox`]?.[`/${patp2dec(a)}`]?.last || 0)

View File

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