diff options
Diffstat (limited to 'subprojects/frontend/src/xtext')
4 files changed, 13 insertions, 8 deletions
diff --git a/subprojects/frontend/src/xtext/OccurrencesService.ts b/subprojects/frontend/src/xtext/OccurrencesService.ts index 9d738d76..248a9a87 100644 --- a/subprojects/frontend/src/xtext/OccurrencesService.ts +++ b/subprojects/frontend/src/xtext/OccurrencesService.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { Transaction } from '@codemirror/state'; | 1 | import { Transaction } from '@codemirror/state'; |
2 | import { debounce } from 'lodash-es'; | 2 | import { debounce } from 'lodash-es'; |
3 | import ms from 'ms'; | ||
3 | 4 | ||
4 | import type EditorStore from '../editor/EditorStore'; | 5 | import type EditorStore from '../editor/EditorStore'; |
5 | import { | 6 | import { |
@@ -11,7 +12,7 @@ import getLogger from '../utils/getLogger'; | |||
11 | import type UpdateService from './UpdateService'; | 12 | import type UpdateService from './UpdateService'; |
12 | import type { TextRegion } from './xtextServiceResults'; | 13 | import type { TextRegion } from './xtextServiceResults'; |
13 | 14 | ||
14 | const FIND_OCCURRENCES_TIMEOUT_MS = 1000; | 15 | const FIND_OCCURRENCES_TIMEOUT = ms('1s'); |
15 | 16 | ||
16 | const log = getLogger('xtext.OccurrencesService'); | 17 | const log = getLogger('xtext.OccurrencesService'); |
17 | 18 | ||
@@ -33,7 +34,7 @@ export default class OccurrencesService { | |||
33 | 34 | ||
34 | private readonly findOccurrencesLater = debounce( | 35 | private readonly findOccurrencesLater = debounce( |
35 | () => this.findOccurrences(), | 36 | () => this.findOccurrences(), |
36 | FIND_OCCURRENCES_TIMEOUT_MS, | 37 | FIND_OCCURRENCES_TIMEOUT, |
37 | ); | 38 | ); |
38 | 39 | ||
39 | constructor( | 40 | constructor( |
diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts index 1f7e446f..cd5d280d 100644 --- a/subprojects/frontend/src/xtext/XtextClient.ts +++ b/subprojects/frontend/src/xtext/XtextClient.ts | |||
@@ -4,6 +4,7 @@ import type { | |||
4 | } from '@codemirror/autocomplete'; | 4 | } from '@codemirror/autocomplete'; |
5 | import type { Transaction } from '@codemirror/state'; | 5 | import type { Transaction } from '@codemirror/state'; |
6 | 6 | ||
7 | import type PWAStore from '../PWAStore'; | ||
7 | import type EditorStore from '../editor/EditorStore'; | 8 | import type EditorStore from '../editor/EditorStore'; |
8 | import getLogger from '../utils/getLogger'; | 9 | import getLogger from '../utils/getLogger'; |
9 | 10 | ||
@@ -30,7 +31,7 @@ export default class XtextClient { | |||
30 | 31 | ||
31 | private readonly occurrencesService: OccurrencesService; | 32 | private readonly occurrencesService: OccurrencesService; |
32 | 33 | ||
33 | constructor(store: EditorStore) { | 34 | constructor(store: EditorStore, private readonly pwaStore: PWAStore) { |
34 | this.webSocketClient = new XtextWebSocketClient( | 35 | this.webSocketClient = new XtextWebSocketClient( |
35 | () => this.onReconnect(), | 36 | () => this.onReconnect(), |
36 | () => this.onDisconnect(), | 37 | () => this.onDisconnect(), |
@@ -54,6 +55,7 @@ export default class XtextClient { | |||
54 | private onReconnect(): void { | 55 | private onReconnect(): void { |
55 | this.updateService.onReconnect(); | 56 | this.updateService.onReconnect(); |
56 | this.occurrencesService.onReconnect(); | 57 | this.occurrencesService.onReconnect(); |
58 | this.pwaStore.checkForUpdates(); | ||
57 | } | 59 | } |
58 | 60 | ||
59 | private onDisconnect(): void { | 61 | private onDisconnect(): void { |
diff --git a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts index cba6f064..a39620cb 100644 --- a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts +++ b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { createAtom, makeAutoObservable, observable } from 'mobx'; | 1 | import { createAtom, makeAutoObservable, observable } from 'mobx'; |
2 | import ms from 'ms'; | ||
2 | import { nanoid } from 'nanoid'; | 3 | import { nanoid } from 'nanoid'; |
3 | import { interpret } from 'xstate'; | 4 | import { interpret } from 'xstate'; |
4 | 5 | ||
@@ -18,7 +19,7 @@ const XTEXT_SUBPROTOCOL_V1 = 'tools.refinery.language.web.xtext.v1'; | |||
18 | 19 | ||
19 | // Use a large enough timeout so that a request can complete successfully | 20 | // Use a large enough timeout so that a request can complete successfully |
20 | // even if the browser has throttled the background tab. | 21 | // even if the browser has throttled the background tab. |
21 | const REQUEST_TIMEOUT = 5000; | 22 | const REQUEST_TIMEOUT = ms('5s'); |
22 | 23 | ||
23 | const log = getLogger('xtext.XtextWebSocketClient'); | 24 | const log = getLogger('xtext.XtextWebSocketClient'); |
24 | 25 | ||
diff --git a/subprojects/frontend/src/xtext/webSocketMachine.ts b/subprojects/frontend/src/xtext/webSocketMachine.ts index 25689cec..a1eee781 100644 --- a/subprojects/frontend/src/xtext/webSocketMachine.ts +++ b/subprojects/frontend/src/xtext/webSocketMachine.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import ms from 'ms'; | ||
1 | import { actions, assign, createMachine, RaiseAction } from 'xstate'; | 2 | import { actions, assign, createMachine, RaiseAction } from 'xstate'; |
2 | 3 | ||
3 | const { raise } = actions; | 4 | const { raise } = actions; |
4 | 5 | ||
5 | const ERROR_WAIT_TIMES = [200, 1000, 5000, 30_000]; | 6 | const ERROR_WAIT_TIMES = ['200', '1s', '5s', '30s'].map(ms); |
6 | 7 | ||
7 | export interface WebSocketContext { | 8 | export interface WebSocketContext { |
8 | webSocketURL: string | undefined; | 9 | webSocketURL: string | undefined; |
@@ -229,9 +230,9 @@ export default createMachine( | |||
229 | needsNetwork: ({ webSocketURL }) => !isWebSocketURLLocal(webSocketURL), | 230 | needsNetwork: ({ webSocketURL }) => !isWebSocketURLLocal(webSocketURL), |
230 | }, | 231 | }, |
231 | delays: { | 232 | delays: { |
232 | IDLE_TIMEOUT: 300_000, | 233 | IDLE_TIMEOUT: ms('5m'), |
233 | OPEN_TIMEOUT: 10_000, | 234 | OPEN_TIMEOUT: ms('10s'), |
234 | PING_PERIOD: 10_000, | 235 | PING_PERIOD: ms('10s'), |
235 | ERROR_WAIT_TIME: ({ errors: { length: retryCount } }) => { | 236 | ERROR_WAIT_TIME: ({ errors: { length: retryCount } }) => { |
236 | const { length } = ERROR_WAIT_TIMES; | 237 | const { length } = ERROR_WAIT_TIMES; |
237 | const index = retryCount < length ? retryCount : length - 1; | 238 | const index = retryCount < length ? retryCount : length - 1; |