@lightworkai.official/debug-capture 0.19.11 → 0.19.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/live.d.ts CHANGED
@@ -9,6 +9,18 @@ export interface RingingCall {
9
9
  ringUntil: string;
10
10
  side?: string | null;
11
11
  }
12
+ /**
13
+ * The support host restarting (a deploy — it says 1012 as it stops): every widget on every page of every host app lost
14
+ * its socket in the same instant, and each came back after exactly 2 s — the whole fleet's tickets, sign-ins and
15
+ * sockets on the support host's one thread in the same second. Back somewhere in this window instead, at random.
16
+ */
17
+ export declare const RESTART_SPREAD_MS = 15000;
18
+ /**
19
+ * How long before trying again — each step ×0.5–1.5, never the same moment as every other widget's (the desk's own tabs
20
+ * do the same) — `restart`: the host said it restarts (1012); `slow`:
21
+ * refused for now (429), or nobody signed in yet; else the next step of the ladder. Pure but for the dice, for the tests.
22
+ */
23
+ export declare function retryWait(how: "restart" | "slow" | null, attempt: number, roll?: () => number): number;
12
24
  /** `wss://support.example/api/presence/ws?t=…` — the support host's scheme, the socket's own path. Pure, for the tests. */
13
25
  export declare function liveSocketUrl(host: string, ticket: string): string;
14
26
  /** Where the card sends them: their request, with the call — the support host rings it there. Pure, for the tests. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightworkai.official/debug-capture",
3
- "version": "0.19.11",
3
+ "version": "0.19.12",
4
4
  "description": "Report-a-problem widget: rolling network/console/action capture, optional rrweb session replay, annotated screenshot, and submission to a Lightwork Support host",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
package/src/live.ts CHANGED
@@ -42,6 +42,22 @@ export interface RingingCall {
42
42
  }
43
43
 
44
44
  const RETRY_MS = [2000, 5000, 15_000, 30_000, 60_000];
45
+ /**
46
+ * The support host restarting (a deploy — it says 1012 as it stops): every widget on every page of every host app lost
47
+ * its socket in the same instant, and each came back after exactly 2 s — the whole fleet's tickets, sign-ins and
48
+ * sockets on the support host's one thread in the same second. Back somewhere in this window instead, at random.
49
+ */
50
+ export const RESTART_SPREAD_MS = 15_000;
51
+ /**
52
+ * How long before trying again — each step ×0.5–1.5, never the same moment as every other widget's (the desk's own tabs
53
+ * do the same) — `restart`: the host said it restarts (1012); `slow`:
54
+ * refused for now (429), or nobody signed in yet; else the next step of the ladder. Pure but for the dice, for the tests.
55
+ */
56
+ export function retryWait(how: "restart" | "slow" | null, attempt: number, roll: () => number = Math.random): number {
57
+ if (how === "restart") return 1000 + Math.round(roll() * RESTART_SPREAD_MS);
58
+ const step = how === "slow" ? RETRY_MS[RETRY_MS.length - 1]! : RETRY_MS[Math.min(attempt, RETRY_MS.length - 1)]!;
59
+ return Math.round(step * (0.5 + roll()));
60
+ }
45
61
  const LIVE_STATES = new Set(["ringing", "active"]);
46
62
  const PING_MS = 20_000;
47
63
 
@@ -144,9 +160,9 @@ export function stopLiveRing(): void {
144
160
  closeCallFrame();
145
161
  }
146
162
 
147
- function schedule(slow = false): void {
163
+ function schedule(how: "restart" | "slow" | null = null): void {
148
164
  if (stopped) return;
149
- const wait = slow ? RETRY_MS[RETRY_MS.length - 1]! : RETRY_MS[Math.min(retry++, RETRY_MS.length - 1)]!;
165
+ const wait = retryWait(how, how ? retry : retry++);
150
166
  clearTimeout(reconnectTimer);
151
167
  reconnectTimer = setTimeout(() => void connect(), wait);
152
168
  }
@@ -160,7 +176,7 @@ async function connect(): Promise<void> {
160
176
  stopped = true;
161
177
  return;
162
178
  }
163
- return schedule(true);
179
+ return schedule("slow");
164
180
  }
165
181
  tokenless = 0;
166
182
  let res: Response;
@@ -174,7 +190,8 @@ async function connect(): Promise<void> {
174
190
  stopped = true;
175
191
  return;
176
192
  }
177
- if (!res.ok) return schedule(res.status === 429);
193
+ // Refused for now: slowly. The host restarting (its proxy answering for it): back at random within the window.
194
+ if (!res.ok) return schedule(res.status === 429 ? "slow" : res.status === 502 || res.status === 503 ? "restart" : null);
178
195
  let out: { calls?: boolean; ticket?: string | null; call?: RingingCall | null };
179
196
  try {
180
197
  out = await res.json();
@@ -221,10 +238,11 @@ async function connect(): Promise<void> {
221
238
  /* not ours to read */
222
239
  }
223
240
  };
224
- ws.onclose = () => {
241
+ ws.onclose = (e) => {
225
242
  clearInterval(pinger);
226
243
  if (socket === ws) socket = null;
227
- schedule();
244
+ // 1012: the support host is restarting — every widget heard it at once; each comes back at its own moment.
245
+ schedule(e.code === 1012 ? "restart" : null);
228
246
  };
229
247
  }
230
248