@nivaro/react 0.3.8 → 0.3.10
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/components/fields/FileField.js +20 -19
- package/dist/full.css +1 -1
- package/dist/hooks/replayUploadQueue.js +107 -93
- package/dist/hooks/useNivaroForm.js +129 -126
- package/dist/hooks/useSessionRecorder.js +103 -101
- package/dist/index.d.ts +115 -2
- package/dist/index.js +466 -447
- package/dist/shared/components/CollectionBrowserView.js +1058 -1059
- package/dist/shared/components/ConformanceView.js +36 -35
- package/dist/shared/components/DataTable.js +230 -223
- package/dist/shared/components/ForceReloadBanner.js +58 -34
- package/dist/shared/components/ItemEditForm.js +3687 -3580
- package/dist/shared/components/JsonMapEditor.js +18 -17
- package/dist/shared/components/MatrixEditor.js +8 -7
- package/dist/shared/components/MyWorkView.js +32 -31
- package/dist/shared/components/PageRenderer.js +146 -145
- package/dist/shared/components/QueryTable.js +49 -49
- package/dist/shared/components/RecordGridEditor.js +76 -75
- package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
- package/dist/shared/components/ai/AskPanel.js +55 -54
- package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
- package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
- package/dist/shared/components/chat/ChatPanel.js +288 -287
- package/dist/shared/components/chat/SlashCommands.js +30 -29
- package/dist/shared/components/chat/chat-outbox.js +76 -75
- package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
- package/dist/shared/components/integrations/console/SignalCard.js +124 -123
- package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
- package/dist/shared/components/item-edit/CloneDialog.js +85 -78
- package/dist/shared/components/item-edit/InlineTableField.js +301 -300
- package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
- package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
- package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
- package/dist/shared/components/item-edit/staged-links.js +86 -0
- package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
- package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
- package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
- package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
- package/dist/shared/components/panels/CommentPanel.js +237 -236
- package/dist/shared/components/profile/AiMemoryCard.js +15 -14
- package/dist/shared/components/profile/PersonAdminTools.js +70 -67
- package/dist/shared/components/profile/usePersonPresence.js +42 -37
- package/dist/shared/components/queue/QueueItemSheet.js +36 -35
- package/dist/shared/components/queue/QueueWorklist.js +597 -598
- package/dist/shared/lib/client-version.js +63 -0
- package/dist/shared/lib/force-reload.js +36 -0
- package/dist/shared/lib/load-error.js +11 -10
- package/dist/shared/lib/presence-live.js +73 -0
- package/dist/shared/lib/presence-state.js +39 -31
- package/dist/shared/lib/record-outbox.js +76 -75
- package/dist/shared/lib/request-gate.js +120 -102
- package/dist/shared/lib/rum.js +45 -36
- package/dist/shared/lib/safe-error.js +39 -0
- package/dist/shared/lib/server-clock.js +11 -7
- package/dist/shared/lib/signed-out.js +114 -0
- package/dist/shared/lib/socket-realtime.js +19 -17
- package/dist/shared/lib/unsaved-work.js +62 -0
- package/dist/shared/lib/use-online-users.js +11 -10
- package/dist/shared/lib/worker-socket.js +89 -79
- package/package.json +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const T = 1e3, y = 3e5, S = /* @__PURE__ */ new Set([
|
|
2
|
+
"NOT_SIGNED_IN",
|
|
3
|
+
"SESSION_EXPIRED",
|
|
4
|
+
"TOKEN_INVALID",
|
|
5
|
+
"ACCOUNT_NOT_ACTIVE"
|
|
6
|
+
]), _ = /^(MASQUERADE_|KEY_SIM_)/, E = /* @__PURE__ */ new Set(["/auth/me", "/users/me", "/auth/ws-token"]);
|
|
7
|
+
let r = !1, u = 0, i = 0;
|
|
8
|
+
const a = /* @__PURE__ */ new Set();
|
|
9
|
+
let o, f = !1;
|
|
10
|
+
function d(t, n = Math.random) {
|
|
11
|
+
const e = Math.min(1e3 * 2 ** Math.max(0, t - 1), 3e5);
|
|
12
|
+
return Math.min(3e5, Math.round(e * (0.75 + n() * 0.5)));
|
|
13
|
+
}
|
|
14
|
+
function I(t) {
|
|
15
|
+
var s;
|
|
16
|
+
const n = t, e = typeof (n == null ? void 0 : n.status) == "number" ? n.status : (s = n == null ? void 0 : n.response) == null ? void 0 : s.status;
|
|
17
|
+
return typeof e == "number" ? e : void 0;
|
|
18
|
+
}
|
|
19
|
+
function N(t) {
|
|
20
|
+
var s;
|
|
21
|
+
const n = t == null ? void 0 : t.response, e = (n == null ? void 0 : n.code) ?? ((s = n == null ? void 0 : n.data) == null ? void 0 : s.code);
|
|
22
|
+
return typeof e == "string" ? e : void 0;
|
|
23
|
+
}
|
|
24
|
+
function O(t, n = !1) {
|
|
25
|
+
if (I(t) !== 401) return !1;
|
|
26
|
+
const e = N(t);
|
|
27
|
+
return e && _.test(e) ? !1 : n || e != null && S.has(e);
|
|
28
|
+
}
|
|
29
|
+
function D() {
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
function g(t = !0) {
|
|
33
|
+
r && !t || (u += 1, r = !0, i = Date.now() + d(u));
|
|
34
|
+
}
|
|
35
|
+
function c() {
|
|
36
|
+
const t = r;
|
|
37
|
+
if (r = !1, u = 0, i = 0, t)
|
|
38
|
+
for (const n of [...a])
|
|
39
|
+
try {
|
|
40
|
+
n();
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
return t;
|
|
44
|
+
}
|
|
45
|
+
function l() {
|
|
46
|
+
if (o !== void 0) return o;
|
|
47
|
+
o = null;
|
|
48
|
+
try {
|
|
49
|
+
typeof BroadcastChannel == "function" && (o = new BroadcastChannel("nvr-auth"), o.onmessage = (t) => {
|
|
50
|
+
var n;
|
|
51
|
+
((n = t.data) == null ? void 0 : n.t) === "signed-in" && c();
|
|
52
|
+
});
|
|
53
|
+
} catch {
|
|
54
|
+
o = null;
|
|
55
|
+
}
|
|
56
|
+
return o;
|
|
57
|
+
}
|
|
58
|
+
function h() {
|
|
59
|
+
const t = l();
|
|
60
|
+
if (!(!c() && f)) {
|
|
61
|
+
f = !0;
|
|
62
|
+
try {
|
|
63
|
+
t == null || t.postMessage({ t: "signed-in" });
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function w() {
|
|
69
|
+
c();
|
|
70
|
+
}
|
|
71
|
+
function C(t) {
|
|
72
|
+
return l(), a.add(t), () => {
|
|
73
|
+
a.delete(t);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function M() {
|
|
77
|
+
if (!r) return !0;
|
|
78
|
+
const t = Date.now();
|
|
79
|
+
return t < i ? !1 : (i = t + d(u), !0);
|
|
80
|
+
}
|
|
81
|
+
function G() {
|
|
82
|
+
return Object.assign(new Error("Not signed in"), {
|
|
83
|
+
status: 401,
|
|
84
|
+
response: { error: "Not signed in", code: "NOT_SIGNED_IN" },
|
|
85
|
+
signedOutGate: !0
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function p(t, n, e) {
|
|
89
|
+
return (t ?? "GET").toUpperCase() !== "GET" || !n || e && typeof e == "object" && Object.keys(e).length > 0 ? !1 : E.has(n);
|
|
90
|
+
}
|
|
91
|
+
async function A(t, n) {
|
|
92
|
+
if (!M()) return n();
|
|
93
|
+
try {
|
|
94
|
+
const e = await t();
|
|
95
|
+
return h(), e;
|
|
96
|
+
} catch (e) {
|
|
97
|
+
throw O(e, !0) && g(), e;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
y as SIGNED_OUT_MAX_MS,
|
|
102
|
+
T as SIGNED_OUT_MIN_MS,
|
|
103
|
+
M as claimIdentityCall,
|
|
104
|
+
A as guardIdentityCall,
|
|
105
|
+
p as isIdentityRead,
|
|
106
|
+
D as isSignedOut,
|
|
107
|
+
O as isSignedOutError,
|
|
108
|
+
w as noteCredentialChanged,
|
|
109
|
+
h as noteSignedIn,
|
|
110
|
+
g as noteUnauthorized,
|
|
111
|
+
C as onSignedIn,
|
|
112
|
+
d as signedOutBackoff,
|
|
113
|
+
G as signedOutError
|
|
114
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var N = Object.defineProperty;
|
|
2
2
|
var U = (i, n, r) => n in i ? N(i, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[n] = r;
|
|
3
|
-
var
|
|
3
|
+
var _ = (i, n, r) => U(i, typeof n != "symbol" ? n + "" : n, r);
|
|
4
4
|
import { bindClientChaosSocket as k } from "./client-chaos.js";
|
|
5
5
|
import { deliveryAckFor as L } from "./delivery-ack.js";
|
|
6
6
|
import { forgetSettledReads as y } from "./request-gate.js";
|
|
@@ -11,9 +11,9 @@ const p = {
|
|
|
11
11
|
configUpdate: "nvr:config-update",
|
|
12
12
|
forceRefresh: "nvr:force-refresh"
|
|
13
13
|
};
|
|
14
|
-
class
|
|
14
|
+
class C {
|
|
15
15
|
constructor(n, r) {
|
|
16
|
-
|
|
16
|
+
_(this, "refs", /* @__PURE__ */ new Map());
|
|
17
17
|
this.join = n, this.leave = r;
|
|
18
18
|
}
|
|
19
19
|
add(n) {
|
|
@@ -45,33 +45,35 @@ function G(i) {
|
|
|
45
45
|
}, R = () => {
|
|
46
46
|
var e, o, t;
|
|
47
47
|
return ((t = (o = (e = n == null ? void 0 : n.io) == null ? void 0 : e.engine) == null ? void 0 : o.transport) == null ? void 0 : t.name) ?? null;
|
|
48
|
-
},
|
|
48
|
+
}, b = (e, o) => {
|
|
49
49
|
l && clearTimeout(l), l = null, g({ state: "live", transport: R(), refreshed: e, resumed: o });
|
|
50
50
|
}, u = (e, o) => {
|
|
51
51
|
typeof window > "u" || window.dispatchEvent(new CustomEvent(e, { detail: o }));
|
|
52
52
|
}, h = (e, o) => {
|
|
53
53
|
n != null && n.connected && n.emit(e, o);
|
|
54
|
-
},
|
|
54
|
+
}, E = (e, o) => {
|
|
55
55
|
var t;
|
|
56
56
|
for (const s of ((t = n == null ? void 0 : n.listeners) == null ? void 0 : t.call(n, e)) ?? []) s(o);
|
|
57
|
-
},
|
|
58
|
-
for (const o of W(e))
|
|
57
|
+
}, F = (e) => {
|
|
58
|
+
for (const o of W(e)) E(o.event, o.payload);
|
|
59
59
|
u("nvr:realtime-stale", { rooms: e });
|
|
60
60
|
}, m = M({
|
|
61
61
|
request: (e) => h("catchup:room", e),
|
|
62
|
-
dispatch:
|
|
63
|
-
refetch:
|
|
64
|
-
}), q = new
|
|
62
|
+
dispatch: E,
|
|
63
|
+
refetch: F
|
|
64
|
+
}), q = new C(
|
|
65
65
|
(e) => {
|
|
66
66
|
m.reset([`collection:${e}`]), h("collection:join", { collection: e });
|
|
67
67
|
},
|
|
68
68
|
(e) => {
|
|
69
69
|
m.reset([`collection:${e}`]), h("collection:leave", { collection: e });
|
|
70
70
|
}
|
|
71
|
-
), A = new
|
|
72
|
-
|
|
71
|
+
), A = new C(
|
|
72
|
+
// The Traffic Map page reads batched frames (api traffic-map-batch.ts); twin: admin
|
|
73
|
+
// lib/socket.ts watchJoinPayload.
|
|
74
|
+
(e) => h("admin:join", e === "traffic-map" ? { room: e, frames: "batch" } : { room: e }),
|
|
73
75
|
(e) => h("admin:leave", { room: e })
|
|
74
|
-
), S = new
|
|
76
|
+
), S = new C(
|
|
75
77
|
(e) => h("ops:join", { topic: e }),
|
|
76
78
|
(e) => h("ops:leave", { topic: e })
|
|
77
79
|
), w = () => {
|
|
@@ -81,7 +83,7 @@ function G(i) {
|
|
|
81
83
|
return n = e, k(e), j = e.connected, e.on("auth:ok", () => {
|
|
82
84
|
if (m.reset(), q.rejoinAll(), A.rejoinAll(), S.rejoinAll(), j && r > 0) {
|
|
83
85
|
const t = r;
|
|
84
|
-
g({ transport: R() }), l && clearTimeout(l), l = setTimeout(() =>
|
|
86
|
+
g({ transport: R() }), l && clearTimeout(l), l = setTimeout(() => b(null, "unverified"), i.catchupTimeoutMs ?? 8e3), e.emit("catchup", { cursor: t });
|
|
85
87
|
} else
|
|
86
88
|
g({
|
|
87
89
|
state: "live",
|
|
@@ -101,7 +103,7 @@ function G(i) {
|
|
|
101
103
|
d && e.emit("rt:ack", d);
|
|
102
104
|
}), e.on("catchup:room:events", (t) => m.replayed(t)), e.on("realtime:stale", (t) => {
|
|
103
105
|
const s = Array.isArray(t == null ? void 0 : t.rooms) ? t.rooms.filter((c) => typeof c == "string") : [];
|
|
104
|
-
m.reset(s), t != null && t.all ? (v("catchupFull") && u(p.catchupFull, {}), u("nvr:realtime-stale", { rooms: s, all: !0 })) : s.length &&
|
|
106
|
+
m.reset(s), t != null && t.all ? (v("catchupFull") && u(p.catchupFull, {}), u("nvr:realtime-stale", { rooms: s, all: !0 })) : s.length && F(s);
|
|
105
107
|
}), e.on(
|
|
106
108
|
"catchup:events",
|
|
107
109
|
(t) => {
|
|
@@ -110,10 +112,10 @@ function G(i) {
|
|
|
110
112
|
c.seq > r && (r = c.seq);
|
|
111
113
|
for (const d of ((s = e.listeners) == null ? void 0 : s.call(e, c.event)) ?? []) d({ ...c.payload, _seq: c.seq });
|
|
112
114
|
}
|
|
113
|
-
|
|
115
|
+
b(null, "replayed");
|
|
114
116
|
}
|
|
115
117
|
), e.on("catchup:full", (t) => {
|
|
116
|
-
v("catchupFull") && u(p.catchupFull, {}),
|
|
118
|
+
v("catchupFull") && u(p.catchupFull, {}), b(
|
|
117
119
|
(t == null ? void 0 : t.reason) === "slow-consumer" ? "Live updates resumed. This tab fell too far behind to send each change, so the lists and records on this page were reloaded." : "Live updates resumed. The connection was gone too long to replay each change, so the lists and records on this page were reloaded.",
|
|
118
120
|
"reloaded"
|
|
119
121
|
);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useEffect as c } from "react";
|
|
2
|
+
import { subscribeRecordOutbox as f, getRecordOutbox as i } from "./record-outbox.js";
|
|
3
|
+
const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
|
|
4
|
+
let a = 0;
|
|
5
|
+
function u() {
|
|
6
|
+
for (const e of [...s])
|
|
7
|
+
try {
|
|
8
|
+
e();
|
|
9
|
+
} catch {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function d(e, t) {
|
|
13
|
+
const n = ++a;
|
|
14
|
+
return r.set(n, { label: e, dirty: t }), u(), () => {
|
|
15
|
+
r.delete(n) && u();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function l() {
|
|
19
|
+
try {
|
|
20
|
+
return i().length;
|
|
21
|
+
} catch {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function b() {
|
|
26
|
+
const e = [];
|
|
27
|
+
for (const n of r.values()) {
|
|
28
|
+
let o = !1;
|
|
29
|
+
try {
|
|
30
|
+
o = n.dirty();
|
|
31
|
+
} catch {
|
|
32
|
+
o = !1;
|
|
33
|
+
}
|
|
34
|
+
o && !e.includes(n.label) && e.push(n.label);
|
|
35
|
+
}
|
|
36
|
+
const t = l();
|
|
37
|
+
return t && e.push(`${t} save${t === 1 ? "" : "s"} waiting to be sent`), e;
|
|
38
|
+
}
|
|
39
|
+
function g() {
|
|
40
|
+
return b().length > 0;
|
|
41
|
+
}
|
|
42
|
+
function k(e) {
|
|
43
|
+
s.add(e);
|
|
44
|
+
const t = f(e);
|
|
45
|
+
return () => {
|
|
46
|
+
s.delete(e), t();
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function p(e, t = "Unsaved changes") {
|
|
50
|
+
c(() => {
|
|
51
|
+
if (e)
|
|
52
|
+
return d(t, () => !0);
|
|
53
|
+
}, [e, t]);
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
g as hasUnsavedWork,
|
|
57
|
+
u as notifyUnsavedWorkChanged,
|
|
58
|
+
d as registerUnsavedWork,
|
|
59
|
+
k as subscribeUnsavedWork,
|
|
60
|
+
b as unsavedWorkLabels,
|
|
61
|
+
p as useUnsavedWork
|
|
62
|
+
};
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { readOnlinePresence as
|
|
2
|
-
import { useQuery as
|
|
3
|
-
import { useNivaroClient as
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { readOnlinePresence as l } from "@nivaro/sdk";
|
|
2
|
+
import { useQuery as s } from "@tanstack/react-query";
|
|
3
|
+
import { useNivaroClient as u } from "../context.js";
|
|
4
|
+
import { usePresenceOnlinePoll as a } from "./presence-live.js";
|
|
5
|
+
function y(r = !0) {
|
|
6
|
+
const t = u(), n = a(3e4, r), { data: o } = s({
|
|
6
7
|
queryKey: ["presence-online"],
|
|
7
|
-
queryFn: () => t.request(
|
|
8
|
-
select: (e) => ((e == null ? void 0 : e.data) ?? []).map((
|
|
8
|
+
queryFn: () => t.request(l()),
|
|
9
|
+
select: (e) => ((e == null ? void 0 : e.data) ?? []).map((i) => String(i.user_id ?? "").toUpperCase()).filter(Boolean),
|
|
9
10
|
enabled: r,
|
|
10
|
-
refetchInterval:
|
|
11
|
+
refetchInterval: n,
|
|
11
12
|
staleTime: 25e3,
|
|
12
13
|
retry: !1
|
|
13
14
|
});
|
|
14
|
-
return new Set(
|
|
15
|
+
return new Set(o ?? []);
|
|
15
16
|
}
|
|
16
17
|
export {
|
|
17
|
-
|
|
18
|
+
y as useOnlineUsers
|
|
18
19
|
};
|
|
@@ -1,194 +1,204 @@
|
|
|
1
|
-
import { bindClientChaosSocket as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { bindClientChaosSocket as x } from "./client-chaos.js";
|
|
2
|
+
import { onSignedIn as z, signedOutBackoff as F, isSignedOut as U } from "./signed-out.js";
|
|
3
|
+
const j = 1, B = "nvr-realtime-worker";
|
|
4
|
+
function N() {
|
|
4
5
|
return typeof window < "u" && typeof window.SharedWorker == "function";
|
|
5
6
|
}
|
|
6
|
-
function
|
|
7
|
+
function Y() {
|
|
7
8
|
try {
|
|
8
|
-
const o = localStorage.getItem(
|
|
9
|
+
const o = localStorage.getItem(B);
|
|
9
10
|
return o === "on" || o === "off" ? o : null;
|
|
10
11
|
} catch {
|
|
11
12
|
return null;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
if (!
|
|
15
|
+
function $(o) {
|
|
16
|
+
if (!N() || Y() === "off") return !1;
|
|
16
17
|
try {
|
|
17
18
|
return new URL(o, window.location.href).origin === window.location.origin;
|
|
18
19
|
} catch {
|
|
19
20
|
return !1;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
let
|
|
25
|
-
const
|
|
26
|
-
let
|
|
27
|
-
const
|
|
28
|
-
for (const r of [...
|
|
23
|
+
function J(o) {
|
|
24
|
+
const u = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set();
|
|
25
|
+
let c = "pending", s = null, n = null, d = !1, T = null, K = 0;
|
|
26
|
+
const E = /* @__PURE__ */ new Map(), M = [];
|
|
27
|
+
let R = 0, k = null, p = null, m = !1, w = !1, b = 0, h = 0, v = null;
|
|
28
|
+
const A = (e, t) => {
|
|
29
|
+
for (const r of [...u.get(e) ?? []])
|
|
29
30
|
try {
|
|
30
31
|
r(...t);
|
|
31
32
|
} catch {
|
|
32
33
|
}
|
|
33
|
-
for (const r of [...
|
|
34
|
+
for (const r of [...g])
|
|
34
35
|
try {
|
|
35
36
|
r(e, ...t);
|
|
36
37
|
} catch {
|
|
37
38
|
}
|
|
38
|
-
},
|
|
39
|
+
}, C = () => {
|
|
39
40
|
if (k && clearTimeout(k), k = null, p && clearInterval(p), p = null, s)
|
|
40
41
|
try {
|
|
41
42
|
s.postMessage({ t: "bye" }), s.close();
|
|
42
43
|
} catch {
|
|
43
44
|
}
|
|
44
45
|
s = null;
|
|
45
|
-
},
|
|
46
|
-
var
|
|
47
|
-
if (
|
|
48
|
-
const t =
|
|
49
|
-
|
|
46
|
+
}, l = (e) => {
|
|
47
|
+
var i, y, S;
|
|
48
|
+
if (c === "fallback" || m) return;
|
|
49
|
+
const t = d;
|
|
50
|
+
C(), c = "fallback", d = !1;
|
|
50
51
|
const r = o.fallback();
|
|
51
|
-
n = r, w && ((
|
|
52
|
-
for (const [
|
|
53
|
-
|
|
52
|
+
n = r, w && ((i = r.disconnect) == null || i.call(r));
|
|
53
|
+
for (const [O, W] of u) for (const q of W) r.on(O, q);
|
|
54
|
+
g.size && ((y = r.onAny) == null || y.call(r, (O, ...W) => I(O, W))), t && A("disconnect", ["worker-fallback"]), (S = o.onMode) == null || S.call(o, "fallback", e);
|
|
54
55
|
};
|
|
55
|
-
function
|
|
56
|
-
for (const r of [...
|
|
56
|
+
function I(e, t) {
|
|
57
|
+
for (const r of [...g])
|
|
57
58
|
try {
|
|
58
59
|
r(e, ...t);
|
|
59
60
|
} catch {
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
const
|
|
63
|
+
const D = () => a({
|
|
63
64
|
t: "hello",
|
|
64
65
|
app: o.app,
|
|
65
66
|
features: o.features ?? [],
|
|
66
67
|
version: o.version ?? {},
|
|
67
68
|
active: typeof document > "u" || document.visibilityState === "visible"
|
|
68
|
-
}),
|
|
69
|
+
}), a = (e) => {
|
|
69
70
|
try {
|
|
70
71
|
s == null || s.postMessage(e);
|
|
71
72
|
} catch {
|
|
72
|
-
|
|
73
|
+
l("port-closed");
|
|
73
74
|
}
|
|
74
|
-
},
|
|
75
|
+
}, L = (e) => {
|
|
75
76
|
var r;
|
|
76
77
|
const t = e.data;
|
|
77
78
|
if (!(!t || typeof t != "object" || m))
|
|
78
|
-
switch (
|
|
79
|
+
switch (R = Date.now(), t.t) {
|
|
79
80
|
case "ready": {
|
|
80
|
-
if (k && clearTimeout(k), k = null, t.proto !==
|
|
81
|
-
|
|
82
|
-
Date.now() -
|
|
81
|
+
if (k && clearTimeout(k), k = null, t.proto !== j) return l(`proto-${String(t.proto)}`);
|
|
82
|
+
c = "worker", w || D(), p = setInterval(() => {
|
|
83
|
+
Date.now() - R > (o.silentMs ?? 2e4) && l("worker-silent");
|
|
83
84
|
}, 5e3), (r = o.onMode) == null || r.call(o, "worker", "ready");
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
86
87
|
case "ping":
|
|
87
|
-
|
|
88
|
+
a({ t: "pong" });
|
|
88
89
|
return;
|
|
89
90
|
case "status": {
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
91
|
+
d = !!t.connected;
|
|
92
|
+
const i = typeof t.transport == "string" ? t.transport : null, y = i === "websocket" && T !== "websocket";
|
|
93
|
+
if (T = i, y) for (const S of M.splice(0)) S();
|
|
93
94
|
return;
|
|
94
95
|
}
|
|
95
96
|
case "need-token":
|
|
96
|
-
|
|
97
|
+
P().then(
|
|
98
|
+
(i) => a({ t: "token", req: t.req, token: i, ...i ? {} : { signedOut: U() } })
|
|
99
|
+
);
|
|
97
100
|
return;
|
|
98
101
|
case "ev": {
|
|
99
102
|
if (w) return;
|
|
100
|
-
t.event === "connect" && (
|
|
103
|
+
t.event === "connect" && (d = !0), t.event === "disconnect" && (d = !1), A(String(t.event), Array.isArray(t.args) ? t.args : []);
|
|
101
104
|
return;
|
|
102
105
|
}
|
|
103
106
|
case "ack": {
|
|
104
|
-
const
|
|
105
|
-
|
|
107
|
+
const i = E.get(t.id);
|
|
108
|
+
E.delete(t.id), i == null || i(...Array.isArray(t.args) ? t.args : []);
|
|
106
109
|
return;
|
|
107
110
|
}
|
|
108
111
|
case "fallback":
|
|
109
|
-
|
|
112
|
+
l(String(t.reason ?? "worker"));
|
|
110
113
|
return;
|
|
111
114
|
default:
|
|
112
115
|
return;
|
|
113
116
|
}
|
|
114
|
-
},
|
|
115
|
-
if (
|
|
117
|
+
}, P = async () => {
|
|
118
|
+
if (Date.now() < h) return null;
|
|
119
|
+
const e = await o.authToken().catch(() => null);
|
|
120
|
+
return e ? (b = 0, h = 0, e) : (b += 1, h = Date.now() + F(b), null);
|
|
121
|
+
}, _ = () => {
|
|
122
|
+
if (!$(o.url)) return l("unsupported");
|
|
116
123
|
try {
|
|
117
124
|
const e = new SharedWorker(o.url, { name: o.name ?? o.app });
|
|
118
|
-
s = e.port, s.onmessage =
|
|
125
|
+
s = e.port, s.onmessage = L, s.onmessageerror = () => l("message-error"), e.onerror = () => l("worker-error"), s.start(), k = setTimeout(() => l("no-greeting"), o.readyTimeoutMs ?? 15e3);
|
|
119
126
|
} catch {
|
|
120
|
-
|
|
127
|
+
l("construct-failed");
|
|
121
128
|
}
|
|
122
129
|
if (typeof window < "u") {
|
|
123
130
|
const e = () => {
|
|
124
|
-
|
|
131
|
+
c === "worker" && document.visibilityState === "visible" && a({ t: "active" });
|
|
125
132
|
};
|
|
126
133
|
document.addEventListener("visibilitychange", e), window.addEventListener("focus", e), window.addEventListener("pagehide", () => {
|
|
127
|
-
|
|
134
|
+
c === "worker" && a({ t: "bye" });
|
|
128
135
|
});
|
|
129
136
|
}
|
|
130
137
|
}, f = {
|
|
131
138
|
get connected() {
|
|
132
|
-
return w &&
|
|
139
|
+
return w && c !== "fallback" ? !1 : c === "fallback" ? !!(n != null && n.connected) : d;
|
|
133
140
|
},
|
|
134
141
|
on(e, t) {
|
|
135
|
-
const r =
|
|
136
|
-
return
|
|
142
|
+
const r = u.get(e) ?? /* @__PURE__ */ new Set();
|
|
143
|
+
return u.set(e, r), r.add(t), c === "fallback" && (n == null || n.on(e, t)), f;
|
|
137
144
|
},
|
|
138
145
|
off(e, t) {
|
|
139
146
|
var r;
|
|
140
|
-
return t ? (r =
|
|
147
|
+
return t ? (r = u.get(e)) == null || r.delete(t) : u.delete(e), c === "fallback" && (n == null || n.off(e, t)), f;
|
|
141
148
|
},
|
|
142
149
|
once(e, t) {
|
|
143
|
-
const r = (...
|
|
144
|
-
f.off(e, r), t(...
|
|
150
|
+
const r = (...i) => {
|
|
151
|
+
f.off(e, r), t(...i);
|
|
145
152
|
};
|
|
146
153
|
return f.on(e, r);
|
|
147
154
|
},
|
|
148
155
|
onAny(e) {
|
|
149
156
|
var r;
|
|
150
|
-
const t =
|
|
151
|
-
return
|
|
157
|
+
const t = g.size === 0;
|
|
158
|
+
return g.add(e), c === "fallback" && t && ((r = n == null ? void 0 : n.onAny) == null || r.call(n, (i, ...y) => I(i, y))), f;
|
|
152
159
|
},
|
|
153
160
|
offAny(e) {
|
|
154
|
-
return
|
|
161
|
+
return g.delete(e), f;
|
|
155
162
|
},
|
|
156
163
|
listeners(e) {
|
|
157
|
-
return [...
|
|
164
|
+
return [...u.get(e) ?? []];
|
|
158
165
|
},
|
|
159
166
|
emit(e, ...t) {
|
|
160
|
-
if (
|
|
167
|
+
if (c === "fallback") return n == null ? void 0 : n.emit(e, ...t);
|
|
161
168
|
const r = t[t.length - 1];
|
|
162
169
|
if (w)
|
|
163
170
|
return typeof r == "function" && setTimeout(() => r(), 0), f;
|
|
164
171
|
if (typeof r == "function") {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
} else
|
|
172
|
+
const i = ++K;
|
|
173
|
+
E.set(i, r), a({ t: "emit", event: e, payload: t[0], ack: i });
|
|
174
|
+
} else a({ t: "emit", event: e, payload: t[0] });
|
|
168
175
|
return f;
|
|
169
176
|
},
|
|
170
177
|
connect() {
|
|
171
178
|
var e;
|
|
172
|
-
|
|
179
|
+
c === "fallback" ? (e = n == null ? void 0 : n.connect) == null || e.call(n) : a({ t: "connect" });
|
|
173
180
|
},
|
|
174
181
|
disconnect() {
|
|
175
182
|
var e;
|
|
176
|
-
m = !0,
|
|
183
|
+
m = !0, v == null || v(), C(), (e = n == null ? void 0 : n.disconnect) == null || e.call(n);
|
|
177
184
|
},
|
|
178
|
-
|
|
185
|
+
signedIn() {
|
|
186
|
+
b = 0, h = 0, !(c !== "worker" || m) && (a({ t: "signed-in" }), (typeof document > "u" || document.visibilityState === "visible") && a({ t: "active" }));
|
|
187
|
+
},
|
|
188
|
+
mode: () => c,
|
|
179
189
|
chaosPause(e) {
|
|
180
190
|
var t, r;
|
|
181
191
|
if (!(e === w || m)) {
|
|
182
|
-
if (w = e,
|
|
192
|
+
if (w = e, c === "fallback") {
|
|
183
193
|
e ? (t = n == null ? void 0 : n.disconnect) == null || t.call(n) : (r = n == null ? void 0 : n.connect) == null || r.call(n);
|
|
184
194
|
return;
|
|
185
195
|
}
|
|
186
196
|
if (e) {
|
|
187
|
-
const
|
|
188
|
-
|
|
197
|
+
const i = d;
|
|
198
|
+
d = !1, i && A("disconnect", ["transport close"]);
|
|
189
199
|
return;
|
|
190
200
|
}
|
|
191
|
-
|
|
201
|
+
c === "worker" && D(), typeof window < "u" && window.dispatchEvent(new CustomEvent("nvr:catchup-full"));
|
|
192
202
|
}
|
|
193
203
|
},
|
|
194
204
|
io: {
|
|
@@ -197,23 +207,23 @@ function j(o) {
|
|
|
197
207
|
return {
|
|
198
208
|
get name() {
|
|
199
209
|
var e, t, r;
|
|
200
|
-
return
|
|
210
|
+
return c === "fallback" ? (r = (t = (e = n == null ? void 0 : n.io) == null ? void 0 : e.engine) == null ? void 0 : t.transport) == null ? void 0 : r.name : T ?? void 0;
|
|
201
211
|
}
|
|
202
212
|
};
|
|
203
213
|
},
|
|
204
214
|
once(e, t) {
|
|
205
|
-
e === "upgrade" &&
|
|
215
|
+
e === "upgrade" && M.push(t);
|
|
206
216
|
}
|
|
207
217
|
}
|
|
208
218
|
}
|
|
209
219
|
};
|
|
210
|
-
return
|
|
220
|
+
return v = z(() => f.signedIn()), _(), x(f), f;
|
|
211
221
|
}
|
|
212
222
|
export {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
223
|
+
B as WORKER_SOCKET_PREF_KEY,
|
|
224
|
+
j as WORKER_SOCKET_PROTO,
|
|
225
|
+
J as createWorkerSocket,
|
|
226
|
+
N as sharedWorkerSupported,
|
|
227
|
+
$ as shouldUseWorkerSocket,
|
|
228
|
+
Y as workerSocketPreference
|
|
219
229
|
};
|