@nivaro/react 0.2.56 → 0.3.0

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.
Files changed (59) hide show
  1. package/dist/components/slots/TasksSlot.js +31 -29
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useSessionRecorder.js +1 -1
  4. package/dist/index.d.ts +73 -1
  5. package/dist/index.js +515 -505
  6. package/dist/shared/components/ItemEditForm.js +666 -658
  7. package/dist/shared/components/MyWorkView.js +47 -37
  8. package/dist/shared/components/ProfileView.js +163 -144
  9. package/dist/shared/components/ai/AiPlanCard.js +427 -0
  10. package/dist/shared/components/ai/AiPlanChanges.js +117 -0
  11. package/dist/shared/components/ai/TaskDo.js +1022 -0
  12. package/dist/shared/components/chat/ChatAnalyticsView.js +19 -17
  13. package/dist/shared/components/chat/ChatPanel.js +1356 -1317
  14. package/dist/shared/components/chat/HuddleAnalyticsTab.js +198 -0
  15. package/dist/shared/components/chat/RoomHeaderMenu.js +78 -65
  16. package/dist/shared/components/chat/chat-core.js +273 -264
  17. package/dist/shared/components/chat/huddle/HuddleAudioUi.js +397 -0
  18. package/dist/shared/components/chat/huddle/HuddleCallBar.js +296 -0
  19. package/dist/shared/components/chat/huddle/HuddleCallLayer.js +180 -0
  20. package/dist/shared/components/chat/huddle/HuddleCamera.js +124 -0
  21. package/dist/shared/components/chat/huddle/HuddleCollab.js +320 -0
  22. package/dist/shared/components/chat/huddle/HuddleControls.js +82 -121
  23. package/dist/shared/components/chat/huddle/HuddleDraw.js +231 -0
  24. package/dist/shared/components/chat/huddle/HuddleLiveBadge.js +52 -0
  25. package/dist/shared/components/chat/huddle/HuddlePeoplePicker.js +143 -0
  26. package/dist/shared/components/chat/huddle/HuddleScheduleCard.js +190 -0
  27. package/dist/shared/components/chat/huddle/HuddleScheduleForm.js +188 -0
  28. package/dist/shared/components/chat/huddle/HuddleStage.js +184 -89
  29. package/dist/shared/components/chat/huddle/HuddleStageTools.js +197 -0
  30. package/dist/shared/components/chat/huddle/huddle-audio-logic.js +156 -0
  31. package/dist/shared/components/chat/huddle/huddle-audio.js +69 -0
  32. package/dist/shared/components/chat/huddle/huddle-calls.js +129 -0
  33. package/dist/shared/components/chat/huddle/huddle-camera.js +143 -0
  34. package/dist/shared/components/chat/huddle/huddle-collab-store.js +391 -0
  35. package/dist/shared/components/chat/huddle/huddle-device-prefs.js +55 -0
  36. package/dist/shared/components/chat/huddle/huddle-devices.js +99 -0
  37. package/dist/shared/components/chat/huddle/huddle-draw.js +226 -0
  38. package/dist/shared/components/chat/huddle/huddle-follow-bus.js +96 -0
  39. package/dist/shared/components/chat/huddle/huddle-hold.js +62 -0
  40. package/dist/shared/components/chat/huddle/huddle-link-quality.js +159 -0
  41. package/dist/shared/components/chat/huddle/huddle-live.js +82 -0
  42. package/dist/shared/components/chat/huddle/huddle-pip.js +343 -0
  43. package/dist/shared/components/chat/huddle/huddle-quality.js +22 -0
  44. package/dist/shared/components/chat/huddle/huddle-reactions.js +71 -0
  45. package/dist/shared/components/chat/huddle/huddle-ring-refused.js +34 -0
  46. package/dist/shared/components/chat/huddle/huddle-schedule.js +102 -0
  47. package/dist/shared/components/chat/huddle/huddle-sfu.js +176 -0
  48. package/dist/shared/components/chat/huddle/huddle-shortcuts.js +91 -0
  49. package/dist/shared/components/chat/huddle/huddle-speaking.js +100 -0
  50. package/dist/shared/components/chat/huddle/huddle-store.js +431 -157
  51. package/dist/shared/components/chat/huddle/useHuddle.js +46 -38
  52. package/dist/shared/components/chat/huddle/useHuddleAudio.js +35 -0
  53. package/dist/shared/components/item-edit/GroupSection.js +1 -0
  54. package/dist/shared/components/item-edit/RecordChatActions.js +68 -59
  55. package/dist/shared/components/item-edit/UserChip.js +145 -142
  56. package/dist/shared/components/panels/TaskPanel.js +51 -49
  57. package/dist/shared/components/support/TicketDetailSheet.js +57 -42
  58. package/dist/shared/lib/notification-sound.js +25 -16
  59. package/package.json +2 -1
@@ -0,0 +1,226 @@
1
+ var M = Object.defineProperty;
2
+ var _ = (r, t, e) => t in r ? M(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var l = (r, t, e) => _(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import { chatAvatarColorIndex as N, chatAvatarColorAt as U, chatAvatarColor as C } from "../chat-core.js";
5
+ import { huddleStore as h } from "./huddle-store.js";
6
+ const E = 23, v = "nvr-huddle-draw", c = 4e3, g = 1e3, m = 600, O = 16e3, y = /^[A-Za-z0-9_-]{1,64}$/, d = (r) => r < 0 ? 0 : r > 1 ? 1 : r, u = (r) => typeof r == "number" && Number.isFinite(r);
7
+ function F(r) {
8
+ if (typeof r != "string" || r.length > O) return null;
9
+ try {
10
+ return D(JSON.parse(r));
11
+ } catch {
12
+ return null;
13
+ }
14
+ }
15
+ function D(r) {
16
+ if (!r || typeof r != "object") return null;
17
+ const t = r;
18
+ return typeof t.s != "string" || !y.test(t.s) ? null : t.t === "clr" ? { t: "clr", s: t.s } : t.t === "pt" ? !u(t.x) || !u(t.y) ? null : { t: "pt", s: t.s, x: d(t.x), y: d(t.y) } : t.t === "st" ? typeof t.id != "string" || !y.test(t.id) || t.tool !== "pen" && t.tool !== "arrow" || !u(t.k) || t.k < 0 || t.k >= m || !Number.isInteger(t.k) || !Array.isArray(t.p) || t.p.length % 2 || t.p.length > m * 2 || !t.p.every(u) ? null : { t: "st", s: t.s, id: t.id, tool: t.tool, k: t.k, p: t.p.map(d) } : null;
19
+ }
20
+ function A(r) {
21
+ return C(r);
22
+ }
23
+ function q(r) {
24
+ return r <= c - g ? 1 : r >= c ? 0 : (c - r) / g;
25
+ }
26
+ function G(r, t, e, s) {
27
+ if (!e || !s || !r || !t) return { x: 0, y: 0, w: r, h: t };
28
+ const n = Math.min(r / e, t / s), o = e * n, i = s * n;
29
+ return { x: (r - o) / 2, y: (t - i) / 2, w: o, h: i };
30
+ }
31
+ const k = 64, I = 2e3;
32
+ function R(r) {
33
+ if (r.t !== "st" || r.p.length <= k * 2) return [r];
34
+ const t = [];
35
+ for (let e = 0; e < r.p.length; e += k * 2)
36
+ t.push({ ...r, k: r.k + e / 2, p: r.p.slice(e, e + k * 2) });
37
+ return t;
38
+ }
39
+ class x {
40
+ constructor() {
41
+ l(this, "marks", /* @__PURE__ */ new Map());
42
+ l(this, "pointers", /* @__PURE__ */ new Map());
43
+ l(this, "channels", /* @__PURE__ */ new Map());
44
+ l(this, "listeners", /* @__PURE__ */ new Set());
45
+ l(this, "snap", { version: 0, marks: this.marks, pointers: this.pointers });
46
+ l(this, "seq", 0);
47
+ l(this, "subscribe", (t) => (this.listeners.add(t), () => {
48
+ this.listeners.delete(t);
49
+ }));
50
+ l(this, "getSnapshot", () => this.snap);
51
+ /** My user id, for my own colour (the store only knows my socket). */
52
+ l(this, "selfUser", "");
53
+ /** After a `huddle:mark:slow` from the server, pointer moves pause until then. */
54
+ l(this, "slowUntil", 0);
55
+ l(this, "ext", {
56
+ attach: (t) => [
57
+ t.on("huddle:mark", (e) => this.onSocketMark(e)),
58
+ t.on("huddle:mark:slow", (e) => {
59
+ (e == null ? void 0 : e.room) === h.getSnapshot().room && (this.slowUntil = Date.now() + I);
60
+ }),
61
+ h.subscribeRosters(() => this.dropGone())
62
+ ],
63
+ link: (t, e) => {
64
+ if (typeof e.createDataChannel != "function") return;
65
+ let s;
66
+ try {
67
+ s = e.createDataChannel(v, {
68
+ negotiated: !0,
69
+ id: E,
70
+ ordered: !0,
71
+ maxRetransmits: 2
72
+ });
73
+ } catch {
74
+ return;
75
+ }
76
+ this.channels.set(t, s), s.onmessage = (n) => {
77
+ const o = F(n.data);
78
+ o && this.apply(t, o);
79
+ }, s.onclose = () => {
80
+ this.channels.get(t) === s && this.channels.delete(t);
81
+ };
82
+ },
83
+ unlink: (t) => {
84
+ this.channels.delete(t), this.dropFrom(t);
85
+ },
86
+ teardown: () => {
87
+ this.channels.clear(), this.marks.clear(), this.pointers.clear(), this.changed();
88
+ }
89
+ });
90
+ }
91
+ changed() {
92
+ this.snap = { version: this.snap.version + 1, marks: this.marks, pointers: this.pointers };
93
+ for (const t of this.listeners) t();
94
+ }
95
+ who(t, e) {
96
+ const s = h.getSnapshot();
97
+ if (t === s.self) return { name: "You", color: A(this.myUser() || t) };
98
+ const n = s.peers.find((i) => i.socket === t), o = e == null ? null : U(e);
99
+ return { name: (n == null ? void 0 : n.name) || "Someone", color: o ?? A((n == null ? void 0 : n.user) || t) };
100
+ }
101
+ myUser() {
102
+ var e, s;
103
+ if (this.selfUser) return this.selfUser;
104
+ const t = h.getSnapshot();
105
+ return !t.room || !t.self ? "" : ((s = (e = h.roster(t.room)) == null ? void 0 : e.find((n) => n.socket === t.self)) == null ? void 0 : s.user) ?? "";
106
+ }
107
+ /** Apply one message from `from` (a peer's socket, or mine); `colorIndex` = the socket path's. */
108
+ apply(t, e, s = Date.now(), n) {
109
+ if (e.t === "clr")
110
+ return !this.marks.has(e.s) && !this.pointers.has(e.s) ? void 0 : (this.marks.delete(e.s), this.pointers.delete(e.s), this.changed());
111
+ const { name: o, color: i } = this.who(t, n);
112
+ if (e.t === "pt") {
113
+ let a = this.pointers.get(e.s);
114
+ return a || (a = /* @__PURE__ */ new Map(), this.pointers.set(e.s, a)), a.set(t, { from: t, x: e.x, y: e.y, at: s, color: i, name: o }), this.changed();
115
+ }
116
+ const S = `${t}:${e.id}`, p = this.marks.get(e.s) ?? [];
117
+ let f = p.find((a) => a.key === S);
118
+ f || (f = { key: S, from: t, tool: e.tool, pts: [], at: s, color: i, name: o }, p.push(f), this.marks.set(e.s, p));
119
+ for (let a = 0; a < e.p.length; a += 2) {
120
+ const w = e.k + a / 2;
121
+ w < m && (f.pts[w] = [e.p[a], e.p[a + 1]]);
122
+ }
123
+ for (let a = 0; a < f.pts.length; a++)
124
+ f.pts[a] || (f.pts[a] = f.pts[a - 1] ?? [0, 0]);
125
+ f.at = s, this.changed();
126
+ }
127
+ /** Forget everything older than MARK_LIFE_MS; true when anything is still showing. */
128
+ prune(t = Date.now()) {
129
+ let e = !1;
130
+ for (const [s, n] of this.marks) {
131
+ const o = n.filter((i) => t - i.at < c);
132
+ o.length !== n.length && (e = !0), o.length ? this.marks.set(s, o) : this.marks.delete(s);
133
+ }
134
+ for (const [s, n] of this.pointers) {
135
+ for (const [o, i] of n)
136
+ t - i.at >= c && (n.delete(o), e = !0);
137
+ n.size || this.pointers.delete(s);
138
+ }
139
+ return e && this.changed(), this.marks.size > 0 || this.pointers.size > 0;
140
+ }
141
+ /** People (not me) with a live mark or pointer on `screen`. */
142
+ pointing(t, e = Date.now()) {
143
+ var o;
144
+ const s = h.getSnapshot().self, n = /* @__PURE__ */ new Set();
145
+ for (const i of this.marks.get(t) ?? []) e - i.at < c && n.add(i.from);
146
+ for (const i of ((o = this.pointers.get(t)) == null ? void 0 : o.values()) ?? [])
147
+ e - i.at < c && n.add(i.from);
148
+ return s && n.delete(s), n.size;
149
+ }
150
+ /** Send to every peer and show it here at once. */
151
+ send(t) {
152
+ const e = h.getSnapshot(), s = e.self;
153
+ if (!s) return;
154
+ if (this.apply(s, t), e.mode === "sfu") {
155
+ if (t.t === "pt" && Date.now() < this.slowUntil) return;
156
+ const o = N(this.myUser() || s);
157
+ for (const i of R(t)) h.send("huddle:mark", { ...i, c: o });
158
+ return;
159
+ }
160
+ const n = JSON.stringify(t);
161
+ for (const o of this.channels.values())
162
+ if (o.readyState === "open")
163
+ try {
164
+ o.send(n);
165
+ } catch {
166
+ }
167
+ }
168
+ nextStrokeId() {
169
+ return this.seq += 1, `${Date.now().toString(36)}${this.seq}`;
170
+ }
171
+ /** A mark relayed over the socket (#2859): the server named the sender; the rest is checked. */
172
+ onSocketMark(t) {
173
+ const e = h.getSnapshot();
174
+ if (!t || e.status !== "live" || t.room !== e.room) return;
175
+ const s = t.from;
176
+ if (typeof s != "string" || !y.test(s) || s === e.self) return;
177
+ const n = D(t);
178
+ n && this.apply(s, n, Date.now(), typeof t.c == "number" ? t.c : void 0);
179
+ }
180
+ /** People who left the roster take their marks with them (the SFU has no unlink). */
181
+ dropGone() {
182
+ const t = h.getSnapshot();
183
+ if (!t.room || t.mode !== "sfu") return;
184
+ const e = new Set((h.roster(t.room) ?? []).map((n) => n.socket));
185
+ if (!e.size) return;
186
+ const s = /* @__PURE__ */ new Set();
187
+ for (const [n, o] of this.marks) {
188
+ e.has(n) || s.add(n);
189
+ for (const i of o) e.has(i.from) || s.add(i.from);
190
+ }
191
+ for (const [n, o] of this.pointers) {
192
+ e.has(n) || s.add(n);
193
+ for (const i of o.keys()) e.has(i) || s.add(i);
194
+ }
195
+ for (const n of s) this.dropFrom(n);
196
+ }
197
+ dropFrom(t) {
198
+ let e = !1;
199
+ for (const [s, n] of this.marks) {
200
+ const o = n.filter((i) => i.from !== t);
201
+ o.length !== n.length && (e = !0), o.length ? this.marks.set(s, o) : this.marks.delete(s);
202
+ }
203
+ (this.marks.delete(t) || this.pointers.delete(t)) && (e = !0);
204
+ for (const s of this.pointers.values()) s.delete(t) && (e = !0);
205
+ e && this.changed();
206
+ }
207
+ }
208
+ const z = new x();
209
+ function K() {
210
+ h.use(z.ext);
211
+ }
212
+ export {
213
+ E as DRAW_CHANNEL_ID,
214
+ v as DRAW_CHANNEL_LABEL,
215
+ g as MARK_FADE_MS,
216
+ c as MARK_LIFE_MS,
217
+ k as SOCKET_MAX_POINTS,
218
+ G as contentRect,
219
+ A as drawColor,
220
+ z as drawStore,
221
+ K as installHuddleDraw,
222
+ q as markOpacity,
223
+ F as parseDrawMsg,
224
+ D as parseDrawObject,
225
+ R as splitForSocket
226
+ };
@@ -0,0 +1,96 @@
1
+ import { useRef as f, useEffect as S } from "react";
2
+ const v = 1500;
3
+ let i = [], R = 1, o = null;
4
+ const d = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Set();
5
+ function a() {
6
+ for (const e of d) e();
7
+ }
8
+ function h() {
9
+ var e;
10
+ return ((e = i.at(-1)) == null ? void 0 : e.view) ?? null;
11
+ }
12
+ function m(e) {
13
+ return d.add(e), () => {
14
+ d.delete(e);
15
+ };
16
+ }
17
+ function C(e) {
18
+ return w.add(e), () => {
19
+ w.delete(e);
20
+ };
21
+ }
22
+ function p(e, r) {
23
+ if (!e || !r) return !1;
24
+ const t = String(e.itemId ?? e.id ?? ""), n = String(r.itemId ?? r.id ?? "");
25
+ return e.collection === r.collection && !!t && t.toUpperCase() === n.toUpperCase();
26
+ }
27
+ function T(e, r, t) {
28
+ const n = i.at(-1);
29
+ return !n || !p(n.view, { collection: e, itemId: r }) ? !1 : (n.view.step === t || (o = { token: n.token, step: t }, n.setStep(t)), !0);
30
+ }
31
+ function V(e = document) {
32
+ const r = e.querySelectorAll("[data-section-key]");
33
+ for (const t of r) {
34
+ const n = t.getBoundingClientRect();
35
+ if (n.height !== 0 && n.bottom > 140)
36
+ return t.dataset.sectionKey ?? null;
37
+ }
38
+ return null;
39
+ }
40
+ function E(e, r = document) {
41
+ const t = r.querySelector(`[data-section-key="${CSS.escape(e)}"]`);
42
+ return t ? (typeof t.scrollIntoView == "function" && t.scrollIntoView({ block: "start", behavior: "smooth" }), !0) : !1;
43
+ }
44
+ function y(e, r) {
45
+ const t = R++;
46
+ return i = [...i, { token: t, view: e, setStep: r, since: Date.now() }], a(), {
47
+ update(n) {
48
+ const u = i.find((l) => l.token === t);
49
+ if (!u) return;
50
+ const c = u.view;
51
+ if (u.view = n, n.step !== c.step) {
52
+ if ((o == null ? void 0 : o.token) === t && o.step === n.step) o = null;
53
+ else if (c.step !== null && p(c, n) && Date.now() - u.since > v && u === i.at(-1))
54
+ for (const s of w) s();
55
+ }
56
+ a();
57
+ },
58
+ remove() {
59
+ i = i.filter((n) => n.token !== t), (o == null ? void 0 : o.token) === t && (o = null), a();
60
+ }
61
+ };
62
+ }
63
+ function q({
64
+ collection: e,
65
+ itemId: r,
66
+ step: t,
67
+ setStep: n
68
+ }) {
69
+ const u = f(n);
70
+ u.current = n;
71
+ const c = f(null), l = f(t);
72
+ l.current = t, S(() => {
73
+ if (!r) return;
74
+ const s = y(
75
+ { collection: e, itemId: r, step: l.current },
76
+ (k) => u.current(k)
77
+ );
78
+ return c.current = s, () => {
79
+ s.remove(), c.current === s && (c.current = null);
80
+ };
81
+ }, [e, r]), S(() => {
82
+ var s;
83
+ r && ((s = c.current) == null || s.update({ collection: e, itemId: r, step: t }));
84
+ }, [e, r, t]);
85
+ }
86
+ export {
87
+ T as applyFollowStep,
88
+ h as currentRecordView,
89
+ V as currentSection,
90
+ C as onManualRecordChange,
91
+ y as registerRecordSurface,
92
+ p as sameRecord,
93
+ E as scrollToSection,
94
+ m as subscribeRecordView,
95
+ q as useHuddleFollowSurface
96
+ };
@@ -0,0 +1,62 @@
1
+ import { huddleStore as i } from "./huddle-store.js";
2
+ const c = /* @__PURE__ */ new Set();
3
+ let o = [], e = null;
4
+ function a() {
5
+ for (const t of c) t();
6
+ }
7
+ function d(t) {
8
+ return (t == null ? void 0 : t.huddle_hold_notifications) !== !1;
9
+ }
10
+ function v(t) {
11
+ const n = i.getSnapshot();
12
+ return d(t) && n.status === "live" && !!n.room;
13
+ }
14
+ function S(t) {
15
+ return o = [...o, { ...t, at: Date.now() }].slice(-200), a(), !0;
16
+ }
17
+ function m(t) {
18
+ return c.add(t), () => {
19
+ c.delete(t);
20
+ };
21
+ }
22
+ function p() {
23
+ return o.length;
24
+ }
25
+ function w(t) {
26
+ if (!t.length) return null;
27
+ const n = t.filter((f) => f.kind === "notification").length, l = t.length - n, u = [];
28
+ return n && u.push(`${n} notification${n === 1 ? "" : "s"}`), l && u.push(`${l} chat message${l === 1 ? "" : "s"}`), `${u.join(" and ")} arrived during your huddle`;
29
+ }
30
+ function H(t) {
31
+ return e = t, () => {
32
+ e === t && (e = null);
33
+ };
34
+ }
35
+ function h() {
36
+ const t = o;
37
+ return o = [], a(), t.length && (e == null || e(t)), t;
38
+ }
39
+ let r = !1, s = !1;
40
+ function $() {
41
+ if (r) return () => {
42
+ };
43
+ r = !0, s = i.getSnapshot().status === "live";
44
+ const t = i.subscribe(() => {
45
+ const n = i.getSnapshot().status === "live";
46
+ s && !n && h(), s = n;
47
+ });
48
+ return () => {
49
+ t(), r = !1;
50
+ };
51
+ }
52
+ export {
53
+ p as getHeldSnapshot,
54
+ w as heldSummary,
55
+ S as holdNotification,
56
+ d as holdPreferenceOn,
57
+ v as huddleHolds,
58
+ H as onHeldRelease,
59
+ h as releaseHeld,
60
+ m as subscribeHeld,
61
+ $ as watchHuddleForRelease
62
+ };
@@ -0,0 +1,159 @@
1
+ var v = Object.defineProperty;
2
+ var B = (e, t, s) => t in e ? v(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var c = (e, t, s) => B(e, typeof t != "symbol" ? t + "" : t, s);
4
+ import { summarizeStats as w, PoorDetector as x } from "./huddle-audio-logic.js";
5
+ import { linkSummaryOf as L } from "./huddle-quality.js";
6
+ import { huddleStore as p } from "./huddle-store.js";
7
+ const b = { peers: {}, poor: !1 }, M = 2e3, D = { maxBitrate: 25e4, scaleResolutionDownBy: 2 };
8
+ function S(e, t) {
9
+ if (!t || t === "unknown") return e;
10
+ const s = t === "excellent" ? 4 : t === "good" ? 3 : 1, o = e.bars === 0 ? s : Math.min(e.bars, s);
11
+ return { ...e, bars: o, poor: e.poor || t === "poor" || t === "lost" };
12
+ }
13
+ const m = () => ({ cursor: null, detector: new x(), lowered: null });
14
+ class O {
15
+ constructor(t, s = M) {
16
+ c(this, "state", b);
17
+ c(this, "listeners", /* @__PURE__ */ new Set());
18
+ c(this, "watches", /* @__PURE__ */ new Map());
19
+ /** My own side: every mesh link poor, or (SFU) my uplink poor. */
20
+ c(this, "local", m());
21
+ c(this, "mode", null);
22
+ c(this, "timer", null);
23
+ c(this, "polling", !1);
24
+ c(this, "started", !1);
25
+ c(this, "subscribe", (t) => (this.listeners.add(t), () => {
26
+ this.listeners.delete(t);
27
+ }));
28
+ c(this, "getSnapshot", () => this.state);
29
+ this.host = t, this.pollMs = s;
30
+ }
31
+ emit(t) {
32
+ this.state = t;
33
+ for (const s of this.listeners) s();
34
+ }
35
+ start() {
36
+ this.started || typeof window > "u" || (this.started = !0, this.host.subscribe(() => this.sync()), this.sync());
37
+ }
38
+ reset() {
39
+ this.watches.clear(), this.local = m(), this.mode = null;
40
+ }
41
+ sync() {
42
+ const t = !!this.host.live();
43
+ t && !this.timer ? this.timer = setInterval(() => void this.poll(), this.pollMs) : !t && this.timer && (clearInterval(this.timer), this.timer = null, this.reset(), this.host.report(null), this.emit(b));
44
+ }
45
+ async poll() {
46
+ if (!this.polling) {
47
+ this.polling = !0;
48
+ try {
49
+ await this.sample();
50
+ } finally {
51
+ this.polling = !1;
52
+ }
53
+ }
54
+ }
55
+ /** One poll (public for tests). */
56
+ async sample(t = Date.now()) {
57
+ const s = this.host.live();
58
+ if (!s) return;
59
+ const o = await this.host.sources();
60
+ this.mode !== o.mode && (this.reset(), this.mode = o.mode);
61
+ const n = {};
62
+ let r;
63
+ if (o.mode === "mesh") {
64
+ this.prune(o.links.map((i) => i.socket));
65
+ let l = 0, u = 0;
66
+ for (const i of o.links) {
67
+ if (i.pc.connectionState !== "connected") continue;
68
+ let h;
69
+ try {
70
+ h = [...(await i.pc.getStats()).values()];
71
+ } catch {
72
+ continue;
73
+ }
74
+ const { quality: f, watch: d } = this.measure(i.socket, h, null, t, !0);
75
+ n[i.socket] = f, l++;
76
+ const y = d.detector.push(f.poor, t);
77
+ y && u++, await g(d, i.screenSender, y);
78
+ }
79
+ r = this.local.detector.push(l > 0 && u === l, t);
80
+ } else if (o.sfu) {
81
+ const l = o.sfu;
82
+ this.prune(l.peers.map((i) => i.socket));
83
+ for (const i of l.peers) {
84
+ const { quality: h, watch: f } = this.measure(i.socket, i.reports, i.grade, t, !0);
85
+ n[i.socket] = h, f.detector.push(h.poor, t);
86
+ }
87
+ const u = this.measureLocal(l.local.reports, l.local.grade, t);
88
+ r = this.local.detector.push(u.poor, t), await g(this.local, l.screenSender, r);
89
+ } else
90
+ r = this.local.detector.active;
91
+ const a = { peers: n, poor: r };
92
+ this.emit(a), this.host.report(P(s.room, s.users, a, t));
93
+ }
94
+ prune(t) {
95
+ for (const s of this.watches.keys())
96
+ t.includes(s) || this.watches.delete(s);
97
+ }
98
+ measure(t, s, o, n, r) {
99
+ let a = this.watches.get(t);
100
+ a || (a = m(), this.watches.set(t, a));
101
+ const { quality: l, cursor: u } = w(s, a.cursor, n);
102
+ a.cursor = u;
103
+ const i = S(l, o);
104
+ return r && this.host.record(t, L(i, u)), { quality: i, watch: a };
105
+ }
106
+ measureLocal(t, s, o) {
107
+ const { quality: n, cursor: r } = w(t, this.local.cursor, o);
108
+ return this.local.cursor = r, S(n, s);
109
+ }
110
+ }
111
+ async function g(e, t, s) {
112
+ e.lowered && e.lowered !== t && (e.lowered = null), t && (s && !e.lowered ? await k(t, D) && (e.lowered = t) : !s && e.lowered && await k(t, null) && (e.lowered = null));
113
+ }
114
+ async function k(e, t) {
115
+ var s;
116
+ try {
117
+ const o = e.getParameters();
118
+ (s = o.encodings) != null && s.length || (o.encodings = [{}]);
119
+ const n = o.encodings[0];
120
+ return t ? (n.maxBitrate = t.maxBitrate, n.scaleResolutionDownBy = t.scaleResolutionDownBy) : (delete n.maxBitrate, n.scaleResolutionDownBy = 1), await e.setParameters(o), !0;
121
+ } catch {
122
+ return !1;
123
+ }
124
+ }
125
+ function P(e, t, s, o) {
126
+ return {
127
+ at: o,
128
+ room: e,
129
+ poor: s.poor,
130
+ peers: Object.entries(s.peers).map(([n, r]) => ({
131
+ socket: n,
132
+ user: t.get(n) ?? "",
133
+ rtt: r.rtt,
134
+ loss: r.loss,
135
+ jitter: r.jitter,
136
+ path: r.path,
137
+ inKbps: r.inKbps,
138
+ outKbps: r.outKbps,
139
+ bars: r.bars
140
+ }))
141
+ };
142
+ }
143
+ const R = {
144
+ subscribe: (e) => p.subscribe(e),
145
+ live: () => {
146
+ const e = p.getSnapshot();
147
+ return e.status !== "live" || !e.room ? null : { room: e.room, users: new Map(e.peers.map((t) => [t.socket, t.user])) };
148
+ },
149
+ sources: () => p.qualitySources(),
150
+ report: (e) => p.reportQuality(e),
151
+ record: (e, t) => p.recordLinkStats(e, t)
152
+ }, I = new O(R);
153
+ export {
154
+ D as POOR_SCREEN,
155
+ M as QUALITY_POLL_MS,
156
+ O as QualityEngine,
157
+ I as huddleQuality,
158
+ S as withSfuGrade
159
+ };
@@ -0,0 +1,82 @@
1
+ var c = Object.defineProperty;
2
+ var u = (e, t, s) => t in e ? c(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var i = (e, t, s) => u(e, typeof t != "symbol" ? t + "" : t, s);
4
+ import { useEffect as f, useSyncExternalStore as a, useMemo as m } from "react";
5
+ import { useOptionalRealtime as d } from "../../../lib/realtime.js";
6
+ const o = [], y = 300, S = 12e4;
7
+ class p {
8
+ constructor() {
9
+ i(this, "rooms", o);
10
+ i(this, "listeners", /* @__PURE__ */ new Set());
11
+ i(this, "transport", null);
12
+ i(this, "offs", []);
13
+ i(this, "timer", null);
14
+ i(this, "resync", null);
15
+ i(this, "subscribe", (t) => (this.listeners.add(t), this.syncTimer(), () => {
16
+ this.listeners.delete(t), this.syncTimer();
17
+ }));
18
+ i(this, "getSnapshot", () => this.rooms);
19
+ }
20
+ syncTimer() {
21
+ this.listeners.size && !this.resync ? this.resync = setInterval(() => this.watch(), S) : !this.listeners.size && this.resync && (clearInterval(this.resync), this.resync = null);
22
+ }
23
+ watch() {
24
+ var t;
25
+ (t = this.transport) == null || t.emit("huddle:live-watch", {});
26
+ }
27
+ /** Bind the host's socket adapter once; the same adapter again is a no-op. */
28
+ attach(t) {
29
+ if (this.transport !== t) {
30
+ for (const s of this.offs) s();
31
+ this.transport = t, this.offs = [
32
+ t.on("huddle:live", (s) => {
33
+ this.rooms = Array.isArray(s == null ? void 0 : s.rooms) ? s.rooms : o;
34
+ for (const r of this.listeners) r();
35
+ }),
36
+ t.on("huddle:live-poke", () => {
37
+ this.timer || (this.timer = setTimeout(() => {
38
+ this.timer = null, this.watch();
39
+ }, y));
40
+ }),
41
+ // Sign-in and every reconnect: the server forgot us, so ask again.
42
+ t.on("auth:ok", () => this.watch())
43
+ ], this.watch();
44
+ }
45
+ }
46
+ /** Test hook. */
47
+ reset() {
48
+ for (const t of this.offs) t();
49
+ this.offs = [], this.transport = null, this.rooms = o;
50
+ }
51
+ }
52
+ const n = new p();
53
+ function v(e) {
54
+ const t = new Map(e.map((s) => [s.room, s]));
55
+ return {
56
+ rooms: e,
57
+ /** People in the room's huddle (0 = none visible). */
58
+ countFor: (s) => {
59
+ var r;
60
+ return s ? ((r = t.get(s)) == null ? void 0 : r.count) ?? 0 : 0;
61
+ },
62
+ /** The huddle a person is in, if the viewer can see that room. */
63
+ roomOf: (s) => {
64
+ if (!s) return null;
65
+ const r = String(s).toUpperCase();
66
+ return e.find((h) => h.users.some((l) => String(l).toUpperCase() === r)) ?? null;
67
+ }
68
+ };
69
+ }
70
+ function g() {
71
+ const e = d();
72
+ f(() => {
73
+ e && n.attach(e);
74
+ }, [e]);
75
+ const t = a(n.subscribe, n.getSnapshot, () => o);
76
+ return m(() => v(t), [t]);
77
+ }
78
+ export {
79
+ n as huddleLive,
80
+ v as liveLookups,
81
+ g as useHuddleLive
82
+ };