@usero/sdk 1.1.7 → 1.1.9

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.
@@ -86,6 +86,7 @@ interface RecorderStore {
86
86
  indicatorRoot: ShadowRoot | null;
87
87
  indicatorState: 'recording' | 'finishing' | 'done' | 'no-audio' | 'error';
88
88
  pageHideHandler: (() => void) | null;
89
+ visibilityHandler: (() => void) | null;
89
90
  options: Required<UserTestOptions>;
90
91
  tasks: UserTestTask[];
91
92
  tasksPanelOpen: boolean;
@@ -86,6 +86,7 @@ interface RecorderStore {
86
86
  indicatorRoot: ShadowRoot | null;
87
87
  indicatorState: 'recording' | 'finishing' | 'done' | 'no-audio' | 'error';
88
88
  pageHideHandler: (() => void) | null;
89
+ visibilityHandler: (() => void) | null;
89
90
  options: Required<UserTestOptions>;
90
91
  tasks: UserTestTask[];
91
92
  tasksPanelOpen: boolean;
@@ -4,7 +4,12 @@ var DEFAULT_API_URL = "https://usero.io";
4
4
  // src/plugins/user-test.ts
5
5
  var DEFAULT_OPTIONS = {
6
6
  queryParam: "usero_test",
7
- chunkSeconds: 30,
7
+ // 10s (not 30) so at most ~10s of audio is at risk if the tab is torn
8
+ // down before a flush, and so a session shorter than the old 30s window
9
+ // still emits at least one chunk (previously its single buffered chunk was
10
+ // never flushed and its audio was lost). Tradeoff: ~3x the R2 writes /
11
+ // upload requests per session; 10s is an acceptable balance, don't go lower.
12
+ chunkSeconds: 10,
8
13
  apiUrl: DEFAULT_API_URL,
9
14
  testerName: "",
10
15
  hideIndicator: false
@@ -1570,6 +1575,7 @@ function userTest(options = {}) {
1570
1575
  indicatorRoot: null,
1571
1576
  indicatorState: "recording",
1572
1577
  pageHideHandler: null,
1578
+ visibilityHandler: null,
1573
1579
  options: { ...merged, apiUrl },
1574
1580
  tasks: [],
1575
1581
  tasksPanelOpen: readTasksPanelOpen(),
@@ -1677,6 +1683,12 @@ function userTest(options = {}) {
1677
1683
  };
1678
1684
  store.pageHideHandler = pageHide;
1679
1685
  window.addEventListener("pagehide", pageHide);
1686
+ const onVisibilityChange = () => {
1687
+ if (document.visibilityState !== "hidden") return;
1688
+ void finishFlow(store, ctx, { showThanks: false });
1689
+ };
1690
+ store.visibilityHandler = onVisibilityChange;
1691
+ document.addEventListener("visibilitychange", onVisibilityChange);
1680
1692
  void (async () => {
1681
1693
  const adoptId = getAdoptSessionId();
1682
1694
  const created = adoptId ? await adoptSession(apiUrl, adoptId) : await createSession(apiUrl, slug, readTesterName(merged.testerName));
@@ -1712,6 +1724,10 @@ function userTest(options = {}) {
1712
1724
  window.removeEventListener("pagehide", store.pageHideHandler);
1713
1725
  store.pageHideHandler = null;
1714
1726
  }
1727
+ if (store.visibilityHandler) {
1728
+ document.removeEventListener("visibilitychange", store.visibilityHandler);
1729
+ store.visibilityHandler = null;
1730
+ }
1715
1731
  stopRecording(store);
1716
1732
  if (store.outsidePointerHandler) {
1717
1733
  document.removeEventListener("pointerdown", store.outsidePointerHandler, true);