mirror of
https://github.com/stablyai/orca.git
synced 2026-10-17 16:02:55 +00:00
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { remoteRuntimeUnavailableError } from './remote-runtime-request-frames'
|
|
import {
|
|
finishSharedControlSubscription,
|
|
scheduleSharedControlReconnect
|
|
} from './remote-runtime-shared-control-state'
|
|
import type { SharedControlLogicalSubscription } from './remote-runtime-shared-control-types'
|
|
|
|
export function scheduleSharedControlReconnectOrFinish(args: {
|
|
current: ReturnType<typeof setTimeout> | null
|
|
intentionallyClosed: boolean
|
|
reconnectAttempt: number
|
|
delaysMs: readonly number[]
|
|
subscriptions: Map<string, SharedControlLogicalSubscription<unknown>>
|
|
open: () => void
|
|
}): { timer: ReturnType<typeof setTimeout> | null; reconnectAttempt: number } {
|
|
if (args.reconnectAttempt >= args.delaysMs.length) {
|
|
const error = remoteRuntimeUnavailableError(
|
|
'Remote Orca runtime connection could not be restored.'
|
|
)
|
|
for (const subscription of Array.from(args.subscriptions.values())) {
|
|
finishSharedControlSubscription(args.subscriptions, subscription, true, error)
|
|
}
|
|
return { timer: null, reconnectAttempt: args.reconnectAttempt }
|
|
}
|
|
return scheduleSharedControlReconnect(args)
|
|
}
|