@arbidocs/react 0.4.167 → 0.4.169
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifacts/index.cjs +15 -12
- package/dist/artifacts/index.cjs.map +1 -1
- package/dist/artifacts/index.js +6 -3
- package/dist/artifacts/index.js.map +1 -1
- package/dist/calls/livekit/index.cjs +977 -0
- package/dist/calls/livekit/index.cjs.map +1 -0
- package/dist/calls/livekit/index.d.cts +280 -0
- package/dist/calls/livekit/index.d.ts +280 -0
- package/dist/calls/livekit/index.js +961 -0
- package/dist/calls/livekit/index.js.map +1 -0
- package/dist/{chunk-ON4PL6DQ.cjs → chunk-2M4B4FFA.cjs} +48 -4
- package/dist/chunk-2M4B4FFA.cjs.map +1 -0
- package/dist/chunk-3NVSUYUV.js +528 -0
- package/dist/chunk-3NVSUYUV.js.map +1 -0
- package/dist/{chunk-QJHCVQ6C.js → chunk-3WIBD44F.js} +4734 -4673
- package/dist/chunk-3WIBD44F.js.map +1 -0
- package/dist/chunk-5HDC43MF.js +145 -0
- package/dist/chunk-5HDC43MF.js.map +1 -0
- package/dist/{chunk-D66JCVBB.cjs → chunk-7NHOKV7N.cjs} +4093 -4040
- package/dist/chunk-7NHOKV7N.cjs.map +1 -0
- package/dist/chunk-7NY2J3TR.js +986 -0
- package/dist/chunk-7NY2J3TR.js.map +1 -0
- package/dist/chunk-APZZQZ6P.js +147 -0
- package/dist/chunk-APZZQZ6P.js.map +1 -0
- package/dist/{chunk-I5ZBQ63Y.js → chunk-DGMK3EUN.js} +188 -181
- package/dist/chunk-DGMK3EUN.js.map +1 -0
- package/dist/chunk-DPYBZDJB.js +18 -0
- package/dist/chunk-DPYBZDJB.js.map +1 -0
- package/dist/chunk-EEIYXVM4.cjs +181 -0
- package/dist/chunk-EEIYXVM4.cjs.map +1 -0
- package/dist/chunk-GGYCK5A6.cjs +1035 -0
- package/dist/chunk-GGYCK5A6.cjs.map +1 -0
- package/dist/{chunk-JSSKEXRR.js → chunk-KGCGA452.js} +2 -2
- package/dist/chunk-KGCGA452.js.map +1 -0
- package/dist/chunk-N73IMVFF.cjs +21 -0
- package/dist/chunk-N73IMVFF.cjs.map +1 -0
- package/dist/chunk-NVAIVJID.js +298 -0
- package/dist/chunk-NVAIVJID.js.map +1 -0
- package/dist/{chunk-GTJ667CP.cjs → chunk-QQ7SCJRY.cjs} +2 -2
- package/dist/chunk-QQ7SCJRY.cjs.map +1 -0
- package/dist/chunk-S4PCA3ES.cjs +572 -0
- package/dist/chunk-S4PCA3ES.cjs.map +1 -0
- package/dist/chunk-VAMPYLQ4.cjs +157 -0
- package/dist/chunk-VAMPYLQ4.cjs.map +1 -0
- package/dist/chunk-VLK52VXC.cjs +307 -0
- package/dist/chunk-VLK52VXC.cjs.map +1 -0
- package/dist/chunk-VPKFUYGW.cjs +2551 -0
- package/dist/chunk-VPKFUYGW.cjs.map +1 -0
- package/dist/chunk-W6DYNLA2.js +2362 -0
- package/dist/chunk-W6DYNLA2.js.map +1 -0
- package/dist/{chunk-SVHGCX25.js → chunk-YWYCEEBF.js} +43 -4
- package/dist/chunk-YWYCEEBF.js.map +1 -0
- package/dist/{chunk-EUC2BTNS.cjs → chunk-ZI2VJOID.cjs} +206 -199
- package/dist/chunk-ZI2VJOID.cjs.map +1 -0
- package/dist/document-tools/index.cjs +79 -107
- package/dist/document-tools/index.cjs.map +1 -1
- package/dist/document-tools/index.d.cts +4 -5
- package/dist/document-tools/index.d.ts +4 -5
- package/dist/document-tools/index.js +23 -68
- package/dist/document-tools/index.js.map +1 -1
- package/dist/index.cjs +12650 -9452
- package/dist/index.cjs.map +1 -1
- package/dist/{index.d-DfCFKora.d.cts → index.d-Bvp6rKNo.d.cts} +139 -1
- package/dist/{index.d-DfCFKora.d.ts → index.d-Bvp6rKNo.d.ts} +139 -1
- package/dist/{index.d-DCjYj7YK.d.ts → index.d-Dx9sGkW2.d.cts} +20 -8
- package/dist/{index.d-DCjYj7YK.d.cts → index.d-Dx9sGkW2.d.ts} +20 -8
- package/dist/index.d.cts +5465 -2291
- package/dist/index.d.ts +5465 -2291
- package/dist/index.js +11047 -8858
- package/dist/index.js.map +1 -1
- package/dist/query-keys.d-Kw0JMoff.d.cts +308 -0
- package/dist/query-keys.d-Kw0JMoff.d.ts +308 -0
- package/dist/shell/index.cjs +78 -21
- package/dist/shell/index.d.cts +1 -1
- package/dist/shell/index.d.ts +1 -1
- package/dist/shell/index.js +6 -1
- package/dist/ui/index.cjs +191 -186
- package/dist/ui/index.d.cts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +3 -2
- package/dist/useAudioRecorder.d-CWFDsb_S.d.cts +778 -0
- package/dist/useAudioRecorder.d-CWFDsb_S.d.ts +778 -0
- package/dist/viewers/index.cjs +22 -13
- package/dist/viewers/index.cjs.map +1 -1
- package/dist/viewers/index.js +21 -12
- package/dist/viewers/index.js.map +1 -1
- package/package.json +13 -3
- package/dist/chunk-6MTKKT2O.cjs +0 -999
- package/dist/chunk-6MTKKT2O.cjs.map +0 -1
- package/dist/chunk-CEZCFQ47.js +0 -932
- package/dist/chunk-CEZCFQ47.js.map +0 -1
- package/dist/chunk-D66JCVBB.cjs.map +0 -1
- package/dist/chunk-EUC2BTNS.cjs.map +0 -1
- package/dist/chunk-GTJ667CP.cjs.map +0 -1
- package/dist/chunk-I5ZBQ63Y.js.map +0 -1
- package/dist/chunk-JSSKEXRR.js.map +0 -1
- package/dist/chunk-ON4PL6DQ.cjs.map +0 -1
- package/dist/chunk-QJHCVQ6C.js.map +0 -1
- package/dist/chunk-SVHGCX25.js.map +0 -1
|
@@ -0,0 +1,977 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVPKFUYGW_cjs = require('../../chunk-VPKFUYGW.cjs');
|
|
4
|
+
require('../../chunk-GGYCK5A6.cjs');
|
|
5
|
+
require('../../chunk-VLK52VXC.cjs');
|
|
6
|
+
var chunkVAMPYLQ4_cjs = require('../../chunk-VAMPYLQ4.cjs');
|
|
7
|
+
require('../../chunk-N73IMVFF.cjs');
|
|
8
|
+
require('../../chunk-ZWFMFOGP.cjs');
|
|
9
|
+
require('../../chunk-VOFNX4P6.cjs');
|
|
10
|
+
require('../../chunk-EEIYXVM4.cjs');
|
|
11
|
+
require('../../chunk-Z3LLUO32.cjs');
|
|
12
|
+
require('../../chunk-S6A6FSG7.cjs');
|
|
13
|
+
var chunkQQ7SCJRY_cjs = require('../../chunk-QQ7SCJRY.cjs');
|
|
14
|
+
require('../../chunk-RCKA7BEF.cjs');
|
|
15
|
+
var react = require('react');
|
|
16
|
+
var livekitClient = require('livekit-client');
|
|
17
|
+
var componentsReact = require('@livekit/components-react');
|
|
18
|
+
var reactQuery = require('@tanstack/react-query');
|
|
19
|
+
var browser = require('@arbidocs/sdk/browser');
|
|
20
|
+
|
|
21
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
22
|
+
function createE2EEWorker() {
|
|
23
|
+
return new Worker(new URL("livekit-client/e2ee-worker", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))), { type: "module" });
|
|
24
|
+
}
|
|
25
|
+
function createRoom(e2eeKey, choices, createWorker) {
|
|
26
|
+
const options = {
|
|
27
|
+
adaptiveStream: true,
|
|
28
|
+
dynacast: true,
|
|
29
|
+
audioCaptureDefaults: choices.audioDeviceId ? { deviceId: choices.audioDeviceId } : void 0,
|
|
30
|
+
videoCaptureDefaults: choices.videoDeviceId ? { deviceId: choices.videoDeviceId } : void 0
|
|
31
|
+
};
|
|
32
|
+
let worker = null;
|
|
33
|
+
let keyProvider = null;
|
|
34
|
+
if (e2eeKey) {
|
|
35
|
+
keyProvider = new livekitClient.ExternalE2EEKeyProvider();
|
|
36
|
+
worker = createWorker();
|
|
37
|
+
options.e2ee = { keyProvider, worker };
|
|
38
|
+
}
|
|
39
|
+
const room = new livekitClient.Room(options);
|
|
40
|
+
const ready = (async () => {
|
|
41
|
+
if (!keyProvider || !e2eeKey) return;
|
|
42
|
+
await keyProvider.setKey(e2eeKey.slice().buffer);
|
|
43
|
+
await room.setE2EEEnabled(true);
|
|
44
|
+
})();
|
|
45
|
+
return { bundle: { room, worker }, ready };
|
|
46
|
+
}
|
|
47
|
+
function useCallRoom(e2eeKey, choices, options = {}) {
|
|
48
|
+
const [room, setRoom] = react.useState(null);
|
|
49
|
+
const [error, setError] = react.useState(null);
|
|
50
|
+
react.useEffect(() => {
|
|
51
|
+
let cancelled = false;
|
|
52
|
+
let created = null;
|
|
53
|
+
try {
|
|
54
|
+
const { bundle, ready } = createRoom(
|
|
55
|
+
e2eeKey,
|
|
56
|
+
choices,
|
|
57
|
+
options.createWorker ?? createE2EEWorker
|
|
58
|
+
);
|
|
59
|
+
created = bundle;
|
|
60
|
+
ready.then(() => {
|
|
61
|
+
if (!cancelled) setRoom(bundle.room);
|
|
62
|
+
}).catch((err) => {
|
|
63
|
+
console.error("[calls] E2EE setup failed", err);
|
|
64
|
+
if (!cancelled) setError("This browser cannot encrypt the call (E2EE unsupported).");
|
|
65
|
+
});
|
|
66
|
+
} catch (err) {
|
|
67
|
+
console.error("[calls] room setup failed", err);
|
|
68
|
+
setError("Could not set up the call in this browser.");
|
|
69
|
+
}
|
|
70
|
+
return () => {
|
|
71
|
+
cancelled = true;
|
|
72
|
+
if (created) {
|
|
73
|
+
void created.room.disconnect();
|
|
74
|
+
created.worker?.terminate();
|
|
75
|
+
}
|
|
76
|
+
setRoom(null);
|
|
77
|
+
};
|
|
78
|
+
}, [e2eeKey]);
|
|
79
|
+
return { room, error };
|
|
80
|
+
}
|
|
81
|
+
var MUTE_REQUEST_TOPIC = "arbi.mute-request";
|
|
82
|
+
function useMuteRequests() {
|
|
83
|
+
const room = componentsReact.useRoomContext();
|
|
84
|
+
react.useEffect(() => {
|
|
85
|
+
const onData = (payload, from, _kind, topic) => {
|
|
86
|
+
if (topic !== MUTE_REQUEST_TOPIC || !from) return;
|
|
87
|
+
const who = from.name || from.identity;
|
|
88
|
+
chunkVAMPYLQ4_cjs.notify.info(`${who} asks you to mute your microphone`, {
|
|
89
|
+
action: {
|
|
90
|
+
label: "Mute",
|
|
91
|
+
onClick: () => void room.localParticipant.setMicrophoneEnabled(false)
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
room.on(livekitClient.RoomEvent.DataReceived, onData);
|
|
96
|
+
return () => {
|
|
97
|
+
room.off(livekitClient.RoomEvent.DataReceived, onData);
|
|
98
|
+
};
|
|
99
|
+
}, [room]);
|
|
100
|
+
return (identity) => void room.localParticipant.publishData(new TextEncoder().encode('{"v":1}'), {
|
|
101
|
+
reliable: true,
|
|
102
|
+
topic: MUTE_REQUEST_TOPIC,
|
|
103
|
+
destinationIdentities: [identity]
|
|
104
|
+
}).then(() => chunkVAMPYLQ4_cjs.notify.info("Asked to mute")).catch((err) => chunkVAMPYLQ4_cjs.notify.error(`Could not ask: ${err.message}`));
|
|
105
|
+
}
|
|
106
|
+
var FINAL_SEGMENT_GRACE_MS = 3e4;
|
|
107
|
+
function mayStillSend(params) {
|
|
108
|
+
if (params.sending) return true;
|
|
109
|
+
if (params.stoppedAt === null) return false;
|
|
110
|
+
return params.segmentStartedAt <= params.stoppedAt && params.now - params.stoppedAt <= FINAL_SEGMENT_GRACE_MS;
|
|
111
|
+
}
|
|
112
|
+
function storedSpeakerName(participantName, profileName, identity) {
|
|
113
|
+
return participantName?.trim() || profileName?.trim() || identity;
|
|
114
|
+
}
|
|
115
|
+
function useCallTranscriber({
|
|
116
|
+
callExtId,
|
|
117
|
+
callKey,
|
|
118
|
+
isCreator,
|
|
119
|
+
canPost,
|
|
120
|
+
linkVersion = null
|
|
121
|
+
}) {
|
|
122
|
+
const room = componentsReact.useRoomContext();
|
|
123
|
+
const { localParticipant } = componentsReact.useLocalParticipant();
|
|
124
|
+
const myIdentity = localParticipant.identity;
|
|
125
|
+
const arbi = chunkQQ7SCJRY_cjs.useArbi();
|
|
126
|
+
const queryClient = reactQuery.useQueryClient();
|
|
127
|
+
const profile = arbi.isLoggedIn ? arbi.user.profile() : null;
|
|
128
|
+
const myProfileName = profile && chunkVPKFUYGW_cjs.toProfileView(profile).fullName || null;
|
|
129
|
+
const deploymentAvailable = chunkVPKFUYGW_cjs.useCallTranscriptionAvailable();
|
|
130
|
+
const available = deploymentAvailable && !!callKey;
|
|
131
|
+
const [state, setState] = react.useState(null);
|
|
132
|
+
const [creatorExtId, setCreatorExtId] = react.useState(null);
|
|
133
|
+
const [busy, setBusy] = react.useState(false);
|
|
134
|
+
const [muted, setMuted] = react.useState(false);
|
|
135
|
+
const [indicatorShown, setIndicatorShown] = react.useState(false);
|
|
136
|
+
const [captions, setCaptions] = react.useState([]);
|
|
137
|
+
const liveUpdate = react.useRef(false);
|
|
138
|
+
const persisted = react.useRef(/* @__PURE__ */ new Set());
|
|
139
|
+
const saveFailureShown = react.useRef(false);
|
|
140
|
+
const selfPosts = react.useRef(canPost);
|
|
141
|
+
react.useEffect(() => {
|
|
142
|
+
selfPosts.current = canPost;
|
|
143
|
+
}, [canPost]);
|
|
144
|
+
const on = available && !!state?.on;
|
|
145
|
+
const shouldSend = on && indicatorShown && !muted;
|
|
146
|
+
const shouldSendRef = react.useRef(shouldSend);
|
|
147
|
+
const sendStoppedAtRef = react.useRef(null);
|
|
148
|
+
if (shouldSendRef.current !== shouldSend) {
|
|
149
|
+
sendStoppedAtRef.current = shouldSend ? null : Date.now();
|
|
150
|
+
}
|
|
151
|
+
shouldSendRef.current = shouldSend;
|
|
152
|
+
const myPreviousText = react.useRef("");
|
|
153
|
+
const applyState = react.useCallback((next) => {
|
|
154
|
+
liveUpdate.current = true;
|
|
155
|
+
setState(next);
|
|
156
|
+
}, []);
|
|
157
|
+
react.useEffect(() => {
|
|
158
|
+
if (!available) return;
|
|
159
|
+
let cancelled = false;
|
|
160
|
+
arbi.calls.get(callExtId).then((call) => {
|
|
161
|
+
if (cancelled) return;
|
|
162
|
+
setCreatorExtId(call.creator_ext_id ?? null);
|
|
163
|
+
if (!liveUpdate.current) {
|
|
164
|
+
setState(browser.calls.transcriptionStateFrom(call.transcription));
|
|
165
|
+
}
|
|
166
|
+
}).catch((err) => console.warn("[calls] could not read the transcription state", err));
|
|
167
|
+
return () => {
|
|
168
|
+
cancelled = true;
|
|
169
|
+
};
|
|
170
|
+
}, [available, callExtId]);
|
|
171
|
+
react.useEffect(
|
|
172
|
+
() => chunkVPKFUYGW_cjs.onCallEvent("call.transcription", (message) => {
|
|
173
|
+
if (message.call_ext_id === callExtId) applyState(message);
|
|
174
|
+
}),
|
|
175
|
+
[callExtId, applyState]
|
|
176
|
+
);
|
|
177
|
+
const addCaption = react.useCallback((line) => {
|
|
178
|
+
setCaptions((prev) => {
|
|
179
|
+
if (prev.some((c) => c.segmentId === line.segmentId && c.identity === line.identity)) {
|
|
180
|
+
return prev;
|
|
181
|
+
}
|
|
182
|
+
return [...prev, line].sort((a, b) => a.t - b.t).slice(-30);
|
|
183
|
+
});
|
|
184
|
+
}, []);
|
|
185
|
+
const persist = react.useCallback(
|
|
186
|
+
(segment, speakerNeedsProxy) => {
|
|
187
|
+
if (!callKey || persisted.current.has(segment.segmentId)) return;
|
|
188
|
+
const role = chunkVPKFUYGW_cjs.transcriptPersistRole({
|
|
189
|
+
myIdentity,
|
|
190
|
+
canPost: canPost && (segment.speakerIdentity !== myIdentity || selfPosts.current),
|
|
191
|
+
hasCallKey: true,
|
|
192
|
+
speakerIdentity: segment.speakerIdentity,
|
|
193
|
+
speakerNeedsProxy
|
|
194
|
+
});
|
|
195
|
+
if (!role) return;
|
|
196
|
+
persisted.current.add(segment.segmentId);
|
|
197
|
+
chunkVPKFUYGW_cjs.persistTranscriptSegment(arbi, queryClient, callExtId, callKey, segment).catch(
|
|
198
|
+
(err) => {
|
|
199
|
+
persisted.current.delete(segment.segmentId);
|
|
200
|
+
if (role === "own" && err?.status === 403) {
|
|
201
|
+
selfPosts.current = false;
|
|
202
|
+
}
|
|
203
|
+
console.warn("[calls] could not keep the transcript line", err);
|
|
204
|
+
if (!saveFailureShown.current) {
|
|
205
|
+
saveFailureShown.current = true;
|
|
206
|
+
chunkVAMPYLQ4_cjs.notify.warning(
|
|
207
|
+
`Transcript lines are not being saved to the meeting chat: ${err?.message ?? "unknown error"}`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
[callExtId, callKey, myIdentity, canPost]
|
|
214
|
+
);
|
|
215
|
+
react.useEffect(() => {
|
|
216
|
+
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
217
|
+
if (topic === chunkVPKFUYGW_cjs.CALL_TRANSCRIPTION_TOPIC) {
|
|
218
|
+
if (participant || participantIdentity) return;
|
|
219
|
+
try {
|
|
220
|
+
const next = browser.calls.transcriptionStateFrom(JSON.parse(new TextDecoder().decode(payload)));
|
|
221
|
+
if (next) applyState(next);
|
|
222
|
+
} catch {
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (topic !== chunkVPKFUYGW_cjs.CALL_CAPTION_TOPIC || !callKey) return;
|
|
227
|
+
const identity = participant?.identity ?? participantIdentity;
|
|
228
|
+
if (!identity || identity === myIdentity) return;
|
|
229
|
+
void chunkVPKFUYGW_cjs.decodeCaptionPacket(payload, callKey).then((packet) => {
|
|
230
|
+
if (!packet || packet.identity !== identity) return;
|
|
231
|
+
const name = participant?.name || packet.name || identity;
|
|
232
|
+
const t = Math.min(packet.t, Date.now());
|
|
233
|
+
addCaption({
|
|
234
|
+
segmentId: packet.segment_id,
|
|
235
|
+
identity,
|
|
236
|
+
name,
|
|
237
|
+
text: packet.text,
|
|
238
|
+
t,
|
|
239
|
+
mine: false,
|
|
240
|
+
receivedAt: Date.now()
|
|
241
|
+
});
|
|
242
|
+
persist(
|
|
243
|
+
{
|
|
244
|
+
segmentId: packet.segment_id,
|
|
245
|
+
text: packet.text,
|
|
246
|
+
speakerIdentity: identity,
|
|
247
|
+
speakerName: name,
|
|
248
|
+
startedAt: new Date(t).toISOString()
|
|
249
|
+
},
|
|
250
|
+
packet.proxy === true
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
room.on(livekitClient.RoomEvent.DataReceived, onData);
|
|
255
|
+
return () => {
|
|
256
|
+
room.off(livekitClient.RoomEvent.DataReceived, onData);
|
|
257
|
+
};
|
|
258
|
+
}, [room, callKey, myIdentity, addCaption, applyState, persist]);
|
|
259
|
+
const handleSegment = react.useCallback(
|
|
260
|
+
async (segment) => {
|
|
261
|
+
if (!callKey || !mayStillSend({
|
|
262
|
+
sending: shouldSendRef.current,
|
|
263
|
+
stoppedAt: sendStoppedAtRef.current,
|
|
264
|
+
segmentStartedAt: segment.startedAt,
|
|
265
|
+
now: Date.now()
|
|
266
|
+
})) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const segmentId = chunkVPKFUYGW_cjs.newSegmentId();
|
|
270
|
+
const startedAt = new Date(segment.startedAt).toISOString();
|
|
271
|
+
let text;
|
|
272
|
+
try {
|
|
273
|
+
const result = await arbi.calls.transcription.transcribe(callExtId, {
|
|
274
|
+
audio: segment.blob,
|
|
275
|
+
segmentId,
|
|
276
|
+
startedAt,
|
|
277
|
+
linkVersion,
|
|
278
|
+
prompt: browser.continuityPrompt(myPreviousText.current)
|
|
279
|
+
});
|
|
280
|
+
text = result.text.trim();
|
|
281
|
+
} catch (err) {
|
|
282
|
+
if (err instanceof browser.CallApiError && err.status === 409) {
|
|
283
|
+
applyState({ on: false, by_identity: null, by_name: null });
|
|
284
|
+
}
|
|
285
|
+
console.warn("[calls] could not transcribe a segment", err);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (!text) return;
|
|
289
|
+
myPreviousText.current = `${myPreviousText.current} ${text}`.slice(-400);
|
|
290
|
+
const name = storedSpeakerName(localParticipant.name, myProfileName, myIdentity);
|
|
291
|
+
const proxy = !selfPosts.current;
|
|
292
|
+
addCaption({
|
|
293
|
+
segmentId,
|
|
294
|
+
identity: myIdentity,
|
|
295
|
+
name,
|
|
296
|
+
text,
|
|
297
|
+
t: segment.startedAt,
|
|
298
|
+
mine: true,
|
|
299
|
+
receivedAt: Date.now()
|
|
300
|
+
});
|
|
301
|
+
try {
|
|
302
|
+
await localParticipant.publishData(
|
|
303
|
+
await chunkVPKFUYGW_cjs.encodeCaptionPacket(
|
|
304
|
+
{
|
|
305
|
+
v: 1,
|
|
306
|
+
segment_id: segmentId,
|
|
307
|
+
text,
|
|
308
|
+
identity: myIdentity,
|
|
309
|
+
name,
|
|
310
|
+
t: segment.startedAt,
|
|
311
|
+
...proxy ? { proxy: true } : {}
|
|
312
|
+
},
|
|
313
|
+
callKey
|
|
314
|
+
),
|
|
315
|
+
{ reliable: true, topic: chunkVPKFUYGW_cjs.CALL_CAPTION_TOPIC }
|
|
316
|
+
);
|
|
317
|
+
} catch (err) {
|
|
318
|
+
console.warn("[calls] could not broadcast a caption", err);
|
|
319
|
+
}
|
|
320
|
+
if (!proxy) {
|
|
321
|
+
persist(
|
|
322
|
+
{ segmentId, text, speakerIdentity: myIdentity, speakerName: name, startedAt },
|
|
323
|
+
false
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
[
|
|
328
|
+
callExtId,
|
|
329
|
+
callKey,
|
|
330
|
+
linkVersion,
|
|
331
|
+
localParticipant,
|
|
332
|
+
myIdentity,
|
|
333
|
+
myProfileName,
|
|
334
|
+
addCaption,
|
|
335
|
+
applyState,
|
|
336
|
+
persist
|
|
337
|
+
]
|
|
338
|
+
);
|
|
339
|
+
const startedByMe = !!state?.on && state.by_identity === myIdentity;
|
|
340
|
+
const canToggle = available && (isCreator || !!creatorExtId && creatorExtId === myIdentity);
|
|
341
|
+
const toggle = react.useCallback(async () => {
|
|
342
|
+
if (!canToggle) return;
|
|
343
|
+
const next = !on;
|
|
344
|
+
setBusy(true);
|
|
345
|
+
try {
|
|
346
|
+
const answer = await arbi.calls.transcription.set(callExtId, next);
|
|
347
|
+
applyState(
|
|
348
|
+
answer ?? (next ? { on: true, by_identity: myIdentity, by_name: localParticipant.name || null } : { on: false, by_identity: null, by_name: null })
|
|
349
|
+
);
|
|
350
|
+
} catch (err) {
|
|
351
|
+
chunkVAMPYLQ4_cjs.notify.error(`Could not turn transcription ${next ? "on" : "off"}: ${err.message}`);
|
|
352
|
+
} finally {
|
|
353
|
+
setBusy(false);
|
|
354
|
+
}
|
|
355
|
+
}, [on, canToggle, callExtId, myIdentity, localParticipant, applyState]);
|
|
356
|
+
return react.useMemo(
|
|
357
|
+
() => ({
|
|
358
|
+
available,
|
|
359
|
+
on,
|
|
360
|
+
startedByName: on ? state?.by_name ?? null : null,
|
|
361
|
+
startedByMe,
|
|
362
|
+
canToggle,
|
|
363
|
+
busy,
|
|
364
|
+
muted,
|
|
365
|
+
setMuted,
|
|
366
|
+
toggle,
|
|
367
|
+
setIndicatorShown,
|
|
368
|
+
shouldSend,
|
|
369
|
+
captions,
|
|
370
|
+
handleSegment
|
|
371
|
+
}),
|
|
372
|
+
[
|
|
373
|
+
available,
|
|
374
|
+
on,
|
|
375
|
+
state,
|
|
376
|
+
startedByMe,
|
|
377
|
+
canToggle,
|
|
378
|
+
busy,
|
|
379
|
+
muted,
|
|
380
|
+
toggle,
|
|
381
|
+
shouldSend,
|
|
382
|
+
captions,
|
|
383
|
+
handleSegment
|
|
384
|
+
]
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
function captureAllowed(params) {
|
|
388
|
+
return params.available && !!params.state?.on && !!params.state.recording_ext_id && params.indicatorShown;
|
|
389
|
+
}
|
|
390
|
+
function useCallRecorder({
|
|
391
|
+
callExtId,
|
|
392
|
+
callKey,
|
|
393
|
+
isCreator,
|
|
394
|
+
linkVersion = null
|
|
395
|
+
}) {
|
|
396
|
+
const arbi = chunkQQ7SCJRY_cjs.useArbi();
|
|
397
|
+
const queryClient = reactQuery.useQueryClient();
|
|
398
|
+
const room = componentsReact.useRoomContext();
|
|
399
|
+
const { localParticipant } = componentsReact.useLocalParticipant();
|
|
400
|
+
const myIdentity = localParticipant.identity;
|
|
401
|
+
const available = !!callKey;
|
|
402
|
+
const [state, setState] = react.useState(null);
|
|
403
|
+
const [call, setCall] = react.useState(null);
|
|
404
|
+
const [busy, setBusy] = react.useState(false);
|
|
405
|
+
const [indicatorShown, setIndicatorShown] = react.useState(false);
|
|
406
|
+
const [pendingStart, setPendingStart] = react.useState(null);
|
|
407
|
+
const liveUpdate = react.useRef(false);
|
|
408
|
+
const stateRef = react.useRef(null);
|
|
409
|
+
stateRef.current = state;
|
|
410
|
+
const applyState = react.useCallback((next) => {
|
|
411
|
+
liveUpdate.current = true;
|
|
412
|
+
if (stateRef.current?.on && next && !next.on && next.reason === "storage_quota_exceeded") {
|
|
413
|
+
chunkVAMPYLQ4_cjs.notify.warning("Recording stopped: the storage is full.");
|
|
414
|
+
}
|
|
415
|
+
stateRef.current = next;
|
|
416
|
+
setState(next);
|
|
417
|
+
}, []);
|
|
418
|
+
react.useEffect(() => {
|
|
419
|
+
let cancelled = false;
|
|
420
|
+
arbi.calls.get(callExtId).then((row) => {
|
|
421
|
+
if (cancelled) return;
|
|
422
|
+
setCall(row);
|
|
423
|
+
if (!liveUpdate.current) setState(browser.calls.recordingStateOfCall(row));
|
|
424
|
+
}).catch((err) => console.warn("[calls] could not read the recording state", err));
|
|
425
|
+
return () => {
|
|
426
|
+
cancelled = true;
|
|
427
|
+
};
|
|
428
|
+
}, [callExtId]);
|
|
429
|
+
react.useEffect(
|
|
430
|
+
() => chunkVPKFUYGW_cjs.onCallEvent("call.recording", (message) => {
|
|
431
|
+
if (message.call_ext_id === callExtId) applyState(message);
|
|
432
|
+
}),
|
|
433
|
+
[callExtId, applyState]
|
|
434
|
+
);
|
|
435
|
+
react.useEffect(() => {
|
|
436
|
+
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
437
|
+
if (topic !== chunkVPKFUYGW_cjs.CALL_RECORDING_TOPIC) return;
|
|
438
|
+
if (participant || participantIdentity) return;
|
|
439
|
+
try {
|
|
440
|
+
const next = browser.calls.recordingStateFrom(JSON.parse(new TextDecoder().decode(payload)));
|
|
441
|
+
if (next) applyState(next);
|
|
442
|
+
} catch {
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
room.on(livekitClient.RoomEvent.DataReceived, onData);
|
|
446
|
+
return () => {
|
|
447
|
+
room.off(livekitClient.RoomEvent.DataReceived, onData);
|
|
448
|
+
};
|
|
449
|
+
}, [room, applyState]);
|
|
450
|
+
const canControl = available && (isCreator || !!call && call.creator_ext_id === myIdentity);
|
|
451
|
+
const on = !!state?.on;
|
|
452
|
+
const start = react.useCallback(
|
|
453
|
+
async (mode) => {
|
|
454
|
+
setBusy(true);
|
|
455
|
+
try {
|
|
456
|
+
const row = call ?? await arbi.calls.get(callExtId);
|
|
457
|
+
if (!row.workspace_locked && !row.chat_ext_id && callKey) {
|
|
458
|
+
const ref = await chunkVPKFUYGW_cjs.ensureMeetingChat(arbi, queryClient, callExtId, callKey);
|
|
459
|
+
if (ref.kind === "chat") setCall({ ...row, chat_ext_id: ref.chatExtId });
|
|
460
|
+
}
|
|
461
|
+
const answer = await arbi.calls.recording.start(callExtId, mode);
|
|
462
|
+
if (answer) applyState(answer);
|
|
463
|
+
} catch (err) {
|
|
464
|
+
chunkVAMPYLQ4_cjs.notify.error(`Could not start recording: ${err.message}`);
|
|
465
|
+
} finally {
|
|
466
|
+
setBusy(false);
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
[callExtId, callKey, call, applyState]
|
|
470
|
+
);
|
|
471
|
+
const requestStart = react.useCallback(
|
|
472
|
+
async (mode) => {
|
|
473
|
+
if (!canControl || on) return;
|
|
474
|
+
setBusy(true);
|
|
475
|
+
let quota = null;
|
|
476
|
+
try {
|
|
477
|
+
quota = await arbi.calls.recording.quota(callExtId);
|
|
478
|
+
} catch (err) {
|
|
479
|
+
console.warn("[calls] could not read the recording quota", err);
|
|
480
|
+
}
|
|
481
|
+
setBusy(false);
|
|
482
|
+
if (quota && browser.calls.quotaNeedsWarning(quota)) {
|
|
483
|
+
setPendingStart({ mode, quota });
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
await start(mode);
|
|
487
|
+
},
|
|
488
|
+
[canControl, on, callExtId, start]
|
|
489
|
+
);
|
|
490
|
+
const confirmStart = react.useCallback(async () => {
|
|
491
|
+
const pending = pendingStart;
|
|
492
|
+
setPendingStart(null);
|
|
493
|
+
if (pending) await start(pending.mode);
|
|
494
|
+
}, [pendingStart, start]);
|
|
495
|
+
const cancelStart = react.useCallback(() => setPendingStart(null), []);
|
|
496
|
+
const stop = react.useCallback(async () => {
|
|
497
|
+
if (!canControl || !on) return;
|
|
498
|
+
setBusy(true);
|
|
499
|
+
try {
|
|
500
|
+
const answer = await arbi.calls.recording.stop(callExtId);
|
|
501
|
+
applyState(answer ?? { ...state, on: false });
|
|
502
|
+
} catch (err) {
|
|
503
|
+
chunkVAMPYLQ4_cjs.notify.error(`Could not stop recording: ${err.message}`);
|
|
504
|
+
} finally {
|
|
505
|
+
setBusy(false);
|
|
506
|
+
}
|
|
507
|
+
}, [canControl, on, callExtId, state, applyState]);
|
|
508
|
+
const markStopped = react.useCallback(() => {
|
|
509
|
+
const prev = stateRef.current;
|
|
510
|
+
if (prev?.on) applyState({ ...prev, on: false, reason: "storage_quota_exceeded" });
|
|
511
|
+
}, [applyState]);
|
|
512
|
+
const shouldCapture = captureAllowed({ available, state, indicatorShown });
|
|
513
|
+
return react.useMemo(
|
|
514
|
+
() => ({
|
|
515
|
+
available,
|
|
516
|
+
on,
|
|
517
|
+
mode: on ? state?.mode ?? "audio" : null,
|
|
518
|
+
recordingExtId: state?.recording_ext_id ?? null,
|
|
519
|
+
startedAt: state?.started_at ?? null,
|
|
520
|
+
startedByName: on ? state?.by_name ?? null : null,
|
|
521
|
+
startedByMe: on && state?.by_identity === myIdentity,
|
|
522
|
+
canControl,
|
|
523
|
+
busy,
|
|
524
|
+
call,
|
|
525
|
+
linkVersion,
|
|
526
|
+
requestStart,
|
|
527
|
+
pendingStart,
|
|
528
|
+
confirmStart,
|
|
529
|
+
cancelStart,
|
|
530
|
+
stop,
|
|
531
|
+
setIndicatorShown,
|
|
532
|
+
shouldCapture,
|
|
533
|
+
markStopped
|
|
534
|
+
}),
|
|
535
|
+
[
|
|
536
|
+
available,
|
|
537
|
+
on,
|
|
538
|
+
state,
|
|
539
|
+
myIdentity,
|
|
540
|
+
canControl,
|
|
541
|
+
busy,
|
|
542
|
+
call,
|
|
543
|
+
linkVersion,
|
|
544
|
+
requestStart,
|
|
545
|
+
pendingStart,
|
|
546
|
+
confirmStart,
|
|
547
|
+
cancelStart,
|
|
548
|
+
stop,
|
|
549
|
+
shouldCapture,
|
|
550
|
+
markStopped
|
|
551
|
+
]
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
function useTrackUploader(recording, callKey, kind, mimeType) {
|
|
555
|
+
const { recordingExtId, call, startedAt, shouldCapture, markStopped, linkVersion } = recording;
|
|
556
|
+
const arbi = chunkQQ7SCJRY_cjs.useArbi();
|
|
557
|
+
const queryClient = reactQuery.useQueryClient();
|
|
558
|
+
return react.useMemo(() => {
|
|
559
|
+
if (!shouldCapture || !recordingExtId || !call) return null;
|
|
560
|
+
return chunkVPKFUYGW_cjs.trackUploaderFor({
|
|
561
|
+
arbi,
|
|
562
|
+
callExtId: call.external_id,
|
|
563
|
+
recordingExtId,
|
|
564
|
+
kind,
|
|
565
|
+
mimeType,
|
|
566
|
+
recordingStartedAt: startedAt,
|
|
567
|
+
linkVersion,
|
|
568
|
+
conversationKey: () => chunkVPKFUYGW_cjs.conversationKeyForCall(arbi, queryClient, call, { callKey }),
|
|
569
|
+
// The server stopped the recording at the quota (its state event says so too).
|
|
570
|
+
onStopped: () => markStopped()
|
|
571
|
+
});
|
|
572
|
+
}, [
|
|
573
|
+
arbi,
|
|
574
|
+
queryClient,
|
|
575
|
+
shouldCapture,
|
|
576
|
+
recordingExtId,
|
|
577
|
+
call,
|
|
578
|
+
startedAt,
|
|
579
|
+
linkVersion,
|
|
580
|
+
kind,
|
|
581
|
+
mimeType,
|
|
582
|
+
callKey,
|
|
583
|
+
markStopped
|
|
584
|
+
]);
|
|
585
|
+
}
|
|
586
|
+
function useInCallChat({
|
|
587
|
+
callExtId,
|
|
588
|
+
callKey,
|
|
589
|
+
open,
|
|
590
|
+
readOnly = false,
|
|
591
|
+
persist = true
|
|
592
|
+
}) {
|
|
593
|
+
const room = componentsReact.useRoomContext();
|
|
594
|
+
const { localParticipant } = componentsReact.useLocalParticipant();
|
|
595
|
+
const myIdentity = localParticipant.identity;
|
|
596
|
+
const arbi = chunkQQ7SCJRY_cjs.useArbi();
|
|
597
|
+
const queryClient = reactQuery.useQueryClient();
|
|
598
|
+
const openMeetingChat = chunkQQ7SCJRY_cjs.useArbiHost().calls?.openMeetingChat;
|
|
599
|
+
const signedIn = arbi.isLoggedIn;
|
|
600
|
+
const persists = !!callKey && signedIn && !readOnly && persist;
|
|
601
|
+
const [live, setLive] = react.useState([]);
|
|
602
|
+
const [history, setHistory] = react.useState([]);
|
|
603
|
+
const [historyLoading, setHistoryLoading] = react.useState(false);
|
|
604
|
+
const [historyError, setHistoryError] = react.useState(null);
|
|
605
|
+
const [meetingChat, setMeetingChat] = react.useState(null);
|
|
606
|
+
const [unread, setUnread] = react.useState(0);
|
|
607
|
+
const openRef = react.useRef(open);
|
|
608
|
+
openRef.current = open;
|
|
609
|
+
const historyRequested = react.useRef(false);
|
|
610
|
+
const seen = react.useRef(/* @__PURE__ */ new Set());
|
|
611
|
+
react.useEffect(() => {
|
|
612
|
+
if (open) setUnread(0);
|
|
613
|
+
}, [open]);
|
|
614
|
+
react.useEffect(() => {
|
|
615
|
+
if (!callKey) return;
|
|
616
|
+
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
617
|
+
if (topic !== chunkVPKFUYGW_cjs.CALL_CHAT_TOPIC) return;
|
|
618
|
+
const identity = participant?.identity ?? participantIdentity;
|
|
619
|
+
if (!identity || identity === myIdentity) return;
|
|
620
|
+
void chunkVPKFUYGW_cjs.decodeCallChatPacket(payload, callKey).then((packet) => {
|
|
621
|
+
if (!packet) return;
|
|
622
|
+
const key = `${identity}:${packet.id}`;
|
|
623
|
+
if (seen.current.has(key)) return;
|
|
624
|
+
seen.current.add(key);
|
|
625
|
+
setLive((prev) => [
|
|
626
|
+
...prev,
|
|
627
|
+
{
|
|
628
|
+
id: packet.id,
|
|
629
|
+
senderIdentity: identity,
|
|
630
|
+
senderName: participant?.name || identity,
|
|
631
|
+
text: packet.text,
|
|
632
|
+
at: Math.min(packet.at, Date.now()),
|
|
633
|
+
mine: false,
|
|
634
|
+
status: "live"
|
|
635
|
+
}
|
|
636
|
+
]);
|
|
637
|
+
if (!openRef.current) setUnread((n) => n + 1);
|
|
638
|
+
});
|
|
639
|
+
};
|
|
640
|
+
room.on(livekitClient.RoomEvent.DataReceived, onData);
|
|
641
|
+
return () => {
|
|
642
|
+
room.off(livekitClient.RoomEvent.DataReceived, onData);
|
|
643
|
+
};
|
|
644
|
+
}, [room, callKey, myIdentity]);
|
|
645
|
+
const canRead = !!callKey && signedIn && persist;
|
|
646
|
+
react.useEffect(() => {
|
|
647
|
+
if (!open || !canRead || historyRequested.current) return;
|
|
648
|
+
historyRequested.current = true;
|
|
649
|
+
setHistoryLoading(true);
|
|
650
|
+
chunkVPKFUYGW_cjs.loadMeetingHistory(arbi, queryClient, callExtId).then((result) => {
|
|
651
|
+
if (!result) return;
|
|
652
|
+
setMeetingChat(result.ref);
|
|
653
|
+
setHistory(result.messages);
|
|
654
|
+
}).catch((err) => {
|
|
655
|
+
console.warn("[calls] could not load the meeting chat", err);
|
|
656
|
+
setHistoryError("Earlier messages could not be loaded.");
|
|
657
|
+
}).finally(() => setHistoryLoading(false));
|
|
658
|
+
}, [open, canRead, callExtId]);
|
|
659
|
+
const send = react.useCallback(
|
|
660
|
+
async (raw) => {
|
|
661
|
+
const text = raw.trim().slice(0, chunkVPKFUYGW_cjs.CALL_CHAT_MAX_CHARS);
|
|
662
|
+
if (!text || !callKey || readOnly) return;
|
|
663
|
+
const id = chunkVPKFUYGW_cjs.newPacketId();
|
|
664
|
+
const at = Date.now();
|
|
665
|
+
await localParticipant.publishData(
|
|
666
|
+
await chunkVPKFUYGW_cjs.encodeCallChatPacket({ v: 1, id, text, at }, callKey),
|
|
667
|
+
{ reliable: true, topic: chunkVPKFUYGW_cjs.CALL_CHAT_TOPIC }
|
|
668
|
+
);
|
|
669
|
+
setLive((prev) => [
|
|
670
|
+
...prev,
|
|
671
|
+
{
|
|
672
|
+
id,
|
|
673
|
+
senderIdentity: myIdentity,
|
|
674
|
+
senderName: localParticipant.name || "You",
|
|
675
|
+
text,
|
|
676
|
+
at,
|
|
677
|
+
mine: true,
|
|
678
|
+
status: persists ? "saving" : "live"
|
|
679
|
+
}
|
|
680
|
+
]);
|
|
681
|
+
if (!persists) return;
|
|
682
|
+
const mark = (status) => setLive(
|
|
683
|
+
(prev) => prev.map((l) => l.id === id && l.senderIdentity === myIdentity ? { ...l, status } : l)
|
|
684
|
+
);
|
|
685
|
+
try {
|
|
686
|
+
setMeetingChat(await chunkVPKFUYGW_cjs.persistMeetingMessage(arbi, queryClient, callExtId, callKey, text));
|
|
687
|
+
mark("saved");
|
|
688
|
+
} catch (err) {
|
|
689
|
+
console.warn("[calls] could not keep the message in the meeting chat", err);
|
|
690
|
+
mark("unsaved");
|
|
691
|
+
}
|
|
692
|
+
},
|
|
693
|
+
[callKey, callExtId, localParticipant, myIdentity, persists, readOnly]
|
|
694
|
+
);
|
|
695
|
+
const openMeeting = react.useCallback(async () => {
|
|
696
|
+
if (!callKey) return;
|
|
697
|
+
try {
|
|
698
|
+
const ref = meetingChat ?? await chunkVPKFUYGW_cjs.ensureMeetingChat(arbi, queryClient, callExtId, callKey);
|
|
699
|
+
setMeetingChat(ref);
|
|
700
|
+
openMeetingChat?.(ref);
|
|
701
|
+
} catch (err) {
|
|
702
|
+
chunkVAMPYLQ4_cjs.notify.error(`Could not open the meeting chat: ${err.message}`);
|
|
703
|
+
}
|
|
704
|
+
}, [callExtId, callKey, meetingChat]);
|
|
705
|
+
const lines = react.useMemo(
|
|
706
|
+
() => chunkVPKFUYGW_cjs.mergeChatLines(history, live, {
|
|
707
|
+
myIdentity,
|
|
708
|
+
nameOf: (identity) => identity === myIdentity ? localParticipant.name || "You" : room.remoteParticipants.get(identity)?.name || null
|
|
709
|
+
}),
|
|
710
|
+
[history, live, myIdentity, localParticipant, room]
|
|
711
|
+
);
|
|
712
|
+
return {
|
|
713
|
+
lines,
|
|
714
|
+
unread,
|
|
715
|
+
available: !!callKey,
|
|
716
|
+
persists,
|
|
717
|
+
readOnly,
|
|
718
|
+
historyLoading,
|
|
719
|
+
historyError,
|
|
720
|
+
meetingChat,
|
|
721
|
+
send,
|
|
722
|
+
openMeeting
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
var DEMOTE_REJOIN_FALLBACK_MS = 5e3;
|
|
726
|
+
function failed(what) {
|
|
727
|
+
return (err) => {
|
|
728
|
+
chunkVAMPYLQ4_cjs.notify.error(`Could not ${what}: ${err?.message ?? "unknown error"}`);
|
|
729
|
+
throw err;
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
function useWebinar({
|
|
733
|
+
role: roleHint = null,
|
|
734
|
+
callExtId,
|
|
735
|
+
linkVersion = null,
|
|
736
|
+
callKey
|
|
737
|
+
}) {
|
|
738
|
+
const arbi = chunkQQ7SCJRY_cjs.useArbi();
|
|
739
|
+
const webinarApi = react.useCallback(() => arbi.calls.webinar, [arbi]);
|
|
740
|
+
const enabled = !!roleHint;
|
|
741
|
+
const room = componentsReact.useRoomContext();
|
|
742
|
+
const { localParticipant } = componentsReact.useLocalParticipant();
|
|
743
|
+
const myIdentity = localParticipant.identity;
|
|
744
|
+
const permissions = componentsReact.useLocalParticipantPermissions();
|
|
745
|
+
const [state, setState] = react.useState(null);
|
|
746
|
+
const [questions, setQuestions] = react.useState([]);
|
|
747
|
+
const [stageCheck, setStageCheck] = react.useState(false);
|
|
748
|
+
const stateRead = react.useRef(0);
|
|
749
|
+
const questionsRead = react.useRef(0);
|
|
750
|
+
const refresh = react.useCallback(async () => {
|
|
751
|
+
if (!enabled) return;
|
|
752
|
+
const n = ++stateRead.current;
|
|
753
|
+
try {
|
|
754
|
+
const next = await webinarApi().get(callExtId, linkVersion);
|
|
755
|
+
if (n === stateRead.current) setState(next);
|
|
756
|
+
} catch (err) {
|
|
757
|
+
console.warn("[calls] could not read the webinar state", err);
|
|
758
|
+
}
|
|
759
|
+
}, [enabled, callExtId, linkVersion]);
|
|
760
|
+
const refreshQuestions = react.useCallback(async () => {
|
|
761
|
+
if (!enabled || !callKey) return;
|
|
762
|
+
const n = ++questionsRead.current;
|
|
763
|
+
try {
|
|
764
|
+
const rows = await webinarApi().questions.list(callExtId, linkVersion);
|
|
765
|
+
const opened = await Promise.all(rows.map((q) => chunkVPKFUYGW_cjs.openQuestion(q, callKey)));
|
|
766
|
+
if (n === questionsRead.current) setQuestions(opened);
|
|
767
|
+
} catch (err) {
|
|
768
|
+
console.warn("[calls] could not load the questions", err);
|
|
769
|
+
}
|
|
770
|
+
}, [enabled, callExtId, linkVersion, callKey]);
|
|
771
|
+
react.useEffect(() => {
|
|
772
|
+
void refresh();
|
|
773
|
+
void refreshQuestions();
|
|
774
|
+
}, [refresh, refreshQuestions]);
|
|
775
|
+
react.useEffect(() => {
|
|
776
|
+
if (!enabled) return;
|
|
777
|
+
return chunkVPKFUYGW_cjs.onCallEvent("call.webinar", (m) => {
|
|
778
|
+
if (m.call_ext_id !== callExtId) return;
|
|
779
|
+
setState((s) => s ? { ...s, live: m.live, chat: m.chat } : s);
|
|
780
|
+
});
|
|
781
|
+
}, [enabled, callExtId]);
|
|
782
|
+
const fallback = react.useRef(null);
|
|
783
|
+
react.useEffect(() => {
|
|
784
|
+
if (!enabled) return;
|
|
785
|
+
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
786
|
+
if (topic !== chunkVPKFUYGW_cjs.CALL_WEBINAR_TOPIC) return;
|
|
787
|
+
const packet = chunkVPKFUYGW_cjs.parseWebinarPacket(payload, !!(participant || participantIdentity));
|
|
788
|
+
if (!packet) return;
|
|
789
|
+
switch (packet.type) {
|
|
790
|
+
case "state":
|
|
791
|
+
setState(
|
|
792
|
+
(s) => s ? { ...s, live: packet.live, live_at: packet.live_at, chat: packet.chat } : s
|
|
793
|
+
);
|
|
794
|
+
void refresh();
|
|
795
|
+
return;
|
|
796
|
+
case "hands":
|
|
797
|
+
setState((s) => s ? { ...s, hands: packet.hands } : s);
|
|
798
|
+
return;
|
|
799
|
+
case "questions":
|
|
800
|
+
void refreshQuestions();
|
|
801
|
+
return;
|
|
802
|
+
case "promoted":
|
|
803
|
+
setStageCheck(true);
|
|
804
|
+
void refresh();
|
|
805
|
+
return;
|
|
806
|
+
case "demoted":
|
|
807
|
+
setStageCheck(false);
|
|
808
|
+
chunkVPKFUYGW_cjs.markRejoining(callExtId);
|
|
809
|
+
if (fallback.current) clearTimeout(fallback.current);
|
|
810
|
+
fallback.current = setTimeout(() => void room.disconnect(), DEMOTE_REJOIN_FALLBACK_MS);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
room.on(livekitClient.RoomEvent.DataReceived, onData);
|
|
815
|
+
return () => {
|
|
816
|
+
room.off(livekitClient.RoomEvent.DataReceived, onData);
|
|
817
|
+
};
|
|
818
|
+
}, [enabled, room, callExtId, refresh, refreshQuestions]);
|
|
819
|
+
react.useEffect(
|
|
820
|
+
() => () => {
|
|
821
|
+
if (fallback.current) clearTimeout(fallback.current);
|
|
822
|
+
},
|
|
823
|
+
[]
|
|
824
|
+
);
|
|
825
|
+
const role = enabled ? state?.my_role ?? null : null;
|
|
826
|
+
const onStage = !enabled || (permissions ? permissions.canPublish : state ? state.on_stage : roleHint !== "attendee");
|
|
827
|
+
const patch = react.useCallback(
|
|
828
|
+
async (body, what) => {
|
|
829
|
+
const next = await webinarApi().update(callExtId, body, linkVersion).catch(failed(what));
|
|
830
|
+
setState(next);
|
|
831
|
+
},
|
|
832
|
+
[callExtId, linkVersion]
|
|
833
|
+
);
|
|
834
|
+
const stepDown = react.useCallback(async () => {
|
|
835
|
+
chunkVPKFUYGW_cjs.markRejoining(callExtId);
|
|
836
|
+
setStageCheck(false);
|
|
837
|
+
try {
|
|
838
|
+
await webinarApi().demote(callExtId, myIdentity, linkVersion);
|
|
839
|
+
} catch (err) {
|
|
840
|
+
chunkVPKFUYGW_cjs.markRejoining(callExtId, false);
|
|
841
|
+
failed("leave the stage")(err);
|
|
842
|
+
}
|
|
843
|
+
}, [callExtId, myIdentity, linkVersion]);
|
|
844
|
+
const joinStage = react.useCallback(
|
|
845
|
+
async (choices) => {
|
|
846
|
+
const lp = room.localParticipant;
|
|
847
|
+
try {
|
|
848
|
+
await lp.setMicrophoneEnabled(
|
|
849
|
+
choices.audioEnabled,
|
|
850
|
+
choices.audioDeviceId ? { deviceId: choices.audioDeviceId } : void 0
|
|
851
|
+
);
|
|
852
|
+
await lp.setCameraEnabled(
|
|
853
|
+
choices.videoEnabled,
|
|
854
|
+
choices.videoDeviceId ? { deviceId: choices.videoDeviceId } : void 0
|
|
855
|
+
);
|
|
856
|
+
} catch (err) {
|
|
857
|
+
failed("turn on your microphone or camera")(err);
|
|
858
|
+
}
|
|
859
|
+
setStageCheck(false);
|
|
860
|
+
},
|
|
861
|
+
[room]
|
|
862
|
+
);
|
|
863
|
+
const questionAction = react.useCallback(
|
|
864
|
+
async (run, what) => {
|
|
865
|
+
await run().catch(failed(what));
|
|
866
|
+
void refreshQuestions();
|
|
867
|
+
},
|
|
868
|
+
[refreshQuestions]
|
|
869
|
+
);
|
|
870
|
+
return react.useMemo(
|
|
871
|
+
() => ({
|
|
872
|
+
enabled,
|
|
873
|
+
role,
|
|
874
|
+
moderator: !!role && browser.calls.WEBINAR_MODERATORS.has(role),
|
|
875
|
+
team: !!role && browser.calls.WEBINAR_TEAM.has(role),
|
|
876
|
+
live: !!state?.live,
|
|
877
|
+
chat: state?.chat ?? "panelists",
|
|
878
|
+
onStage,
|
|
879
|
+
handRaised: !!state?.hand_raised,
|
|
880
|
+
hands: state?.hands ?? [],
|
|
881
|
+
attendees: state?.attendees ?? [],
|
|
882
|
+
questions,
|
|
883
|
+
stageCheck: enabled && stageCheck,
|
|
884
|
+
refresh,
|
|
885
|
+
goLive: () => patch({ live: true }, "go live"),
|
|
886
|
+
end: () => patch({ live: false }, "end the webinar"),
|
|
887
|
+
setChat: (chat) => patch({ chat }, "change who can chat"),
|
|
888
|
+
setHand: async (raised) => {
|
|
889
|
+
const next = await webinarApi().setHand(callExtId, raised, linkVersion).catch(failed(raised ? "raise your hand" : "lower your hand"));
|
|
890
|
+
setState(next);
|
|
891
|
+
},
|
|
892
|
+
promote: (identity) => webinarApi().promote(callExtId, identity, linkVersion).catch(failed("bring them on stage")).then(refresh),
|
|
893
|
+
demote: (identity) => webinarApi().demote(callExtId, identity, linkVersion).catch(failed("move them to the audience")).then(refresh),
|
|
894
|
+
stepDown,
|
|
895
|
+
joinStage,
|
|
896
|
+
ask: (text) => questionAction(async () => {
|
|
897
|
+
if (!callKey) throw new Error("This call has no key.");
|
|
898
|
+
await webinarApi().questions.ask(
|
|
899
|
+
callExtId,
|
|
900
|
+
await chunkVPKFUYGW_cjs.sealQuestionText(text, callKey),
|
|
901
|
+
linkVersion
|
|
902
|
+
);
|
|
903
|
+
}, "ask the question"),
|
|
904
|
+
vote: (id, up) => questionAction(() => webinarApi().questions.vote(callExtId, id, up, linkVersion), "vote"),
|
|
905
|
+
setQuestionStatus: (id, status) => questionAction(
|
|
906
|
+
() => webinarApi().questions.update(callExtId, id, { status }, linkVersion),
|
|
907
|
+
"update the question"
|
|
908
|
+
),
|
|
909
|
+
answer: (id, text) => questionAction(async () => {
|
|
910
|
+
if (!callKey) throw new Error("This call has no key.");
|
|
911
|
+
await webinarApi().questions.update(
|
|
912
|
+
callExtId,
|
|
913
|
+
id,
|
|
914
|
+
{ answer: await chunkVPKFUYGW_cjs.sealQuestionText(text, callKey) },
|
|
915
|
+
linkVersion
|
|
916
|
+
);
|
|
917
|
+
}, "answer the question"),
|
|
918
|
+
removeQuestion: (id) => questionAction(
|
|
919
|
+
() => webinarApi().questions.delete(callExtId, id, linkVersion),
|
|
920
|
+
"delete the question"
|
|
921
|
+
)
|
|
922
|
+
}),
|
|
923
|
+
[
|
|
924
|
+
enabled,
|
|
925
|
+
role,
|
|
926
|
+
state,
|
|
927
|
+
onStage,
|
|
928
|
+
questions,
|
|
929
|
+
stageCheck,
|
|
930
|
+
refresh,
|
|
931
|
+
patch,
|
|
932
|
+
callExtId,
|
|
933
|
+
linkVersion,
|
|
934
|
+
callKey,
|
|
935
|
+
stepDown,
|
|
936
|
+
joinStage,
|
|
937
|
+
questionAction
|
|
938
|
+
]
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
function useHostMuteNotice(callExtId) {
|
|
942
|
+
const room = componentsReact.useRoomContext();
|
|
943
|
+
react.useEffect(() => {
|
|
944
|
+
const notifyMuted = chunkVPKFUYGW_cjs.createMutedNotifier((text) => chunkVAMPYLQ4_cjs.notify.info(text));
|
|
945
|
+
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
946
|
+
if (topic !== chunkVPKFUYGW_cjs.CALL_MODERATION_TOPIC) return;
|
|
947
|
+
if (participant || participantIdentity) return;
|
|
948
|
+
const notice = chunkVPKFUYGW_cjs.mutedNoticeFromPacket(payload);
|
|
949
|
+
if (notice) notifyMuted(notice);
|
|
950
|
+
};
|
|
951
|
+
room.on(livekitClient.RoomEvent.DataReceived, onData);
|
|
952
|
+
const offWs = chunkVPKFUYGW_cjs.onCallEvent("call.muted", (message) => {
|
|
953
|
+
if (message.callExtId === callExtId) notifyMuted(message);
|
|
954
|
+
});
|
|
955
|
+
return () => {
|
|
956
|
+
room.off(livekitClient.RoomEvent.DataReceived, onData);
|
|
957
|
+
offWs();
|
|
958
|
+
};
|
|
959
|
+
}, [room, callExtId]);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
exports.DEMOTE_REJOIN_FALLBACK_MS = DEMOTE_REJOIN_FALLBACK_MS;
|
|
963
|
+
exports.FINAL_SEGMENT_GRACE_MS = FINAL_SEGMENT_GRACE_MS;
|
|
964
|
+
exports.captureAllowed = captureAllowed;
|
|
965
|
+
exports.createE2EEWorker = createE2EEWorker;
|
|
966
|
+
exports.mayStillSend = mayStillSend;
|
|
967
|
+
exports.storedSpeakerName = storedSpeakerName;
|
|
968
|
+
exports.useCallRecorder = useCallRecorder;
|
|
969
|
+
exports.useCallRoom = useCallRoom;
|
|
970
|
+
exports.useCallTranscriber = useCallTranscriber;
|
|
971
|
+
exports.useHostMuteNotice = useHostMuteNotice;
|
|
972
|
+
exports.useInCallChat = useInCallChat;
|
|
973
|
+
exports.useMuteRequests = useMuteRequests;
|
|
974
|
+
exports.useTrackUploader = useTrackUploader;
|
|
975
|
+
exports.useWebinar = useWebinar;
|
|
976
|
+
//# sourceMappingURL=index.cjs.map
|
|
977
|
+
//# sourceMappingURL=index.cjs.map
|