@nivaro/react 0.2.55 → 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 (60) 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 +101 -1
  5. package/dist/index.js +538 -525
  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/dist/shared/lib/stale-chunk.js +60 -0
  60. package/package.json +2 -1
@@ -0,0 +1,143 @@
1
+ var h = Object.defineProperty;
2
+ var d = (r, t, s) => t in r ? h(r, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[t] = s;
3
+ var o = (r, t, s) => d(r, typeof t != "symbol" ? t + "" : t, s);
4
+ import { huddleStore as n } from "./huddle-store.js";
5
+ const u = 4;
6
+ function f(r, t = u) {
7
+ const s = r.filter((e) => !!e.cam).sort((e, i) => (e.cam_at ?? 0) - (i.cam_at ?? 0) || (e.socket < i.socket ? -1 : 1));
8
+ return new Set(s.slice(t).map((e) => e.socket));
9
+ }
10
+ function v(r, t) {
11
+ return t > 0 && t < 360 && r > 1 ? "strip" : r <= 1 ? "one" : "two";
12
+ }
13
+ const l = { stream: null, starting: !1, paused: !1, error: null };
14
+ class m {
15
+ constructor() {
16
+ o(this, "state", l);
17
+ o(this, "listeners", /* @__PURE__ */ new Set());
18
+ o(this, "senders", /* @__PURE__ */ new Map());
19
+ /** The SFU link my camera is published on (#2859), while the huddle is large. */
20
+ o(this, "sfu", null);
21
+ o(this, "subscribe", (t) => (this.listeners.add(t), () => {
22
+ this.listeners.delete(t);
23
+ }));
24
+ o(this, "getSnapshot", () => this.state);
25
+ o(this, "ext", {
26
+ attach: () => [n.subscribeRosters(() => this.evaluate())],
27
+ link: (t, s) => this.addTo(t, s),
28
+ unlink: (t) => {
29
+ this.senders.delete(t);
30
+ },
31
+ joined: () => {
32
+ this.state.stream && n.send("huddle:state", { camera: this.state.stream.id });
33
+ },
34
+ sfu: (t) => this.publishOn(t),
35
+ teardown: () => {
36
+ var t;
37
+ for (const s of ((t = this.state.stream) == null ? void 0 : t.getTracks()) ?? []) s.stop();
38
+ this.senders.clear(), this.sfu = null, this.set({ ...l });
39
+ }
40
+ });
41
+ }
42
+ set(t) {
43
+ this.state = { ...this.state, ...t };
44
+ for (const s of this.listeners) s();
45
+ }
46
+ track() {
47
+ var t;
48
+ return ((t = this.state.stream) == null ? void 0 : t.getVideoTracks()[0]) ?? null;
49
+ }
50
+ async start() {
51
+ if (n.getSnapshot().status !== "live" || this.state.stream || this.state.starting) return;
52
+ this.set({ starting: !0, error: null });
53
+ let s;
54
+ try {
55
+ s = await navigator.mediaDevices.getUserMedia({
56
+ video: {
57
+ width: { ideal: 640 },
58
+ height: { ideal: 360 },
59
+ frameRate: { ideal: 15, max: 15 }
60
+ },
61
+ audio: !1
62
+ });
63
+ } catch (a) {
64
+ const c = a == null ? void 0 : a.name;
65
+ this.set({
66
+ starting: !1,
67
+ error: c === "NotAllowedError" ? "Camera access was refused. Allow it in the browser and try again." : c === "NotFoundError" ? "No camera was found." : "The camera could not be started."
68
+ });
69
+ return;
70
+ }
71
+ if (n.getSnapshot().status !== "live") {
72
+ for (const a of s.getTracks()) a.stop();
73
+ this.set({ starting: !1 });
74
+ return;
75
+ }
76
+ const e = s.getVideoTracks()[0];
77
+ e && (e.onended = () => this.stop()), this.set({ stream: s, starting: !1 }), n.send("huddle:state", { camera: s.id }), n.forEachLink((a, c) => this.addTo(a, c));
78
+ const i = n.sfuSession();
79
+ i && this.publishOn(i);
80
+ }
81
+ publishOn(t) {
82
+ this.sfu = t;
83
+ const s = this.track();
84
+ s && t.publishCamera(s, this.state.paused).catch(() => null);
85
+ }
86
+ stop() {
87
+ var s;
88
+ const t = this.state.stream;
89
+ if (t) {
90
+ for (const e of t.getTracks()) e.stop();
91
+ n.forEachLink((e, i) => {
92
+ const a = this.senders.get(e);
93
+ if (a)
94
+ try {
95
+ i.removeTrack(a);
96
+ } catch {
97
+ }
98
+ }), this.senders.clear(), (s = this.sfu) == null || s.unpublishCamera().catch(() => null), this.set({ ...l }), n.send("huddle:state", { camera: null });
99
+ }
100
+ }
101
+ toggle() {
102
+ this.state.stream ? this.stop() : this.start();
103
+ }
104
+ clearError() {
105
+ this.state.error && this.set({ error: null });
106
+ }
107
+ addTo(t, s) {
108
+ const e = this.track(), i = this.state.stream;
109
+ if (!e || !i || this.senders.has(t) || s.signalingState === "closed") return;
110
+ const a = s.addTrack(e, i);
111
+ this.senders.set(t, a), this.state.paused && a.replaceTrack(null).catch(() => null);
112
+ }
113
+ /** Re-read the roster: pause or resume my sending when my place in line changed. */
114
+ evaluate() {
115
+ var a;
116
+ const t = n.getSnapshot();
117
+ if (!this.state.stream || !t.room || !t.self) {
118
+ this.state.paused && this.set({ paused: !1 });
119
+ return;
120
+ }
121
+ const s = n.roster(t.room) ?? [], e = f(s).has(t.self);
122
+ if (e === this.state.paused) return;
123
+ const i = e ? null : this.track();
124
+ for (const c of this.senders.values()) c.replaceTrack(i).catch(() => null);
125
+ (a = this.sfu) == null || a.setCameraPaused(e).catch(() => null), this.set({ paused: e });
126
+ }
127
+ }
128
+ const p = new m();
129
+ function S() {
130
+ n.use(p.ext);
131
+ }
132
+ function T() {
133
+ var r;
134
+ return typeof navigator < "u" && !!((r = navigator.mediaDevices) != null && r.getUserMedia);
135
+ }
136
+ export {
137
+ u as MAX_LIVE_CAMERAS,
138
+ p as cameraStore,
139
+ T as cameraSupported,
140
+ S as installHuddleCamera,
141
+ f as pausedCameras,
142
+ v as videoLayout
143
+ };
@@ -0,0 +1,391 @@
1
+ var L = Object.defineProperty;
2
+ var E = (n, s, t) => s in n ? L(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
3
+ var r = (n, s, t) => E(n, typeof s != "symbol" ? s + "" : s, t);
4
+ import { subscribeRecordView as N, onManualRecordChange as D, currentRecordView as d, sameRecord as c, currentSection as b, applyFollowStep as F, scrollToSection as B } from "./huddle-follow-bus.js";
5
+ import { huddleStore as m } from "./huddle-store.js";
6
+ const M = 20 * 1024, v = 500, O = 250, _ = 8e3, q = 1e3;
7
+ function A(n) {
8
+ return typeof TextEncoder < "u" ? new TextEncoder().encode(n).length : n.length;
9
+ }
10
+ class S {
11
+ constructor(s) {
12
+ r(this, "state");
13
+ r(this, "listeners", /* @__PURE__ */ new Set());
14
+ r(this, "subscribe", (s) => (this.listeners.add(s), () => {
15
+ this.listeners.delete(s);
16
+ }));
17
+ r(this, "getSnapshot", () => this.state);
18
+ this.state = s;
19
+ }
20
+ set(s) {
21
+ this.state = { ...this.state, ...s };
22
+ for (const t of this.listeners) t();
23
+ }
24
+ }
25
+ const w = {
26
+ room: null,
27
+ text: "",
28
+ rev: 0,
29
+ lastBy: null,
30
+ lastAt: null,
31
+ pending: !1,
32
+ error: null,
33
+ open: !1,
34
+ unseen: !1
35
+ };
36
+ class I extends S {
37
+ constructor(t, e) {
38
+ super(w);
39
+ r(this, "timer", null);
40
+ /** The last note of a huddle I left (null when there was none). */
41
+ r(this, "ended", null);
42
+ r(this, "unpostedListeners", /* @__PURE__ */ new Set());
43
+ this.t = t, this.self = e;
44
+ }
45
+ /** The huddle I am in changed (join, leave, a new room). */
46
+ reset(t) {
47
+ this.state.room !== t && (this.cancel(), this.state.room && this.state.text.trim() && (this.ended = { room: this.state.room, text: this.state.text }), this.set({ ...w, room: t }));
48
+ }
49
+ endedNote(t) {
50
+ var e;
51
+ return ((e = this.ended) == null ? void 0 : e.room) === t ? this.ended.text : null;
52
+ }
53
+ /** The end could not post the notes (the room refused their writer): tell the UI. */
54
+ onUnpostedNote(t) {
55
+ return this.unpostedListeners.add(t), () => {
56
+ this.unpostedListeners.delete(t);
57
+ };
58
+ }
59
+ onUnposted(t) {
60
+ var e;
61
+ if (t != null && t.room) {
62
+ this.endedNote(t.room) || (e = this.t()) == null || e.emit("huddle:note:fetch", { room: t.room });
63
+ for (const i of this.unpostedListeners) i(t);
64
+ }
65
+ }
66
+ onKept(t) {
67
+ t != null && t.room && typeof t.text == "string" && (this.ended = { room: t.room, text: t.text });
68
+ }
69
+ setOpen(t) {
70
+ this.set({ open: t, unseen: t ? !1 : this.state.unseen });
71
+ }
72
+ setText(t) {
73
+ if (!this.state.room) return;
74
+ const e = A(t) > M;
75
+ this.set({
76
+ text: t,
77
+ pending: !e,
78
+ lastBy: null,
79
+ lastAt: Date.now(),
80
+ error: e ? "Notes hold up to 20 KB — shorten them to keep syncing." : null
81
+ }), this.cancel(), e || (this.timer = setTimeout(() => this.flush(), v));
82
+ }
83
+ /** Send a waiting edit now (Leave, or the debounce firing). */
84
+ flush() {
85
+ var l;
86
+ this.cancel();
87
+ const { room: t, text: e, rev: i, pending: o } = this.state;
88
+ !t || !o || ((l = this.t()) == null || l.emit("huddle:note", { room: t, text: e, rev: i }), this.set({ pending: !1 }));
89
+ }
90
+ cancel() {
91
+ this.timer && clearTimeout(this.timer), this.timer = null;
92
+ }
93
+ onNote(t) {
94
+ if (!t || t.room !== this.state.room || !(t.rev > this.state.rev)) return;
95
+ if (!!t.from && t.from === this.self() || this.state.pending) {
96
+ this.set({ rev: t.rev });
97
+ return;
98
+ }
99
+ this.set({
100
+ text: t.text,
101
+ rev: t.rev,
102
+ lastBy: t.by,
103
+ lastAt: Date.now(),
104
+ error: null,
105
+ unseen: !this.state.open && t.text !== this.state.text
106
+ });
107
+ }
108
+ onDenied(t) {
109
+ !t || t.room !== this.state.room || (t.reason === "bad-rev" ? (Number.isSafeInteger(t.rev) && this.set({ rev: t.rev, pending: !0 }), this.cancel(), this.timer = setTimeout(() => this.flush(), v)) : t.reason === "rate" ? (this.set({ pending: !0 }), this.cancel(), this.timer = setTimeout(() => this.flush(), 1e3)) : t.reason === "too-long" && this.set({ pending: !1, error: "Notes hold up to 20 KB — shorten them to keep syncing." }));
110
+ }
111
+ }
112
+ const T = {
113
+ room: null,
114
+ presenter: null,
115
+ target: null,
116
+ presenting: !1,
117
+ following: !1,
118
+ request: null,
119
+ asked: null,
120
+ error: null
121
+ };
122
+ class $ extends S {
123
+ constructor(t, e, i = () => typeof window > "u" ? "" : window.location.pathname) {
124
+ super(T);
125
+ r(this, "nav", null);
126
+ /** Where the last navigation I made went, and until when its page may still be loading. */
127
+ r(this, "navigated", null);
128
+ r(this, "settledPath", null);
129
+ r(this, "poll", null);
130
+ r(this, "moveTimer", null);
131
+ r(this, "lastSent", 0);
132
+ r(this, "lastPos", null);
133
+ r(this, "offBus", []);
134
+ r(this, "onScroll", () => this.queueMove());
135
+ r(this, "askTimer", null);
136
+ /** The tab + section my page was last brought to (a repeat move does not re-scroll). */
137
+ r(this, "applied", null);
138
+ this.t = t, this.self = e, this.path = i, this.offBus = [
139
+ N(() => this.onView()),
140
+ D(() => {
141
+ this.state.following && this.stopFollowing();
142
+ })
143
+ ];
144
+ }
145
+ setNavigator(t) {
146
+ this.nav = t;
147
+ }
148
+ reset(t) {
149
+ this.state.room !== t && (this.endPresenting(), this.stopPolling(), this.navigated = null, this.applied = null, this.askTimer && clearTimeout(this.askTimer), this.askTimer = null, this.set({ ...T, room: t }));
150
+ }
151
+ // ── Presenter ─────────────────────────────────────────────────────────────
152
+ /** Present, or — while someone else does — ask them to hand over. */
153
+ start(t) {
154
+ var a, u;
155
+ const e = this.state.room;
156
+ if (!e) return;
157
+ if (this.state.presenter && this.state.presenter.socket !== this.self()) {
158
+ (a = this.t()) == null || a.emit("huddle:follow", { room: e, action: "request" }), this.setAsked("pending");
159
+ return;
160
+ }
161
+ const o = d();
162
+ t && !c(o, t) && this.nav && this.nav.navigate(this.nav.urlFor({ collection: t.collection, itemId: t.id }));
163
+ const l = this.position(t ?? null);
164
+ this.lastPos = l, this.lastSent = Date.now(), (u = this.t()) == null || u.emit("huddle:follow", { room: e, action: "start", ...l });
165
+ }
166
+ stopPresenting() {
167
+ var e;
168
+ const t = this.state.room;
169
+ !t || !this.state.presenting || (e = this.t()) == null || e.emit("huddle:follow", { room: t, action: "stop" });
170
+ }
171
+ handOver(t) {
172
+ var e;
173
+ this.state.room && ((e = this.t()) == null || e.emit("huddle:follow", { room: this.state.room, action: "handover", to: t })), this.set({ request: null });
174
+ }
175
+ decline(t) {
176
+ var e;
177
+ this.state.room && ((e = this.t()) == null || e.emit("huddle:follow", { room: this.state.room, action: "decline", to: t })), this.set({ request: null });
178
+ }
179
+ position(t) {
180
+ const e = d(), i = t ?? this.state.target, o = e && (!i || c(e, i));
181
+ return {
182
+ step: o ? e.step : null,
183
+ section: o && typeof document < "u" ? b() : null
184
+ };
185
+ }
186
+ beginPresenting() {
187
+ typeof document < "u" && !this.state.presenting && document.addEventListener("scroll", this.onScroll, { capture: !0, passive: !0 });
188
+ }
189
+ endPresenting() {
190
+ typeof document < "u" && document.removeEventListener("scroll", this.onScroll, { capture: !0 }), this.moveTimer && clearTimeout(this.moveTimer), this.moveTimer = null;
191
+ }
192
+ /** Throttled with a trailing send, so where I stop is where followers end up. */
193
+ queueMove() {
194
+ if (!this.state.presenting || this.moveTimer) return;
195
+ const t = Math.max(0, O - (Date.now() - this.lastSent));
196
+ this.moveTimer = setTimeout(() => {
197
+ this.moveTimer = null, this.sendMove();
198
+ }, t);
199
+ }
200
+ sendMove() {
201
+ var o;
202
+ const t = this.state.room;
203
+ if (!t || !this.state.presenting || !this.state.target) return;
204
+ const e = d();
205
+ if (!c(e, this.state.target)) return;
206
+ const i = this.position(null);
207
+ this.lastPos && i.step === this.lastPos.step && i.section === this.lastPos.section || (this.lastPos = i, this.lastSent = Date.now(), (o = this.t()) == null || o.emit("huddle:follow", { room: t, action: "move", ...i }));
208
+ }
209
+ // ── Follower ──────────────────────────────────────────────────────────────
210
+ stopFollowing() {
211
+ this.stopPolling(), this.navigated = null, this.applied = null, this.set({ following: !1 });
212
+ }
213
+ /** Follow the presenter again after stopping. */
214
+ resume() {
215
+ !this.state.presenter || this.state.presenting || (this.set({ following: !0 }), this.drive());
216
+ }
217
+ stopPolling() {
218
+ this.poll && clearInterval(this.poll), this.poll = null, this.settledPath = null;
219
+ }
220
+ startPolling() {
221
+ this.poll || (this.poll = setInterval(() => this.checkPath(), q));
222
+ }
223
+ /** Any route change I did not make while following = the reader went somewhere: stop. */
224
+ checkPath() {
225
+ if (!this.state.following) return this.stopPolling();
226
+ const t = this.navigated;
227
+ if (t && Date.now() < t.until) return;
228
+ const e = this.path();
229
+ if (this.settledPath === null) {
230
+ this.settledPath = e;
231
+ return;
232
+ }
233
+ e !== this.settledPath && this.stopFollowing();
234
+ }
235
+ onView() {
236
+ if (this.state.presenting) {
237
+ this.queueMove();
238
+ return;
239
+ }
240
+ const t = this.state.target;
241
+ !this.state.following || !t || !this.navigated || Date.now() < this.navigated.until && c(d(), t) && (this.navigated = { ...this.navigated, until: 0 }, this.settledPath = this.path(), this.applyPosition(400));
242
+ }
243
+ /** Bring my page to the presenter's record, tab and section. */
244
+ drive() {
245
+ var l;
246
+ const t = this.state.target;
247
+ if (!this.state.following || !t) return;
248
+ this.startPolling();
249
+ const e = d();
250
+ if (c(e, t)) {
251
+ this.applyPosition(120);
252
+ return;
253
+ }
254
+ const i = `${t.collection}:${t.id}`;
255
+ if (((l = this.navigated) == null ? void 0 : l.key) === i || !this.nav) return;
256
+ this.navigated = { key: i, until: Date.now() + _ }, this.settledPath = null;
257
+ const o = t.step ? { step: t.step } : null;
258
+ this.nav.navigate(this.nav.urlFor({ collection: t.collection, itemId: t.id, query: o }));
259
+ }
260
+ applyPosition(t) {
261
+ const e = this.state.target;
262
+ if (!e) return;
263
+ const i = `${e.collection}:${e.id}:${e.step}:${e.section}`;
264
+ if (this.applied === i) return;
265
+ this.applied = i, e.step && F(e.collection, e.id, e.step);
266
+ const o = e.section;
267
+ o && typeof document < "u" && setTimeout(() => {
268
+ var l;
269
+ this.state.following && ((l = this.state.target) == null ? void 0 : l.section) === o && B(o);
270
+ }, t);
271
+ }
272
+ setAsked(t) {
273
+ this.askTimer && clearTimeout(this.askTimer), this.askTimer = null, this.set({ asked: t }), t && (this.askTimer = setTimeout(
274
+ () => this.set({ asked: null }),
275
+ t === "pending" ? 2e4 : 5e3
276
+ ));
277
+ }
278
+ onFollow(t) {
279
+ var i;
280
+ if (!t || t.room !== this.state.room) return;
281
+ const e = this.self();
282
+ switch (t.action) {
283
+ case "start":
284
+ case "move":
285
+ case "state": {
286
+ if (!t.presenter || !t.collection || t.id == null) return;
287
+ const o = t.presenter.socket === e, l = {
288
+ collection: t.collection,
289
+ id: String(t.id),
290
+ step: t.step ?? null,
291
+ section: t.section ?? null
292
+ }, a = ((i = this.state.presenter) == null ? void 0 : i.socket) !== t.presenter.socket, u = o ? !1 : t.action === "move" && !a ? this.state.following : !0;
293
+ o ? this.beginPresenting() : this.endPresenting(), this.set({
294
+ presenter: t.presenter,
295
+ target: l,
296
+ presenting: o,
297
+ following: u,
298
+ error: null,
299
+ asked: o ? null : this.state.asked
300
+ }), u || this.stopPolling(), a && (this.navigated = null), this.drive();
301
+ return;
302
+ }
303
+ case "stop": {
304
+ if (this.state.presenter && t.presenter && this.state.presenter.socket !== t.presenter.socket)
305
+ return;
306
+ this.endPresenting(), this.stopPolling(), this.navigated = null, this.set({
307
+ presenter: null,
308
+ target: null,
309
+ presenting: !1,
310
+ following: !1,
311
+ request: null
312
+ });
313
+ return;
314
+ }
315
+ case "request":
316
+ this.state.presenting && t.from && this.set({ request: t.from });
317
+ return;
318
+ case "granted":
319
+ this.setAsked(null), this.set({ presenter: null }), this.start(this.state.target);
320
+ return;
321
+ case "declined":
322
+ this.setAsked("declined");
323
+ return;
324
+ }
325
+ }
326
+ onDenied(t) {
327
+ if (!t || t.room !== this.state.room) return;
328
+ if (t.reason === "busy" && t.presenter) {
329
+ this.set({ presenter: t.presenter });
330
+ return;
331
+ }
332
+ const e = {
333
+ "not-record": "Follow me works in a record’s room.",
334
+ "no-record": "The record for this room could not be opened.",
335
+ "no-access": "You no longer have access to this room."
336
+ };
337
+ e[t.reason] && this.set({ error: e[t.reason] });
338
+ }
339
+ clearError() {
340
+ this.set({ error: null });
341
+ }
342
+ /** Test seam. */
343
+ dispose() {
344
+ this.endPresenting(), this.stopPolling();
345
+ for (const t of this.offBus) t();
346
+ }
347
+ }
348
+ const y = () => m.transportNow(), x = () => m.getSnapshot().self, h = new I(y, x), g = new $(y, x);
349
+ let f = null, P = [], p = null;
350
+ function H(n) {
351
+ return n.status === "live" && n.room ? n.room : null;
352
+ }
353
+ function k() {
354
+ const n = m.getSnapshot(), s = H(n), t = s ? `${s}|${n.self}` : null;
355
+ t !== p && (p = t, h.reset(s), g.reset(s), s && (f == null || f.emit("huddle:collab:sync", { room: s })));
356
+ }
357
+ function C(n) {
358
+ if (!(!n || f === n)) {
359
+ for (const s of P) s();
360
+ f = n, p = null, P = [
361
+ n.on("huddle:note", (s) => h.onNote(s)),
362
+ n.on(
363
+ "huddle:note:denied",
364
+ (s) => h.onDenied(s)
365
+ ),
366
+ n.on(
367
+ "huddle:note:unposted",
368
+ (s) => h.onUnposted(s)
369
+ ),
370
+ n.on("huddle:note:kept", (s) => h.onKept(s)),
371
+ n.on("huddle:follow", (s) => g.onFollow(s)),
372
+ n.on(
373
+ "huddle:follow:denied",
374
+ (s) => g.onDenied(s)
375
+ ),
376
+ m.subscribe(k),
377
+ m.onBeforeLeave(() => h.flush())
378
+ ], k();
379
+ }
380
+ }
381
+ export {
382
+ O as FOLLOW_THROTTLE_MS,
383
+ $ as HuddleFollowStore,
384
+ I as HuddleNoteStore,
385
+ v as NOTE_DEBOUNCE_MS,
386
+ M as NOTE_MAX_BYTES,
387
+ C as attachHuddleCollab,
388
+ g as huddleFollow,
389
+ h as huddleNotes,
390
+ A as noteBytes
391
+ };
@@ -0,0 +1,55 @@
1
+ const i = {
2
+ micId: null,
3
+ speakerId: null,
4
+ noiseSuppression: !0,
5
+ echoCancellation: !0,
6
+ autoGainControl: !0
7
+ }, c = "nvr-huddle-devices";
8
+ function a(e) {
9
+ if (!e) return { ...i };
10
+ try {
11
+ const n = JSON.parse(e), t = (o) => typeof o == "string" && o ? o : null, r = (o, s) => typeof o == "boolean" ? o : s;
12
+ return {
13
+ micId: t(n.micId),
14
+ speakerId: t(n.speakerId),
15
+ noiseSuppression: r(n.noiseSuppression, !0),
16
+ echoCancellation: r(n.echoCancellation, !0),
17
+ autoGainControl: r(n.autoGainControl, !0)
18
+ };
19
+ } catch {
20
+ return { ...i };
21
+ }
22
+ }
23
+ function l() {
24
+ var e;
25
+ try {
26
+ return a(((e = globalThis.localStorage) == null ? void 0 : e.getItem(c)) ?? null);
27
+ } catch {
28
+ return { ...i };
29
+ }
30
+ }
31
+ function u(e) {
32
+ var t;
33
+ const n = { ...l(), ...e };
34
+ try {
35
+ (t = globalThis.localStorage) == null || t.setItem(c, JSON.stringify(n));
36
+ } catch {
37
+ }
38
+ return n;
39
+ }
40
+ function d(e) {
41
+ return {
42
+ // `ideal`, not `exact`: a microphone unplugged since last time falls back to the default.
43
+ ...e.micId ? { deviceId: { ideal: e.micId } } : {},
44
+ echoCancellation: e.echoCancellation,
45
+ noiseSuppression: e.noiseSuppression,
46
+ autoGainControl: e.autoGainControl
47
+ };
48
+ }
49
+ export {
50
+ i as DEFAULT_DEVICE_PREFS,
51
+ l as loadDevicePrefs,
52
+ d as micConstraints,
53
+ a as parseDevicePrefs,
54
+ u as saveDevicePrefs
55
+ };
@@ -0,0 +1,99 @@
1
+ var k = Object.defineProperty;
2
+ var g = (i, e, t) => e in i ? k(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var o = (i, e, t) => g(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import { toast as f } from "sonner";
5
+ import { speakerChoiceSupported as u } from "./huddle-audio.js";
6
+ import { micChange as m, isPseudoDevice as w } from "./huddle-audio-logic.js";
7
+ import { loadDevicePrefs as h, saveDevicePrefs as I, micConstraints as b } from "./huddle-device-prefs.js";
8
+ import { huddleStore as a } from "./huddle-store.js";
9
+ async function v() {
10
+ const i = typeof navigator < "u" ? navigator.mediaDevices : void 0;
11
+ if (!(i != null && i.enumerateDevices)) return { mics: [], speakers: [] };
12
+ const e = await i.enumerateDevices().catch(() => []), t = (s) => ({
13
+ deviceId: s.deviceId,
14
+ kind: s.kind,
15
+ label: s.label,
16
+ groupId: s.groupId
17
+ });
18
+ return {
19
+ mics: e.filter((s) => s.kind === "audioinput").map(t),
20
+ speakers: e.filter((s) => s.kind === "audiooutput").map(t)
21
+ };
22
+ }
23
+ function D(i) {
24
+ return navigator.mediaDevices.getUserMedia({ audio: b(i) });
25
+ }
26
+ const S = [
27
+ "micId",
28
+ "noiseSuppression",
29
+ "echoCancellation",
30
+ "autoGainControl"
31
+ ];
32
+ function y() {
33
+ const i = a.getSnapshot();
34
+ return i.status === "live" || i.status === "joining";
35
+ }
36
+ async function d(i) {
37
+ const e = I(i);
38
+ if ("speakerId" in i && u() && a.setSpeaker(e.speakerId ?? ""), !y() || !S.some((t) => t in i)) return !0;
39
+ try {
40
+ return await a.swapMic(await D(e)), !0;
41
+ } catch {
42
+ return !1;
43
+ }
44
+ }
45
+ function C() {
46
+ var e, t;
47
+ const i = (e = a.localMic()) == null ? void 0 : e.getAudioTracks()[0];
48
+ return ((t = i == null ? void 0 : i.getSettings) == null ? void 0 : t.call(i).deviceId) ?? null;
49
+ }
50
+ class M {
51
+ constructor() {
52
+ o(this, "started", !1);
53
+ o(this, "bound", !1);
54
+ o(this, "known", []);
55
+ o(this, "onChange", async () => {
56
+ const e = this.known, t = await v(), s = [...t.mics, ...t.speakers];
57
+ if (this.known = s, a.getSnapshot().status !== "live") return;
58
+ const n = m(e, s, C());
59
+ if (n.kind === "switch") {
60
+ if (!await d({ micId: n.device.deviceId })) return;
61
+ const r = t.speakers.find(
62
+ (l) => !w(l) && n.device.groupId && l.groupId === n.device.groupId
63
+ );
64
+ r && u() && await d({ speakerId: r.deviceId }), f(`Switched to ${n.device.label || "the new headset"}`, { id: "huddle-device" });
65
+ } else if (n.kind === "fallback") {
66
+ const c = await d({ micId: null }), r = a.getSnapshot().micLabel;
67
+ c && f(`Microphone disconnected — switched to ${r || "the default microphone"}`, {
68
+ id: "huddle-device"
69
+ });
70
+ }
71
+ const p = h().speakerId;
72
+ p && !t.speakers.some((c) => c.deviceId === p) && await d({ speakerId: null });
73
+ });
74
+ }
75
+ start() {
76
+ this.started || typeof window > "u" || (this.started = !0, a.subscribe(() => this.sync()), this.sync());
77
+ }
78
+ sync() {
79
+ var s;
80
+ const e = navigator.mediaDevices, t = a.getSnapshot().status === "live";
81
+ if (t && !this.bound && (e != null && e.addEventListener)) {
82
+ this.bound = !0, e.addEventListener("devicechange", this.onChange), this.snapshot();
83
+ const n = h().speakerId;
84
+ n && u() && a.setSpeaker(n);
85
+ } else !t && this.bound && (this.bound = !1, (s = e == null ? void 0 : e.removeEventListener) == null || s.call(e, "devicechange", this.onChange), this.known = []);
86
+ }
87
+ async snapshot() {
88
+ const e = await v();
89
+ this.known = [...e.mics, ...e.speakers];
90
+ }
91
+ }
92
+ const x = new M();
93
+ export {
94
+ d as applyDevicePrefs,
95
+ C as currentMicId,
96
+ x as huddleDevices,
97
+ v as listAudioDevices,
98
+ D as openMic
99
+ };