From 9dd708db5d382d8037ad4f8c60153abdbf2d922e Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Wed, 23 Aug 2023 16:49:04 -0400 Subject: [PATCH] Make the timeout for a WebRTC/WebSocket connection pair configurable (#310) Signed-off-by: Paul Tagliamonte --- .env.development | 1 + .env.production | 3 ++- src/env.ts | 2 ++ src/lang/std/engineConnection.ts | 7 +++++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.env.development b/.env.development index 96a7dee66..ac3804b58 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1,4 @@ VITE_KC_API_WS_MODELING_URL=wss://api.dev.kittycad.io/ws/modeling/commands VITE_KC_API_BASE_URL=https://api.dev.kittycad.io VITE_KC_SITE_BASE_URL=https://dev.kittycad.io +VITE_KC_CONNECTION_TIMEOUT_MS=5000 diff --git a/.env.production b/.env.production index b15dc29b5..5cc25ccd9 100644 --- a/.env.production +++ b/.env.production @@ -1,3 +1,4 @@ VITE_KC_API_WS_MODELING_URL=wss://api.kittycad.io/ws/modeling/commands VITE_KC_API_BASE_URL=https://api.kittycad.io -VITE_KC_SITE_BASE_URL=https://kittycad.io \ No newline at end of file +VITE_KC_SITE_BASE_URL=https://kittycad.io +VITE_KC_CONNECTION_TIMEOUT_MS=15000 diff --git a/src/env.ts b/src/env.ts index 2683e92b9..5cab36611 100644 --- a/src/env.ts +++ b/src/env.ts @@ -8,4 +8,6 @@ export const VITE_KC_API_WS_MODELING_URL = import.meta.env .VITE_KC_API_WS_MODELING_URL export const VITE_KC_API_BASE_URL = import.meta.env.VITE_KC_API_BASE_URL export const VITE_KC_SITE_BASE_URL = import.meta.env.VITE_KC_SITE_BASE_URL +export const VITE_KC_CONNECTION_TIMEOUT_MS = import.meta.env + .VITE_KC_CONNECTION_TIMEOUT_MS export const TEST = import.meta.env.TEST diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index b565ffcad..542f2e4c8 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -1,6 +1,9 @@ import { SourceRange } from '../executor' import { Selections } from '../../useStore' -import { VITE_KC_API_WS_MODELING_URL } from '../../env' +import { + VITE_KC_API_WS_MODELING_URL, + VITE_KC_CONNECTION_TIMEOUT_MS, +} from '../../env' import { Models } from '@kittycad/lib' import { exportSave } from '../../lib/exportSave' import { v4 as uuidv4 } from 'uuid' @@ -243,7 +246,7 @@ export class EngineConnection extends EventTarget { // TODO(paultag): This ought to be both controllable, as well as something // like exponential backoff to have some grace on the backend, as well as // fix responsiveness for clients that had a weird network hiccup. - const connectionTimeoutMs = 3000 + const connectionTimeoutMs = VITE_KC_CONNECTION_TIMEOUT_MS setTimeout(() => { if (this.isReady()) {