@arbidocs/react 0.5.22 → 0.5.23

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.
@@ -2,12 +2,12 @@
2
2
 
3
3
  var chunkFLAZSNC5_cjs = require('./chunk-FLAZSNC5.cjs');
4
4
  var chunkRRWAX52L_cjs = require('./chunk-RRWAX52L.cjs');
5
- var chunkEEIYXVM4_cjs = require('./chunk-EEIYXVM4.cjs');
6
5
  var chunkVAMPYLQ4_cjs = require('./chunk-VAMPYLQ4.cjs');
6
+ var chunkEEIYXVM4_cjs = require('./chunk-EEIYXVM4.cjs');
7
7
  var chunkQQ7SCJRY_cjs = require('./chunk-QQ7SCJRY.cjs');
8
+ var browser = require('@arbidocs/sdk/browser');
8
9
  var react = require('react');
9
10
  var reactQuery = require('@tanstack/react-query');
10
- var browser = require('@arbidocs/sdk/browser');
11
11
  var client = require('@arbidocs/client');
12
12
 
13
13
  // src/conversation-list.ts
@@ -67,243 +67,6 @@ function invalidateConversationDetails(queryClient, conversationId) {
67
67
  predicate: ({ queryKey }) => queryKey[0] === "arbi" && queryKey[1] === "conversations" && queryKey[2] === conversationId && queryKey[3] !== "threads"
68
68
  });
69
69
  }
70
- var ArbiWsContext = react.createContext(null);
71
- function useArbiWsContext() {
72
- const ctx = react.useContext(ArbiWsContext);
73
- if (!ctx) {
74
- throw new Error("useArbiWebSocket hooks must be used within an <ArbiWebSocketProvider>");
75
- }
76
- return ctx;
77
- }
78
- function toProfileView(profile) {
79
- return {
80
- ...profile,
81
- fullName: [profile.givenName, profile.familyName].map((part) => part?.trim()).filter(Boolean).join(" ")
82
- };
83
- }
84
- function useProfile(options) {
85
- const { client, enabled } = useAccountClient();
86
- const qc = reactQuery.useQueryClient();
87
- react.useEffect(
88
- () => client.onProfileChange(() => qc.setQueryData(chunkRRWAX52L_cjs.arbiQueryKeys.profile(), client.profile())),
89
- [client, qc]
90
- );
91
- return reactQuery.useQuery({
92
- queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.profile(),
93
- queryFn: () => client.profile(),
94
- enabled: (options?.enabled ?? true) && enabled,
95
- staleTime: Infinity
96
- });
97
- }
98
- function useUpdateProfile() {
99
- const { client } = useAccountClient();
100
- const qc = reactQuery.useQueryClient();
101
- return reactQuery.useMutation({
102
- mutationFn: async (vars) => {
103
- await client.updateProfile(vars);
104
- return client.profile();
105
- },
106
- onSuccess: (profile) => {
107
- qc.setQueryData(chunkRRWAX52L_cjs.arbiQueryKeys.profile(), profile);
108
- void qc.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.identity() });
109
- return qc.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.workspaces() });
110
- }
111
- });
112
- }
113
- function useNameEditor({ givenName, familyName, save }) {
114
- const [isEditing, setIsEditing] = react.useState(false);
115
- const [given, setGiven] = react.useState("");
116
- const [family, setFamily] = react.useState("");
117
- const [isSaving, setIsSaving] = react.useState(false);
118
- const [error, setError] = react.useState(null);
119
- const onStartEdit = react.useCallback(() => {
120
- setGiven(givenName ?? "");
121
- setFamily(familyName ?? "");
122
- setError(null);
123
- setIsEditing(true);
124
- }, [givenName, familyName]);
125
- const onSave = react.useCallback(() => {
126
- const trimmedGiven = given.trim();
127
- if (!trimmedGiven) return;
128
- setIsSaving(true);
129
- setError(null);
130
- void Promise.resolve().then(() => save({ givenName: trimmedGiven, familyName: family.trim() })).then(() => setIsEditing(false)).catch((e) => setError(e)).finally(() => setIsSaving(false));
131
- }, [given, family, save]);
132
- return {
133
- isEditing,
134
- givenName: given,
135
- familyName: family,
136
- onGivenNameChange: setGiven,
137
- onFamilyNameChange: setFamily,
138
- onStartEdit,
139
- onSave,
140
- onCancel: () => setIsEditing(false),
141
- isSaving,
142
- error
143
- };
144
- }
145
- var MAX_AVATAR_FILE_BYTES = 5 * 1024 * 1024;
146
- function useAvatarCrop({
147
- upload,
148
- onProblem,
149
- maxBytes = MAX_AVATAR_FILE_BYTES
150
- }) {
151
- const [pendingImage, setPendingImage] = react.useState(null);
152
- const [isUploading, setIsUploading] = react.useState(false);
153
- const onFileChosen = react.useCallback(
154
- (file) => {
155
- if (!file.type.startsWith("image/")) return onProblem?.("not-image");
156
- if (file.size > maxBytes) return onProblem?.("too-large");
157
- const reader = new FileReader();
158
- reader.onload = () => setPendingImage(reader.result);
159
- reader.onerror = () => onProblem?.("unreadable");
160
- reader.readAsDataURL(file);
161
- },
162
- [maxBytes, onProblem]
163
- );
164
- const onCropComplete = react.useCallback(
165
- (result) => {
166
- setPendingImage(null);
167
- setIsUploading(true);
168
- void Promise.resolve().then(() => upload(result.dataUrl)).catch(() => {
169
- }).finally(() => setIsUploading(false));
170
- },
171
- [upload]
172
- );
173
- return {
174
- onFileChosen,
175
- pendingImage,
176
- onCropComplete,
177
- onCropCancel: () => setPendingImage(null),
178
- isUploading
179
- };
180
- }
181
-
182
- // src/account/client.tsx
183
- function arbiProfile(arbi) {
184
- const profile = arbi.user.profile();
185
- return profile ? toProfileView(profile) : null;
186
- }
187
- function arbiAccountClient(arbi, overrides = {}) {
188
- return {
189
- profile: () => arbiProfile(arbi),
190
- onProfileChange: (listener) => arbi.user.onProfileChange(() => listener()),
191
- updateProfile: async (vars) => {
192
- await arbi.profile.update({
193
- ...vars.givenName !== void 0 && { given_name: vars.givenName.trim() },
194
- ...vars.familyName !== void 0 && { family_name: vars.familyName.trim() },
195
- ...vars.picture !== void 0 && { picture: vars.picture }
196
- });
197
- },
198
- requestEmailChange: (newEmail) => arbi.account.requestEmailChange(newEmail),
199
- confirmEmailChange: async (newEmail, code) => {
200
- await arbi.account.confirmEmailChange(newEmail, code);
201
- },
202
- changePassword: (vars) => arbi.account.changePassword(vars),
203
- listSessions: () => arbi.sessions.list(),
204
- currentSessionId: () => arbi.sessions.currentId(),
205
- terminateSession: (sessionId) => arbi.sessions.terminate(sessionId),
206
- signOut: async ({ everywhere } = {}) => {
207
- try {
208
- if (everywhere) await arbi.sessions.logoutAll();
209
- else await arbi.logout();
210
- } finally {
211
- chunkFLAZSNC5_cjs.clearSealedDrafts();
212
- }
213
- },
214
- requestDeletion: () => arbi.account.requestDeletion(),
215
- identity: {
216
- status: () => arbi.identity.status(),
217
- purchase: () => arbi.identity.purchase(),
218
- startSession: () => arbi.identity.startSession(),
219
- refresh: () => arbi.identity.refresh(),
220
- acceptName: () => arbi.identity.acceptName(),
221
- remove: () => arbi.identity.remove()
222
- },
223
- ...overrides
224
- };
225
- }
226
- var NO_ACCOUNT_ERROR = "The account needs an <ArbiHost> with `account` or an `arbi`";
227
- var refuse = () => Promise.reject(new Error(NO_ACCOUNT_ERROR));
228
- var NO_ACCOUNT = {
229
- client: {
230
- profile: () => null,
231
- onProfileChange: () => () => {
232
- },
233
- updateProfile: refuse,
234
- requestEmailChange: refuse,
235
- confirmEmailChange: refuse,
236
- changePassword: refuse,
237
- listSessions: refuse,
238
- currentSessionId: () => null,
239
- terminateSession: refuse,
240
- signOut: refuse,
241
- requestDeletion: refuse,
242
- identity: {
243
- status: refuse,
244
- purchase: refuse,
245
- startSession: refuse,
246
- refresh: refuse,
247
- acceptName: refuse,
248
- remove: refuse
249
- }
250
- },
251
- enabled: false
252
- };
253
- var ALWAYS = () => true;
254
- function useAccountClient() {
255
- const { account, arbi } = chunkQQ7SCJRY_cjs.useArbiHost();
256
- const fallback = react.useMemo(() => arbi ? arbiAccountClient(arbi) : null, [arbi]);
257
- const useEnabled = account?.useEnabled ?? ALWAYS;
258
- const enabled = useEnabled();
259
- const client = account?.client;
260
- const provided = react.useMemo(() => client ? { client, enabled } : null, [client, enabled]);
261
- if (provided) return provided;
262
- if (!arbi || !fallback) return NO_ACCOUNT;
263
- return { client: fallback, enabled: arbi.isLoggedIn };
264
- }
265
- function useEntitlements() {
266
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
267
- return reactQuery.useQuery({
268
- queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.entitlements(),
269
- queryFn: () => arbi.account.entitlements(),
270
- enabled: arbi.isLoggedIn,
271
- // A plan change shows on the next read; the API enforces it at once either way.
272
- staleTime: 5 * 60 * 1e3
273
- });
274
- }
275
- function useIsEntitled(feature) {
276
- const { data } = useEntitlements();
277
- return data?.[feature] === true;
278
- }
279
- function entitlementRefusal(reason) {
280
- switch (reason) {
281
- case "external_user":
282
- return {
283
- title: "Not available for external users",
284
- description: "Mail, Calendar and hosting calls are for members of the firm. You can still join calls others host."
285
- };
286
- case "not_entitled":
287
- return {
288
- title: "Not available on this account",
289
- description: "Mail, Calendar and hosting calls are not available on this account."
290
- };
291
- default:
292
- return {
293
- title: "Available on Pro",
294
- description: "Mail, Calendar and hosting calls come with a Pro plan. You can still join calls others host."
295
- };
296
- }
297
- }
298
-
299
- // src/calls/keys.ts
300
- function invalidateCall(queryClient, message) {
301
- void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.call(message.call_ext_id) });
302
- const thread = message.log_conversation_ext_id;
303
- if (thread) {
304
- void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.conversationActivity(thread) });
305
- }
306
- }
307
70
  function myChatId(arbi) {
308
71
  try {
309
72
  return arbi.user.identity()?.externalId ?? null;
@@ -476,22 +239,541 @@ async function applyChatEvent(arbi, queryClient, event) {
476
239
  return applyChatUpdated(arbi, queryClient, e.chat_ext_id, e.message);
477
240
  if (e.type === "agent_dm_status") applyAgentDmStatus(queryClient, e);
478
241
  }
479
- function meetingChatRefFrom(row) {
480
- if (row.chat_ext_id) return { kind: "chat", chatExtId: row.chat_ext_id };
481
- const workspaceExtId = row.workspace_ext_id ?? row.locked_workspace_ext_id;
482
- if (row.meeting_conversation_ext_id && workspaceExtId) {
483
- return {
484
- kind: "thread",
485
- conversationExtId: row.meeting_conversation_ext_id,
486
- workspaceExtId
487
- };
242
+
243
+ // src/calls/keys.ts
244
+ function invalidateCall(queryClient, message) {
245
+ void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.call(message.call_ext_id) });
246
+ const thread = message.log_conversation_ext_id;
247
+ if (thread) {
248
+ void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.conversationActivity(thread) });
488
249
  }
489
- return null;
490
250
  }
491
- function callMemberKeys(call) {
492
- const keys = /* @__PURE__ */ new Map();
493
- if (call.creator_ext_id && call.creator_encryption_public_key) {
494
- keys.set(call.creator_ext_id, call.creator_encryption_public_key);
251
+
252
+ // src/calls/moderation.ts
253
+ var CALL_MODERATION_TOPIC = "arbi.moderation";
254
+ function trackOf(value) {
255
+ return value === "audio" || value === "video" ? value : null;
256
+ }
257
+ function mutedNoticeFromPacket(payload) {
258
+ try {
259
+ const parsed = JSON.parse(new TextDecoder().decode(payload));
260
+ if (!parsed || typeof parsed !== "object") return null;
261
+ const p = parsed;
262
+ const track = trackOf(p.track);
263
+ if (p.action !== "muted" || !track) return null;
264
+ return { track, byName: typeof p.by_name === "string" ? p.by_name : null };
265
+ } catch {
266
+ return null;
267
+ }
268
+ }
269
+ function mutedNoticeText(notice) {
270
+ return notice.track === "audio" ? "The host muted you" : "The host turned off your camera";
271
+ }
272
+ var MUTED_DEDUPE_MS = 5e3;
273
+ function createMutedNotifier(show, now = Date.now) {
274
+ const last = /* @__PURE__ */ new Map();
275
+ return (notice) => {
276
+ const at = now();
277
+ const prev = last.get(notice.track);
278
+ if (prev !== void 0 && at - prev < MUTED_DEDUPE_MS) return;
279
+ last.set(notice.track, at);
280
+ show(mutedNoticeText(notice));
281
+ };
282
+ }
283
+ function mutedNoticeFromEvent(raw) {
284
+ if (!raw || typeof raw !== "object") return null;
285
+ const r = raw;
286
+ const track = trackOf(r.track);
287
+ if (typeof r.call_ext_id !== "string" || !track) return null;
288
+ return {
289
+ callExtId: r.call_ext_id,
290
+ track,
291
+ byName: typeof r.by_name === "string" ? r.by_name : null
292
+ };
293
+ }
294
+ var DEFAULT_JOIN_CHOICES = { audioEnabled: true, videoEnabled: false };
295
+ var EMPTY_CALL_SESSION = {
296
+ active: null,
297
+ incoming: [],
298
+ knocks: [],
299
+ liveCalls: {}
300
+ };
301
+ var state = EMPTY_CALL_SESSION;
302
+ var listeners = /* @__PURE__ */ new Set();
303
+ function update(next) {
304
+ const changed = next(state);
305
+ if (changed === state) return;
306
+ state = changed;
307
+ for (const listener of listeners) listener();
308
+ }
309
+ var callSession = {
310
+ getState: () => state,
311
+ subscribe(listener) {
312
+ listeners.add(listener);
313
+ return () => {
314
+ listeners.delete(listener);
315
+ };
316
+ },
317
+ setActiveCall(next) {
318
+ update((s) => ({
319
+ ...s,
320
+ active: { ...next, minimized: next.minimized ?? false, startedAt: Date.now() },
321
+ // Joining a call answers any ring for it; knocks belong to the previous call.
322
+ incoming: s.incoming.filter((ring) => ring.call_ext_id !== next.callExtId),
323
+ knocks: s.knocks.filter((k) => k.callExtId === next.callExtId)
324
+ }));
325
+ },
326
+ /** Patch the active call (no-op when it is a different call or none). */
327
+ updateActiveCall(callExtId, patch) {
328
+ update(
329
+ (s) => s.active?.callExtId === callExtId ? { ...s, active: { ...s.active, ...patch } } : s
330
+ );
331
+ },
332
+ endActiveCall() {
333
+ update((s) => {
334
+ s.active?.knock?.abort();
335
+ return { ...s, active: null, knocks: [] };
336
+ });
337
+ },
338
+ setCallMinimized(minimized) {
339
+ update((s) => s.active ? { ...s, active: { ...s.active, minimized } } : s);
340
+ },
341
+ /** Queue a ring. A repeat ring for the same call replaces the earlier entry. */
342
+ enqueueIncomingCall(ring) {
343
+ update((s) => {
344
+ if (s.active?.callExtId === ring.call_ext_id) return s;
345
+ return {
346
+ ...s,
347
+ incoming: [
348
+ ...s.incoming.filter((r) => r.call_ext_id !== ring.call_ext_id),
349
+ { ...ring, receivedAt: Date.now() }
350
+ ]
351
+ };
352
+ });
353
+ },
354
+ removeIncomingCall(callExtId) {
355
+ update((s) => ({ ...s, incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId) }));
356
+ },
357
+ addKnock(knock) {
358
+ update((s) => {
359
+ if (s.active?.callExtId !== knock.callExtId) return s;
360
+ return {
361
+ ...s,
362
+ knocks: [
363
+ ...s.knocks.filter((k) => k.knockId !== knock.knockId),
364
+ { ...knock, receivedAt: Date.now() }
365
+ ]
366
+ };
367
+ });
368
+ },
369
+ removeKnock(knockId) {
370
+ update((s) => ({ ...s, knocks: s.knocks.filter((k) => k.knockId !== knockId) }));
371
+ },
372
+ markCallLive(callExtId, where) {
373
+ update((s) => ({ ...s, liveCalls: { ...s.liveCalls, [callExtId]: where } }));
374
+ },
375
+ /** Call ended: forget it and drop any unanswered ring / knock for it. */
376
+ markCallEnded(callExtId) {
377
+ update((s) => {
378
+ const liveCalls = { ...s.liveCalls };
379
+ delete liveCalls[callExtId];
380
+ return {
381
+ ...s,
382
+ liveCalls,
383
+ incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId),
384
+ knocks: s.knocks.filter((k) => k.callExtId !== callExtId)
385
+ };
386
+ });
387
+ }
388
+ };
389
+ function resetCallSession() {
390
+ update(() => EMPTY_CALL_SESSION);
391
+ }
392
+ function useCallSession(selector) {
393
+ return react.useSyncExternalStore(
394
+ callSession.subscribe,
395
+ () => selector(state),
396
+ () => selector(state)
397
+ );
398
+ }
399
+ function threadLiveCallId(s, conversationExtId) {
400
+ const found = Object.entries(s.liveCalls).find(
401
+ ([, c]) => c.logConversationExtId === conversationExtId
402
+ );
403
+ return found ? found[0] : null;
404
+ }
405
+ function threadHasLiveCall(s, conversationExtId) {
406
+ return threadLiveCallId(s, conversationExtId) !== null;
407
+ }
408
+ function chatLiveCallId(s, chatExtId) {
409
+ const found = Object.entries(s.liveCalls).find(([, c]) => c.chatExtId === chatExtId);
410
+ return found ? found[0] : null;
411
+ }
412
+ function chatHasLiveCall(s, chatExtId) {
413
+ return chatLiveCallId(s, chatExtId) !== null;
414
+ }
415
+ var listeners2 = /* @__PURE__ */ new Map();
416
+ function onCallEvent(type, listener) {
417
+ let set = listeners2.get(type);
418
+ if (!set) listeners2.set(type, set = /* @__PURE__ */ new Set());
419
+ set.add(listener);
420
+ return () => {
421
+ set.delete(listener);
422
+ };
423
+ }
424
+ function relay(type, message) {
425
+ if (!message) return;
426
+ for (const listener of listeners2.get(type) ?? []) {
427
+ listener(message);
428
+ }
429
+ }
430
+ var str = (value) => typeof value === "string" && value ? value : null;
431
+ function applyCallEvent(queryClient, event, options = {}) {
432
+ const m = event;
433
+ const callExtId = str(m.call_ext_id);
434
+ switch (m.type) {
435
+ case "call.ringing": {
436
+ const ring = m;
437
+ if (options.acceptRings === false || !callExtId || !ring.sealed_key) return true;
438
+ if (options.me && ring.caller_ext_id === options.me) return true;
439
+ callSession.enqueueIncomingCall({
440
+ call_ext_id: ring.call_ext_id,
441
+ room_name: ring.room_name,
442
+ caller_ext_id: ring.caller_ext_id,
443
+ caller_name: ring.caller_name,
444
+ chat_ext_id: ring.chat_ext_id ?? null,
445
+ log_conversation_ext_id: ring.log_conversation_ext_id ?? null,
446
+ meeting_conversation_ext_id: ring.meeting_conversation_ext_id ?? null,
447
+ workspace_ext_id: ring.workspace_ext_id ?? null,
448
+ context: ring.context ?? null,
449
+ sealed_key: ring.sealed_key,
450
+ link_version: ring.link_version,
451
+ title: ring.title ?? null
452
+ });
453
+ return true;
454
+ }
455
+ case "call.declined":
456
+ if (callExtId && callSession.getState().active?.callExtId === callExtId) {
457
+ chunkVAMPYLQ4_cjs.notify.info("Call declined", { record: false, ambient: false });
458
+ }
459
+ return true;
460
+ case "call.started":
461
+ if (!callExtId) return true;
462
+ callSession.markCallLive(callExtId, {
463
+ chatExtId: str(m.chat_ext_id),
464
+ logConversationExtId: str(m.log_conversation_ext_id),
465
+ meetingConversationExtId: str(m.meeting_conversation_ext_id)
466
+ });
467
+ invalidateCall(queryClient, {
468
+ call_ext_id: callExtId,
469
+ log_conversation_ext_id: str(m.log_conversation_ext_id)
470
+ });
471
+ return true;
472
+ case "call.ended":
473
+ if (!callExtId) return true;
474
+ callSession.markCallEnded(callExtId);
475
+ invalidateCall(queryClient, {
476
+ call_ext_id: callExtId,
477
+ log_conversation_ext_id: str(m.log_conversation_ext_id)
478
+ });
479
+ return true;
480
+ case "call.knock": {
481
+ const knock = m;
482
+ if (!callExtId) return true;
483
+ callSession.addKnock({
484
+ callExtId,
485
+ knockId: knock.knock_id,
486
+ displayName: knock.display_name,
487
+ userExtId: knock.user_ext_id
488
+ });
489
+ return true;
490
+ }
491
+ case "call.knock_resolved": {
492
+ const knockId = str(m.knock_id);
493
+ if (knockId) callSession.removeKnock(knockId);
494
+ return true;
495
+ }
496
+ case "call.recording": {
497
+ if (callExtId)
498
+ void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(callExtId) });
499
+ const state2 = browser.calls.recordingStateFrom(m);
500
+ relay("call.recording", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
501
+ return true;
502
+ }
503
+ case "call.recording_updated": {
504
+ if (callExtId)
505
+ void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(callExtId) });
506
+ return true;
507
+ }
508
+ case "call.recording_deleted": {
509
+ if (callExtId)
510
+ void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(callExtId) });
511
+ const recordingExtId = str(m.recording_ext_id);
512
+ relay(
513
+ "call.recording_deleted",
514
+ callExtId && recordingExtId ? { call_ext_id: callExtId, recording_ext_id: recordingExtId } : null
515
+ );
516
+ return true;
517
+ }
518
+ case "call.transcription": {
519
+ const state2 = browser.calls.transcriptionStateFrom(m);
520
+ relay("call.transcription", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
521
+ return true;
522
+ }
523
+ case "call.webinar":
524
+ relay(
525
+ "call.webinar",
526
+ callExtId && typeof m.live === "boolean" ? {
527
+ type: "call.webinar",
528
+ call_ext_id: callExtId,
529
+ live: m.live,
530
+ chat: m.chat === "everyone" ? "everyone" : "panelists"
531
+ } : null
532
+ );
533
+ return true;
534
+ case "call.muted":
535
+ relay("call.muted", mutedNoticeFromEvent(m));
536
+ return true;
537
+ default:
538
+ return false;
539
+ }
540
+ }
541
+ function toProfileView(profile) {
542
+ return {
543
+ ...profile,
544
+ fullName: [profile.givenName, profile.familyName].map((part) => part?.trim()).filter(Boolean).join(" ")
545
+ };
546
+ }
547
+ function useProfile(options) {
548
+ const { client, enabled } = useAccountClient();
549
+ const qc = reactQuery.useQueryClient();
550
+ react.useEffect(
551
+ () => client.onProfileChange(() => qc.setQueryData(chunkRRWAX52L_cjs.arbiQueryKeys.profile(), client.profile())),
552
+ [client, qc]
553
+ );
554
+ return reactQuery.useQuery({
555
+ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.profile(),
556
+ queryFn: () => client.profile(),
557
+ enabled: (options?.enabled ?? true) && enabled,
558
+ staleTime: Infinity
559
+ });
560
+ }
561
+ function useUpdateProfile() {
562
+ const { client } = useAccountClient();
563
+ const qc = reactQuery.useQueryClient();
564
+ return reactQuery.useMutation({
565
+ mutationFn: async (vars) => {
566
+ await client.updateProfile(vars);
567
+ return client.profile();
568
+ },
569
+ onSuccess: (profile) => {
570
+ qc.setQueryData(chunkRRWAX52L_cjs.arbiQueryKeys.profile(), profile);
571
+ void qc.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.identity() });
572
+ return qc.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.workspaces() });
573
+ }
574
+ });
575
+ }
576
+ function useNameEditor({ givenName, familyName, save }) {
577
+ const [isEditing, setIsEditing] = react.useState(false);
578
+ const [given, setGiven] = react.useState("");
579
+ const [family, setFamily] = react.useState("");
580
+ const [isSaving, setIsSaving] = react.useState(false);
581
+ const [error, setError] = react.useState(null);
582
+ const onStartEdit = react.useCallback(() => {
583
+ setGiven(givenName ?? "");
584
+ setFamily(familyName ?? "");
585
+ setError(null);
586
+ setIsEditing(true);
587
+ }, [givenName, familyName]);
588
+ const onSave = react.useCallback(() => {
589
+ const trimmedGiven = given.trim();
590
+ if (!trimmedGiven) return;
591
+ setIsSaving(true);
592
+ setError(null);
593
+ void Promise.resolve().then(() => save({ givenName: trimmedGiven, familyName: family.trim() })).then(() => setIsEditing(false)).catch((e) => setError(e)).finally(() => setIsSaving(false));
594
+ }, [given, family, save]);
595
+ return {
596
+ isEditing,
597
+ givenName: given,
598
+ familyName: family,
599
+ onGivenNameChange: setGiven,
600
+ onFamilyNameChange: setFamily,
601
+ onStartEdit,
602
+ onSave,
603
+ onCancel: () => setIsEditing(false),
604
+ isSaving,
605
+ error
606
+ };
607
+ }
608
+ var MAX_AVATAR_FILE_BYTES = 5 * 1024 * 1024;
609
+ function useAvatarCrop({
610
+ upload,
611
+ onProblem,
612
+ maxBytes = MAX_AVATAR_FILE_BYTES
613
+ }) {
614
+ const [pendingImage, setPendingImage] = react.useState(null);
615
+ const [isUploading, setIsUploading] = react.useState(false);
616
+ const onFileChosen = react.useCallback(
617
+ (file) => {
618
+ if (!file.type.startsWith("image/")) return onProblem?.("not-image");
619
+ if (file.size > maxBytes) return onProblem?.("too-large");
620
+ const reader = new FileReader();
621
+ reader.onload = () => setPendingImage(reader.result);
622
+ reader.onerror = () => onProblem?.("unreadable");
623
+ reader.readAsDataURL(file);
624
+ },
625
+ [maxBytes, onProblem]
626
+ );
627
+ const onCropComplete = react.useCallback(
628
+ (result) => {
629
+ setPendingImage(null);
630
+ setIsUploading(true);
631
+ void Promise.resolve().then(() => upload(result.dataUrl)).catch(() => {
632
+ }).finally(() => setIsUploading(false));
633
+ },
634
+ [upload]
635
+ );
636
+ return {
637
+ onFileChosen,
638
+ pendingImage,
639
+ onCropComplete,
640
+ onCropCancel: () => setPendingImage(null),
641
+ isUploading
642
+ };
643
+ }
644
+
645
+ // src/account/client.tsx
646
+ function arbiProfile(arbi) {
647
+ const profile = arbi.user.profile();
648
+ return profile ? toProfileView(profile) : null;
649
+ }
650
+ function arbiAccountClient(arbi, overrides = {}) {
651
+ return {
652
+ profile: () => arbiProfile(arbi),
653
+ onProfileChange: (listener) => arbi.user.onProfileChange(() => listener()),
654
+ updateProfile: async (vars) => {
655
+ await arbi.profile.update({
656
+ ...vars.givenName !== void 0 && { given_name: vars.givenName.trim() },
657
+ ...vars.familyName !== void 0 && { family_name: vars.familyName.trim() },
658
+ ...vars.picture !== void 0 && { picture: vars.picture }
659
+ });
660
+ },
661
+ requestEmailChange: (newEmail) => arbi.account.requestEmailChange(newEmail),
662
+ confirmEmailChange: async (newEmail, code) => {
663
+ await arbi.account.confirmEmailChange(newEmail, code);
664
+ },
665
+ changePassword: (vars) => arbi.account.changePassword(vars),
666
+ listSessions: () => arbi.sessions.list(),
667
+ currentSessionId: () => arbi.sessions.currentId(),
668
+ terminateSession: (sessionId) => arbi.sessions.terminate(sessionId),
669
+ signOut: async ({ everywhere } = {}) => {
670
+ try {
671
+ if (everywhere) await arbi.sessions.logoutAll();
672
+ else await arbi.logout();
673
+ } finally {
674
+ chunkFLAZSNC5_cjs.clearSealedDrafts();
675
+ }
676
+ },
677
+ requestDeletion: () => arbi.account.requestDeletion(),
678
+ identity: {
679
+ status: () => arbi.identity.status(),
680
+ purchase: () => arbi.identity.purchase(),
681
+ startSession: () => arbi.identity.startSession(),
682
+ refresh: () => arbi.identity.refresh(),
683
+ acceptName: () => arbi.identity.acceptName(),
684
+ remove: () => arbi.identity.remove()
685
+ },
686
+ ...overrides
687
+ };
688
+ }
689
+ var NO_ACCOUNT_ERROR = "The account needs an <ArbiHost> with `account` or an `arbi`";
690
+ var refuse = () => Promise.reject(new Error(NO_ACCOUNT_ERROR));
691
+ var NO_ACCOUNT = {
692
+ client: {
693
+ profile: () => null,
694
+ onProfileChange: () => () => {
695
+ },
696
+ updateProfile: refuse,
697
+ requestEmailChange: refuse,
698
+ confirmEmailChange: refuse,
699
+ changePassword: refuse,
700
+ listSessions: refuse,
701
+ currentSessionId: () => null,
702
+ terminateSession: refuse,
703
+ signOut: refuse,
704
+ requestDeletion: refuse,
705
+ identity: {
706
+ status: refuse,
707
+ purchase: refuse,
708
+ startSession: refuse,
709
+ refresh: refuse,
710
+ acceptName: refuse,
711
+ remove: refuse
712
+ }
713
+ },
714
+ enabled: false
715
+ };
716
+ var ALWAYS = () => true;
717
+ function useAccountClient() {
718
+ const { account, arbi } = chunkQQ7SCJRY_cjs.useArbiHost();
719
+ const fallback = react.useMemo(() => arbi ? arbiAccountClient(arbi) : null, [arbi]);
720
+ const useEnabled = account?.useEnabled ?? ALWAYS;
721
+ const enabled = useEnabled();
722
+ const client = account?.client;
723
+ const provided = react.useMemo(() => client ? { client, enabled } : null, [client, enabled]);
724
+ if (provided) return provided;
725
+ if (!arbi || !fallback) return NO_ACCOUNT;
726
+ return { client: fallback, enabled: arbi.isLoggedIn };
727
+ }
728
+ function useEntitlements() {
729
+ const arbi = chunkQQ7SCJRY_cjs.useArbi();
730
+ return reactQuery.useQuery({
731
+ queryKey: chunkRRWAX52L_cjs.arbiQueryKeys.entitlements(),
732
+ queryFn: () => arbi.account.entitlements(),
733
+ enabled: arbi.isLoggedIn,
734
+ // A plan change shows on the next read; the API enforces it at once either way.
735
+ staleTime: 5 * 60 * 1e3
736
+ });
737
+ }
738
+ function useIsEntitled(feature) {
739
+ const { data } = useEntitlements();
740
+ return data?.[feature] === true;
741
+ }
742
+ function entitlementRefusal(reason) {
743
+ switch (reason) {
744
+ case "external_user":
745
+ return {
746
+ title: "Not available for external users",
747
+ description: "Mail, Calendar and hosting calls are for members of the firm. You can still join calls others host."
748
+ };
749
+ case "not_entitled":
750
+ return {
751
+ title: "Not available on this account",
752
+ description: "Mail, Calendar and hosting calls are not available on this account."
753
+ };
754
+ default:
755
+ return {
756
+ title: "Available on Pro",
757
+ description: "Mail, Calendar and hosting calls come with a Pro plan. You can still join calls others host."
758
+ };
759
+ }
760
+ }
761
+ function meetingChatRefFrom(row) {
762
+ if (row.chat_ext_id) return { kind: "chat", chatExtId: row.chat_ext_id };
763
+ const workspaceExtId = row.workspace_ext_id ?? row.locked_workspace_ext_id;
764
+ if (row.meeting_conversation_ext_id && workspaceExtId) {
765
+ return {
766
+ kind: "thread",
767
+ conversationExtId: row.meeting_conversation_ext_id,
768
+ workspaceExtId
769
+ };
770
+ }
771
+ return null;
772
+ }
773
+ function callMemberKeys(call) {
774
+ const keys = /* @__PURE__ */ new Map();
775
+ if (call.creator_ext_id && call.creator_encryption_public_key) {
776
+ keys.set(call.creator_ext_id, call.creator_encryption_public_key);
495
777
  }
496
778
  for (const i of call.invitees ?? []) {
497
779
  if (i.encryption_public_key) keys.set(i.user_ext_id, i.encryption_public_key);
@@ -1564,417 +1846,111 @@ async function transcribeRecording(params) {
1564
1846
  pcm = await decode(bytes);
1565
1847
  } catch (err) {
1566
1848
  console.warn("[calls] a recording part does not decode; sending it whole", err);
1567
- }
1568
- if (pcm) {
1569
- await sendPieces(cutter.push(part.offset_ms, pcm));
1570
- } else {
1571
- await send({
1572
- audio: new Blob([standalone(bytes)], { type: track.mime_type }),
1573
- seq: part.seq,
1574
- offsetMs: part.offset_ms
1575
- });
1576
- }
1577
- onProgress?.(++done, total);
1578
- }
1579
- await sendPieces(cutter.finish());
1580
- }
1581
- return { stored, failed };
1582
- }
1583
- function useCallsConfig() {
1584
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
1585
- const { data } = reactQuery.useQuery({
1586
- queryKey: chunkRRWAX52L_cjs.callQueryKeys.config(),
1587
- queryFn: () => arbi.calls.config(),
1588
- enabled: arbi.isLoggedIn,
1589
- staleTime: 5 * 6e4,
1590
- retry: false
1591
- });
1592
- return data;
1593
- }
1594
- function useServerCallsEnabled() {
1595
- return useCallsConfig()?.enabled === true;
1596
- }
1597
- function useCallTranscriptionAvailable() {
1598
- return useCallsConfig()?.transcription_available === true;
1599
- }
1600
- function useCall(callExtId) {
1601
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
1602
- return reactQuery.useQuery({
1603
- queryKey: chunkRRWAX52L_cjs.callQueryKeys.call(callExtId ?? ""),
1604
- queryFn: () => arbi.calls.get(callExtId),
1605
- enabled: !!callExtId && arbi.isLoggedIn,
1606
- staleTime: 6e4,
1607
- retry: false
1608
- });
1609
- }
1610
- function useCallRecordings(callExtId, enabled = true) {
1611
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
1612
- return reactQuery.useQuery({
1613
- queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordings(callExtId ?? ""),
1614
- queryFn: () => arbi.calls.recording.list(callExtId),
1615
- enabled: !!callExtId && enabled && arbi.isLoggedIn,
1616
- retry: false
1617
- });
1618
- }
1619
- function useCallRecording(callExtId, recordingExtId) {
1620
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
1621
- return reactQuery.useQuery({
1622
- queryKey: chunkRRWAX52L_cjs.callQueryKeys.recording(callExtId ?? "", recordingExtId ?? ""),
1623
- queryFn: () => arbi.calls.recording.get(callExtId, recordingExtId),
1624
- enabled: !!callExtId && !!recordingExtId && arbi.isLoggedIn,
1625
- retry: false
1626
- });
1627
- }
1628
- var NO_WINDOWS = [];
1629
- function useRecordingWindows(callExtId, enabled) {
1630
- const { data } = useCallRecordings(callExtId, enabled);
1631
- return react.useMemo(() => data ? recordingWindowsOf(data) : NO_WINDOWS, [data]);
1632
- }
1633
- function useCallInviteLinks(callExtId) {
1634
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
1635
- return reactQuery.useQuery({
1636
- queryKey: chunkRRWAX52L_cjs.callQueryKeys.inviteLinks(callExtId ?? ""),
1637
- queryFn: () => arbi.calls.inviteLinks.list(callExtId),
1638
- enabled: !!callExtId && arbi.isLoggedIn,
1639
- retry: false
1640
- });
1641
- }
1642
- function useRecordingActions(call) {
1643
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
1644
- const queryClient = reactQuery.useQueryClient();
1645
- return react.useMemo(
1646
- () => ({
1647
- refresh: () => void queryClient.invalidateQueries({
1648
- queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(call.external_id)
1649
- }),
1650
- open: (recording) => openRecording(arbi, queryClient, call, recording.external_id, recording),
1651
- transcribe: async (opened, onProgress) => transcribeRecording({
1652
- arbi,
1653
- queryClient,
1654
- callExtId: call.external_id,
1655
- opened,
1656
- ref: await meetingRefForCall(arbi, queryClient, call),
1657
- onProgress
1658
- })
1659
- }),
1660
- [arbi, queryClient, call]
1661
- );
1662
- }
1663
- function useRevokeCallInviteLink(callExtId) {
1664
- const arbi = chunkQQ7SCJRY_cjs.useArbi();
1665
- const queryClient = reactQuery.useQueryClient();
1666
- return react.useCallback(
1667
- async (inviteExtId) => {
1668
- await arbi.calls.inviteLinks.revoke(callExtId, inviteExtId);
1669
- void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.inviteLinks(callExtId) });
1670
- },
1671
- [arbi, queryClient, callExtId]
1672
- );
1673
- }
1674
- var DEFAULT_JOIN_CHOICES = { audioEnabled: true, videoEnabled: false };
1675
- var EMPTY_CALL_SESSION = {
1676
- active: null,
1677
- incoming: [],
1678
- knocks: [],
1679
- liveCalls: {}
1680
- };
1681
- var state = EMPTY_CALL_SESSION;
1682
- var listeners = /* @__PURE__ */ new Set();
1683
- function update(next) {
1684
- const changed = next(state);
1685
- if (changed === state) return;
1686
- state = changed;
1687
- for (const listener of listeners) listener();
1688
- }
1689
- var callSession = {
1690
- getState: () => state,
1691
- subscribe(listener) {
1692
- listeners.add(listener);
1693
- return () => {
1694
- listeners.delete(listener);
1695
- };
1696
- },
1697
- setActiveCall(next) {
1698
- update((s) => ({
1699
- ...s,
1700
- active: { ...next, minimized: next.minimized ?? false, startedAt: Date.now() },
1701
- // Joining a call answers any ring for it; knocks belong to the previous call.
1702
- incoming: s.incoming.filter((ring) => ring.call_ext_id !== next.callExtId),
1703
- knocks: s.knocks.filter((k) => k.callExtId === next.callExtId)
1704
- }));
1705
- },
1706
- /** Patch the active call (no-op when it is a different call or none). */
1707
- updateActiveCall(callExtId, patch) {
1708
- update(
1709
- (s) => s.active?.callExtId === callExtId ? { ...s, active: { ...s.active, ...patch } } : s
1710
- );
1711
- },
1712
- endActiveCall() {
1713
- update((s) => {
1714
- s.active?.knock?.abort();
1715
- return { ...s, active: null, knocks: [] };
1716
- });
1717
- },
1718
- setCallMinimized(minimized) {
1719
- update((s) => s.active ? { ...s, active: { ...s.active, minimized } } : s);
1720
- },
1721
- /** Queue a ring. A repeat ring for the same call replaces the earlier entry. */
1722
- enqueueIncomingCall(ring) {
1723
- update((s) => {
1724
- if (s.active?.callExtId === ring.call_ext_id) return s;
1725
- return {
1726
- ...s,
1727
- incoming: [
1728
- ...s.incoming.filter((r) => r.call_ext_id !== ring.call_ext_id),
1729
- { ...ring, receivedAt: Date.now() }
1730
- ]
1731
- };
1732
- });
1733
- },
1734
- removeIncomingCall(callExtId) {
1735
- update((s) => ({ ...s, incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId) }));
1736
- },
1737
- addKnock(knock) {
1738
- update((s) => {
1739
- if (s.active?.callExtId !== knock.callExtId) return s;
1740
- return {
1741
- ...s,
1742
- knocks: [
1743
- ...s.knocks.filter((k) => k.knockId !== knock.knockId),
1744
- { ...knock, receivedAt: Date.now() }
1745
- ]
1746
- };
1747
- });
1748
- },
1749
- removeKnock(knockId) {
1750
- update((s) => ({ ...s, knocks: s.knocks.filter((k) => k.knockId !== knockId) }));
1751
- },
1752
- markCallLive(callExtId, where) {
1753
- update((s) => ({ ...s, liveCalls: { ...s.liveCalls, [callExtId]: where } }));
1754
- },
1755
- /** Call ended: forget it and drop any unanswered ring / knock for it. */
1756
- markCallEnded(callExtId) {
1757
- update((s) => {
1758
- const liveCalls = { ...s.liveCalls };
1759
- delete liveCalls[callExtId];
1760
- return {
1761
- ...s,
1762
- liveCalls,
1763
- incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId),
1764
- knocks: s.knocks.filter((k) => k.callExtId !== callExtId)
1765
- };
1766
- });
1767
- }
1768
- };
1769
- function resetCallSession() {
1770
- update(() => EMPTY_CALL_SESSION);
1771
- }
1772
- function useCallSession(selector) {
1773
- return react.useSyncExternalStore(
1774
- callSession.subscribe,
1775
- () => selector(state),
1776
- () => selector(state)
1777
- );
1778
- }
1779
- function threadLiveCallId(s, conversationExtId) {
1780
- const found = Object.entries(s.liveCalls).find(
1781
- ([, c]) => c.logConversationExtId === conversationExtId
1782
- );
1783
- return found ? found[0] : null;
1784
- }
1785
- function threadHasLiveCall(s, conversationExtId) {
1786
- return threadLiveCallId(s, conversationExtId) !== null;
1787
- }
1788
- function chatLiveCallId(s, chatExtId) {
1789
- const found = Object.entries(s.liveCalls).find(([, c]) => c.chatExtId === chatExtId);
1790
- return found ? found[0] : null;
1791
- }
1792
- function chatHasLiveCall(s, chatExtId) {
1793
- return chatLiveCallId(s, chatExtId) !== null;
1849
+ }
1850
+ if (pcm) {
1851
+ await sendPieces(cutter.push(part.offset_ms, pcm));
1852
+ } else {
1853
+ await send({
1854
+ audio: new Blob([standalone(bytes)], { type: track.mime_type }),
1855
+ seq: part.seq,
1856
+ offsetMs: part.offset_ms
1857
+ });
1858
+ }
1859
+ onProgress?.(++done, total);
1860
+ }
1861
+ await sendPieces(cutter.finish());
1862
+ }
1863
+ return { stored, failed };
1794
1864
  }
1795
-
1796
- // src/calls/moderation.ts
1797
- var CALL_MODERATION_TOPIC = "arbi.moderation";
1798
- function trackOf(value) {
1799
- return value === "audio" || value === "video" ? value : null;
1865
+ function useCallsConfig() {
1866
+ const arbi = chunkQQ7SCJRY_cjs.useArbi();
1867
+ const { data } = reactQuery.useQuery({
1868
+ queryKey: chunkRRWAX52L_cjs.callQueryKeys.config(),
1869
+ queryFn: () => arbi.calls.config(),
1870
+ enabled: arbi.isLoggedIn,
1871
+ staleTime: 5 * 6e4,
1872
+ retry: false
1873
+ });
1874
+ return data;
1800
1875
  }
1801
- function mutedNoticeFromPacket(payload) {
1802
- try {
1803
- const parsed = JSON.parse(new TextDecoder().decode(payload));
1804
- if (!parsed || typeof parsed !== "object") return null;
1805
- const p = parsed;
1806
- const track = trackOf(p.track);
1807
- if (p.action !== "muted" || !track) return null;
1808
- return { track, byName: typeof p.by_name === "string" ? p.by_name : null };
1809
- } catch {
1810
- return null;
1811
- }
1876
+ function useServerCallsEnabled() {
1877
+ return useCallsConfig()?.enabled === true;
1812
1878
  }
1813
- function mutedNoticeText(notice) {
1814
- return notice.track === "audio" ? "The host muted you" : "The host turned off your camera";
1879
+ function useCallTranscriptionAvailable() {
1880
+ return useCallsConfig()?.transcription_available === true;
1815
1881
  }
1816
- var MUTED_DEDUPE_MS = 5e3;
1817
- function createMutedNotifier(show, now = Date.now) {
1818
- const last = /* @__PURE__ */ new Map();
1819
- return (notice) => {
1820
- const at = now();
1821
- const prev = last.get(notice.track);
1822
- if (prev !== void 0 && at - prev < MUTED_DEDUPE_MS) return;
1823
- last.set(notice.track, at);
1824
- show(mutedNoticeText(notice));
1825
- };
1882
+ function useCall(callExtId) {
1883
+ const arbi = chunkQQ7SCJRY_cjs.useArbi();
1884
+ return reactQuery.useQuery({
1885
+ queryKey: chunkRRWAX52L_cjs.callQueryKeys.call(callExtId ?? ""),
1886
+ queryFn: () => arbi.calls.get(callExtId),
1887
+ enabled: !!callExtId && arbi.isLoggedIn,
1888
+ staleTime: 6e4,
1889
+ retry: false
1890
+ });
1826
1891
  }
1827
- function mutedNoticeFromEvent(raw) {
1828
- if (!raw || typeof raw !== "object") return null;
1829
- const r = raw;
1830
- const track = trackOf(r.track);
1831
- if (typeof r.call_ext_id !== "string" || !track) return null;
1832
- return {
1833
- callExtId: r.call_ext_id,
1834
- track,
1835
- byName: typeof r.by_name === "string" ? r.by_name : null
1836
- };
1892
+ function useCallRecordings(callExtId, enabled = true) {
1893
+ const arbi = chunkQQ7SCJRY_cjs.useArbi();
1894
+ return reactQuery.useQuery({
1895
+ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordings(callExtId ?? ""),
1896
+ queryFn: () => arbi.calls.recording.list(callExtId),
1897
+ enabled: !!callExtId && enabled && arbi.isLoggedIn,
1898
+ retry: false
1899
+ });
1837
1900
  }
1838
- var listeners2 = /* @__PURE__ */ new Map();
1839
- function onCallEvent(type, listener) {
1840
- let set = listeners2.get(type);
1841
- if (!set) listeners2.set(type, set = /* @__PURE__ */ new Set());
1842
- set.add(listener);
1843
- return () => {
1844
- set.delete(listener);
1845
- };
1901
+ function useCallRecording(callExtId, recordingExtId) {
1902
+ const arbi = chunkQQ7SCJRY_cjs.useArbi();
1903
+ return reactQuery.useQuery({
1904
+ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recording(callExtId ?? "", recordingExtId ?? ""),
1905
+ queryFn: () => arbi.calls.recording.get(callExtId, recordingExtId),
1906
+ enabled: !!callExtId && !!recordingExtId && arbi.isLoggedIn,
1907
+ retry: false
1908
+ });
1846
1909
  }
1847
- function relay(type, message) {
1848
- if (!message) return;
1849
- for (const listener of listeners2.get(type) ?? []) {
1850
- listener(message);
1851
- }
1910
+ var NO_WINDOWS = [];
1911
+ function useRecordingWindows(callExtId, enabled) {
1912
+ const { data } = useCallRecordings(callExtId, enabled);
1913
+ return react.useMemo(() => data ? recordingWindowsOf(data) : NO_WINDOWS, [data]);
1852
1914
  }
1853
- var str = (value) => typeof value === "string" && value ? value : null;
1854
- function applyCallEvent(queryClient, event, options = {}) {
1855
- const m = event;
1856
- const callExtId = str(m.call_ext_id);
1857
- switch (m.type) {
1858
- case "call.ringing": {
1859
- const ring = m;
1860
- if (options.acceptRings === false || !callExtId || !ring.sealed_key) return true;
1861
- if (options.me && ring.caller_ext_id === options.me) return true;
1862
- callSession.enqueueIncomingCall({
1863
- call_ext_id: ring.call_ext_id,
1864
- room_name: ring.room_name,
1865
- caller_ext_id: ring.caller_ext_id,
1866
- caller_name: ring.caller_name,
1867
- chat_ext_id: ring.chat_ext_id ?? null,
1868
- log_conversation_ext_id: ring.log_conversation_ext_id ?? null,
1869
- meeting_conversation_ext_id: ring.meeting_conversation_ext_id ?? null,
1870
- workspace_ext_id: ring.workspace_ext_id ?? null,
1871
- context: ring.context ?? null,
1872
- sealed_key: ring.sealed_key,
1873
- link_version: ring.link_version,
1874
- title: ring.title ?? null
1875
- });
1876
- return true;
1877
- }
1878
- case "call.declined":
1879
- if (callExtId && callSession.getState().active?.callExtId === callExtId) {
1880
- chunkVAMPYLQ4_cjs.notify.info("Call declined", { record: false, ambient: false });
1881
- }
1882
- return true;
1883
- case "call.started":
1884
- if (!callExtId) return true;
1885
- callSession.markCallLive(callExtId, {
1886
- chatExtId: str(m.chat_ext_id),
1887
- logConversationExtId: str(m.log_conversation_ext_id),
1888
- meetingConversationExtId: str(m.meeting_conversation_ext_id)
1889
- });
1890
- invalidateCall(queryClient, {
1891
- call_ext_id: callExtId,
1892
- log_conversation_ext_id: str(m.log_conversation_ext_id)
1893
- });
1894
- return true;
1895
- case "call.ended":
1896
- if (!callExtId) return true;
1897
- callSession.markCallEnded(callExtId);
1898
- invalidateCall(queryClient, {
1899
- call_ext_id: callExtId,
1900
- log_conversation_ext_id: str(m.log_conversation_ext_id)
1901
- });
1902
- return true;
1903
- case "call.knock": {
1904
- const knock = m;
1905
- if (!callExtId) return true;
1906
- callSession.addKnock({
1907
- callExtId,
1908
- knockId: knock.knock_id,
1909
- displayName: knock.display_name,
1910
- userExtId: knock.user_ext_id
1911
- });
1912
- return true;
1913
- }
1914
- case "call.knock_resolved": {
1915
- const knockId = str(m.knock_id);
1916
- if (knockId) callSession.removeKnock(knockId);
1917
- return true;
1918
- }
1919
- case "call.recording": {
1920
- if (callExtId)
1921
- void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(callExtId) });
1922
- const state2 = browser.calls.recordingStateFrom(m);
1923
- relay("call.recording", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
1924
- return true;
1925
- }
1926
- case "call.recording_updated": {
1927
- if (callExtId)
1928
- void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(callExtId) });
1929
- return true;
1930
- }
1931
- case "call.recording_deleted": {
1932
- if (callExtId)
1933
- void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(callExtId) });
1934
- const recordingExtId = str(m.recording_ext_id);
1935
- relay(
1936
- "call.recording_deleted",
1937
- callExtId && recordingExtId ? { call_ext_id: callExtId, recording_ext_id: recordingExtId } : null
1938
- );
1939
- return true;
1940
- }
1941
- case "call.transcription": {
1942
- const state2 = browser.calls.transcriptionStateFrom(m);
1943
- relay("call.transcription", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
1944
- return true;
1945
- }
1946
- case "call.webinar":
1947
- relay(
1948
- "call.webinar",
1949
- callExtId && typeof m.live === "boolean" ? {
1950
- type: "call.webinar",
1951
- call_ext_id: callExtId,
1952
- live: m.live,
1953
- chat: m.chat === "everyone" ? "everyone" : "panelists"
1954
- } : null
1955
- );
1956
- return true;
1957
- case "call.muted":
1958
- relay("call.muted", mutedNoticeFromEvent(m));
1959
- return true;
1960
- default:
1961
- return false;
1962
- }
1915
+ function useCallInviteLinks(callExtId) {
1916
+ const arbi = chunkQQ7SCJRY_cjs.useArbi();
1917
+ return reactQuery.useQuery({
1918
+ queryKey: chunkRRWAX52L_cjs.callQueryKeys.inviteLinks(callExtId ?? ""),
1919
+ queryFn: () => arbi.calls.inviteLinks.list(callExtId),
1920
+ enabled: !!callExtId && arbi.isLoggedIn,
1921
+ retry: false
1922
+ });
1963
1923
  }
1964
- function useCallLiveUpdates(options = {}) {
1924
+ function useRecordingActions(call) {
1965
1925
  const arbi = chunkQQ7SCJRY_cjs.useArbi();
1966
1926
  const queryClient = reactQuery.useQueryClient();
1967
- const ws = react.useContext(ArbiWsContext);
1968
- const latest = react.useRef({ ...options, me: options.me ?? null });
1969
- latest.current = {
1970
- ...options,
1971
- me: options.me ?? (arbi.isLoggedIn ? arbi.user.identity()?.externalId ?? null : null)
1972
- };
1973
- react.useEffect(
1974
- () => ws?.subscribe((message) => {
1975
- if (message.type.startsWith("call.")) applyCallEvent(queryClient, message, latest.current);
1927
+ return react.useMemo(
1928
+ () => ({
1929
+ refresh: () => void queryClient.invalidateQueries({
1930
+ queryKey: chunkRRWAX52L_cjs.callQueryKeys.recordingsOf(call.external_id)
1931
+ }),
1932
+ open: (recording) => openRecording(arbi, queryClient, call, recording.external_id, recording),
1933
+ transcribe: async (opened, onProgress) => transcribeRecording({
1934
+ arbi,
1935
+ queryClient,
1936
+ callExtId: call.external_id,
1937
+ opened,
1938
+ ref: await meetingRefForCall(arbi, queryClient, call),
1939
+ onProgress
1940
+ })
1976
1941
  }),
1977
- [ws, queryClient]
1942
+ [arbi, queryClient, call]
1943
+ );
1944
+ }
1945
+ function useRevokeCallInviteLink(callExtId) {
1946
+ const arbi = chunkQQ7SCJRY_cjs.useArbi();
1947
+ const queryClient = reactQuery.useQueryClient();
1948
+ return react.useCallback(
1949
+ async (inviteExtId) => {
1950
+ await arbi.calls.inviteLinks.revoke(callExtId, inviteExtId);
1951
+ void queryClient.invalidateQueries({ queryKey: chunkRRWAX52L_cjs.callQueryKeys.inviteLinks(callExtId) });
1952
+ },
1953
+ [arbi, queryClient, callExtId]
1978
1954
  );
1979
1955
  }
1980
1956
  async function postToThread(arbi, conversationExtId, newThreadTitle, content) {
@@ -2360,7 +2336,6 @@ function useOpenCallMeetingChat() {
2360
2336
  }
2361
2337
 
2362
2338
  exports.AUDIENCE_CHOICES = AUDIENCE_CHOICES;
2363
- exports.ArbiWsContext = ArbiWsContext;
2364
2339
  exports.CALL_CAPTION_TOPIC = CALL_CAPTION_TOPIC;
2365
2340
  exports.CALL_CHAT_MAX_CHARS = CALL_CHAT_MAX_CHARS;
2366
2341
  exports.CALL_CHAT_TOPIC = CALL_CHAT_TOPIC;
@@ -2521,11 +2496,9 @@ exports.transcriptSegmentOf = transcriptSegmentOf;
2521
2496
  exports.unwrapTrackKey = unwrapTrackKey;
2522
2497
  exports.upsertChat = upsertChat;
2523
2498
  exports.useAccountClient = useAccountClient;
2524
- exports.useArbiWsContext = useArbiWsContext;
2525
2499
  exports.useAvatarCrop = useAvatarCrop;
2526
2500
  exports.useCall = useCall;
2527
2501
  exports.useCallInviteLinks = useCallInviteLinks;
2528
- exports.useCallLiveUpdates = useCallLiveUpdates;
2529
2502
  exports.useCallRecording = useCallRecording;
2530
2503
  exports.useCallRecordings = useCallRecordings;
2531
2504
  exports.useCallSession = useCallSession;
@@ -2547,5 +2520,5 @@ exports.useServerCallsEnabled = useServerCallsEnabled;
2547
2520
  exports.useUpdateProfile = useUpdateProfile;
2548
2521
  exports.wrapTrackKey = wrapTrackKey;
2549
2522
  exports.writeSamples = writeSamples;
2550
- //# sourceMappingURL=chunk-VVSSTVEB.cjs.map
2551
- //# sourceMappingURL=chunk-VVSSTVEB.cjs.map
2523
+ //# sourceMappingURL=chunk-TUKW4MCI.cjs.map
2524
+ //# sourceMappingURL=chunk-TUKW4MCI.cjs.map