@poolse/react 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +5 -1
- package/dist/index.cjs +573 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +187 -3
- package/dist/index.d.ts +187 -3
- package/dist/index.js +518 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1768,6 +1768,7 @@ function useCallRoom(conversationId, opts) {
|
|
|
1768
1768
|
const [activeDevices, setActiveDevices] = react.useState({});
|
|
1769
1769
|
const [error, setError] = react.useState(null);
|
|
1770
1770
|
const [sfuAvailable, setSfuAvailable] = react.useState(null);
|
|
1771
|
+
const [canPublish, setCanPublish] = react.useState(true);
|
|
1771
1772
|
const optsRef = react.useRef(opts);
|
|
1772
1773
|
optsRef.current = opts;
|
|
1773
1774
|
const joined = react.useRef(false);
|
|
@@ -1779,7 +1780,8 @@ function useCallRoom(conversationId, opts) {
|
|
|
1779
1780
|
...optsRef.current.video !== void 0 ? { video: optsRef.current.video } : {},
|
|
1780
1781
|
...optsRef.current.muted !== void 0 ? { muted: optsRef.current.muted } : {},
|
|
1781
1782
|
...optsRef.current.facing !== void 0 ? { facing: optsRef.current.facing } : {},
|
|
1782
|
-
...optsRef.current.aloneGraceMs !== void 0 ? { aloneGraceMs: optsRef.current.aloneGraceMs } : {}
|
|
1783
|
+
...optsRef.current.aloneGraceMs !== void 0 ? { aloneGraceMs: optsRef.current.aloneGraceMs } : {},
|
|
1784
|
+
...optsRef.current.republishOnPermission !== void 0 ? { republishOnPermission: optsRef.current.republishOnPermission } : {}
|
|
1783
1785
|
});
|
|
1784
1786
|
}, [poolse, conversationId]);
|
|
1785
1787
|
const refreshDevices = react.useCallback((target) => {
|
|
@@ -1804,6 +1806,7 @@ function useCallRoom(conversationId, opts) {
|
|
|
1804
1806
|
setScreen(target.isScreenShareEnabled());
|
|
1805
1807
|
setCanShare(target.canShareScreen());
|
|
1806
1808
|
setFacing(target.getFacingMode());
|
|
1809
|
+
setCanPublish(target.canPublish());
|
|
1807
1810
|
}, []);
|
|
1808
1811
|
react.useEffect(() => {
|
|
1809
1812
|
if (!room) {
|
|
@@ -1823,12 +1826,14 @@ function useCallRoom(conversationId, opts) {
|
|
|
1823
1826
|
const offAlone = room.onAlone(() => setAlone(true));
|
|
1824
1827
|
const offDevices = room.onDevices(() => refreshDevices(room));
|
|
1825
1828
|
const offError = room.onError(setError);
|
|
1829
|
+
const offPublish = room.onPublishPermission(() => sync(room));
|
|
1826
1830
|
return () => {
|
|
1827
1831
|
offStatus();
|
|
1828
1832
|
offRoster();
|
|
1829
1833
|
offAlone();
|
|
1830
1834
|
offDevices();
|
|
1831
1835
|
offError();
|
|
1836
|
+
offPublish();
|
|
1832
1837
|
held.current = null;
|
|
1833
1838
|
if (joined.current) {
|
|
1834
1839
|
joined.current = false;
|
|
@@ -1921,6 +1926,11 @@ function useCallRoom(conversationId, opts) {
|
|
|
1921
1926
|
},
|
|
1922
1927
|
[room]
|
|
1923
1928
|
);
|
|
1929
|
+
const republish = react.useCallback(async () => {
|
|
1930
|
+
if (!room) return;
|
|
1931
|
+
await room.republish();
|
|
1932
|
+
sync(room);
|
|
1933
|
+
}, [room, sync]);
|
|
1924
1934
|
return {
|
|
1925
1935
|
status,
|
|
1926
1936
|
participants,
|
|
@@ -1945,9 +1955,110 @@ function useCallRoom(conversationId, opts) {
|
|
|
1945
1955
|
setMicrophoneEnabled,
|
|
1946
1956
|
toggleMic,
|
|
1947
1957
|
setScreenShareEnabled,
|
|
1948
|
-
toggleScreenShare
|
|
1958
|
+
toggleScreenShare,
|
|
1959
|
+
canPublish,
|
|
1960
|
+
republish
|
|
1949
1961
|
};
|
|
1950
1962
|
}
|
|
1963
|
+
var IDLE_RECORDING = {
|
|
1964
|
+
available: true,
|
|
1965
|
+
active: false,
|
|
1966
|
+
id: null,
|
|
1967
|
+
mode: null,
|
|
1968
|
+
started_at: null,
|
|
1969
|
+
started_by_user_id: null,
|
|
1970
|
+
auto: false,
|
|
1971
|
+
consent_required: false,
|
|
1972
|
+
consent: { accepted: [], declined: [] }
|
|
1973
|
+
};
|
|
1974
|
+
var without = (list, id) => list.filter((x) => x !== id);
|
|
1975
|
+
function applyCaptureEvent(state, e) {
|
|
1976
|
+
const rec = state.recording ?? IDLE_RECORDING;
|
|
1977
|
+
switch (e.type) {
|
|
1978
|
+
case "recording:started": {
|
|
1979
|
+
const r = e.evt.recording;
|
|
1980
|
+
const starter = r.started_by_user_id;
|
|
1981
|
+
return {
|
|
1982
|
+
...state,
|
|
1983
|
+
recording: {
|
|
1984
|
+
...rec,
|
|
1985
|
+
active: true,
|
|
1986
|
+
id: r.id,
|
|
1987
|
+
mode: r.mode,
|
|
1988
|
+
started_at: r.started_at,
|
|
1989
|
+
started_by_user_id: starter,
|
|
1990
|
+
auto: r.auto,
|
|
1991
|
+
consent_required: e.evt.consent_required,
|
|
1992
|
+
// Starting is accepting.
|
|
1993
|
+
consent: starter ? {
|
|
1994
|
+
accepted: [...without(rec.consent.accepted, starter), starter],
|
|
1995
|
+
declined: without(rec.consent.declined, starter)
|
|
1996
|
+
} : rec.consent
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
case "recording:stopped":
|
|
2001
|
+
case "recording:ready":
|
|
2002
|
+
if (rec.id !== null && rec.id !== e.evt.recording.id) return state;
|
|
2003
|
+
return {
|
|
2004
|
+
...state,
|
|
2005
|
+
recording: { ...rec, active: false, id: null, mode: null, consent_required: false }
|
|
2006
|
+
};
|
|
2007
|
+
case "recording:consent": {
|
|
2008
|
+
const { user_id: who, decision } = e.evt;
|
|
2009
|
+
const accepted = without(rec.consent.accepted, who);
|
|
2010
|
+
const declined = without(rec.consent.declined, who);
|
|
2011
|
+
(decision === "accepted" ? accepted : declined).push(who);
|
|
2012
|
+
return { ...state, recording: { ...rec, consent: { accepted, declined } } };
|
|
2013
|
+
}
|
|
2014
|
+
case "transcript:changed": {
|
|
2015
|
+
const t = e.evt.transcript;
|
|
2016
|
+
return {
|
|
2017
|
+
...state,
|
|
2018
|
+
transcription: {
|
|
2019
|
+
available: state.transcription?.available ?? true,
|
|
2020
|
+
active: t.status === "live",
|
|
2021
|
+
id: t.id,
|
|
2022
|
+
status: t.status,
|
|
2023
|
+
language: t.language
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
function subscribeCapture(chat, conversationId, callId, fn) {
|
|
2030
|
+
const conv = chat.realtime.conversation(conversationId);
|
|
2031
|
+
const mine = (id) => callId === null || id === callId;
|
|
2032
|
+
const offs = [
|
|
2033
|
+
conv.onRecordingStarted((evt) => mine(evt.call_id) && fn({ type: "recording:started", evt })),
|
|
2034
|
+
conv.onRecordingStopped((evt) => mine(evt.call_id) && fn({ type: "recording:stopped", evt })),
|
|
2035
|
+
conv.onRecordingReady((evt) => mine(evt.call_id) && fn({ type: "recording:ready", evt })),
|
|
2036
|
+
conv.onRecordingConsent((evt) => mine(evt.call_id) && fn({ type: "recording:consent", evt })),
|
|
2037
|
+
conv.onTranscriptStarted((evt) => mine(evt.call_id) && fn({ type: "transcript:changed", evt })),
|
|
2038
|
+
conv.onTranscriptStopped((evt) => mine(evt.call_id) && fn({ type: "transcript:changed", evt })),
|
|
2039
|
+
conv.onTranscriptReady((evt) => mine(evt.call_id) && fn({ type: "transcript:changed", evt }))
|
|
2040
|
+
];
|
|
2041
|
+
return () => offs.forEach((off) => off());
|
|
2042
|
+
}
|
|
2043
|
+
function useMeId(chat) {
|
|
2044
|
+
const [id, setId] = react.useState(() => chat.me.peek()?.id ?? null);
|
|
2045
|
+
react.useEffect(() => {
|
|
2046
|
+
setId(chat.me.peek()?.id ?? null);
|
|
2047
|
+
return chat.me.onChange((me) => setId(me.id));
|
|
2048
|
+
}, [chat]);
|
|
2049
|
+
return id;
|
|
2050
|
+
}
|
|
2051
|
+
function onReconnect(chat, fn) {
|
|
2052
|
+
let wasConnected = chat.realtime.getStatus() === "connected";
|
|
2053
|
+
let connectedBefore = wasConnected;
|
|
2054
|
+
return chat.realtime.onStatus((status) => {
|
|
2055
|
+
if (status === "connected" && !wasConnected && connectedBefore) fn();
|
|
2056
|
+
wasConnected = status === "connected";
|
|
2057
|
+
connectedBefore ||= wasConnected;
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
// src/use-live-call.ts
|
|
1951
2062
|
function useLiveCall(conversationId) {
|
|
1952
2063
|
const chat = usePoolse();
|
|
1953
2064
|
const [call, setCall] = react.useState(null);
|
|
@@ -1980,6 +2091,21 @@ function useLiveCall(conversationId) {
|
|
|
1980
2091
|
if (evt.call_id === callIdRef.current) setParticipantIds(evt.participants);
|
|
1981
2092
|
else refresh();
|
|
1982
2093
|
});
|
|
2094
|
+
const offCapture = subscribeCapture(chat, conversationId, null, (e) => {
|
|
2095
|
+
if (e.evt.call_id !== callIdRef.current) return;
|
|
2096
|
+
setCall((c) => {
|
|
2097
|
+
if (!c) return c;
|
|
2098
|
+
const next = applyCaptureEvent(
|
|
2099
|
+
{ recording: c.recording ?? null, transcription: c.transcription ?? null },
|
|
2100
|
+
e
|
|
2101
|
+
);
|
|
2102
|
+
return {
|
|
2103
|
+
...c,
|
|
2104
|
+
...next.recording ? { recording: next.recording } : {},
|
|
2105
|
+
...next.transcription ? { transcription: next.transcription } : {}
|
|
2106
|
+
};
|
|
2107
|
+
});
|
|
2108
|
+
});
|
|
1983
2109
|
const offFinished = conv.onCallFinished((evt) => {
|
|
1984
2110
|
if (evt.call_id !== callIdRef.current) return;
|
|
1985
2111
|
seq.current++;
|
|
@@ -1996,6 +2122,7 @@ function useLiveCall(conversationId) {
|
|
|
1996
2122
|
offStarted();
|
|
1997
2123
|
offParticipants();
|
|
1998
2124
|
offFinished();
|
|
2125
|
+
offCapture();
|
|
1999
2126
|
offStatus();
|
|
2000
2127
|
};
|
|
2001
2128
|
}, [chat, conversationId, apply, refresh]);
|
|
@@ -2050,6 +2177,392 @@ function useRoom(conversationId, opts) {
|
|
|
2050
2177
|
error: error ?? media.error
|
|
2051
2178
|
};
|
|
2052
2179
|
}
|
|
2180
|
+
function useRecording(callId, conversationId, initial) {
|
|
2181
|
+
const chat = usePoolse();
|
|
2182
|
+
const meId = useMeId(chat);
|
|
2183
|
+
const [state, setState] = react.useState(
|
|
2184
|
+
() => initial && initial.id === callId ? { recording: initial.recording ?? null, transcription: initial.transcription ?? null } : { recording: null, transcription: null }
|
|
2185
|
+
);
|
|
2186
|
+
const [notice, setNotice] = react.useState(null);
|
|
2187
|
+
const [lastRecording, setLastRecording] = react.useState(null);
|
|
2188
|
+
const [pending, setPending] = react.useState(false);
|
|
2189
|
+
const [error, setError] = react.useState(null);
|
|
2190
|
+
const [transcriptConsent, setTranscriptConsent] = react.useState(false);
|
|
2191
|
+
const seq = react.useRef(0);
|
|
2192
|
+
const hasInitial = react.useRef(!!initial && initial.id === callId);
|
|
2193
|
+
const refresh = react.useCallback(() => {
|
|
2194
|
+
if (!callId || !conversationId) return;
|
|
2195
|
+
const mine = ++seq.current;
|
|
2196
|
+
chat.liveCalls.get(conversationId).then((c) => {
|
|
2197
|
+
if (mine !== seq.current) return;
|
|
2198
|
+
if (c && c.id === callId)
|
|
2199
|
+
setState({ recording: c.recording ?? null, transcription: c.transcription ?? null });
|
|
2200
|
+
else
|
|
2201
|
+
setState((s) => ({
|
|
2202
|
+
recording: s.recording ? { ...s.recording, active: false } : null,
|
|
2203
|
+
transcription: s.transcription ? { ...s.transcription, active: false } : null
|
|
2204
|
+
}));
|
|
2205
|
+
}).catch(() => {
|
|
2206
|
+
});
|
|
2207
|
+
}, [chat, callId, conversationId]);
|
|
2208
|
+
react.useEffect(() => {
|
|
2209
|
+
if (!callId || !conversationId) {
|
|
2210
|
+
setState({ recording: null, transcription: null });
|
|
2211
|
+
return;
|
|
2212
|
+
}
|
|
2213
|
+
if (hasInitial.current) hasInitial.current = false;
|
|
2214
|
+
else refresh();
|
|
2215
|
+
const offCapture = subscribeCapture(chat, conversationId, callId, (e) => {
|
|
2216
|
+
seq.current++;
|
|
2217
|
+
setState((s) => applyCaptureEvent(s, e));
|
|
2218
|
+
if (e.type === "recording:started") {
|
|
2219
|
+
setNotice(e.evt.notice);
|
|
2220
|
+
setLastRecording(e.evt.recording);
|
|
2221
|
+
} else if (e.type === "recording:stopped" || e.type === "recording:ready") {
|
|
2222
|
+
setLastRecording(e.evt.recording);
|
|
2223
|
+
}
|
|
2224
|
+
});
|
|
2225
|
+
const conv = chat.realtime.conversation(conversationId);
|
|
2226
|
+
const offFinished = conv.onCallFinished((evt) => {
|
|
2227
|
+
if (evt.call_id !== callId) return;
|
|
2228
|
+
seq.current++;
|
|
2229
|
+
setState((s) => ({
|
|
2230
|
+
recording: s.recording ? { ...s.recording, active: false } : null,
|
|
2231
|
+
transcription: s.transcription ? { ...s.transcription, active: false } : null
|
|
2232
|
+
}));
|
|
2233
|
+
});
|
|
2234
|
+
const offStatus = onReconnect(chat, refresh);
|
|
2235
|
+
return () => {
|
|
2236
|
+
offCapture();
|
|
2237
|
+
offFinished();
|
|
2238
|
+
offStatus();
|
|
2239
|
+
};
|
|
2240
|
+
}, [chat, callId, conversationId, refresh]);
|
|
2241
|
+
const transcribing = !!state.transcription?.active;
|
|
2242
|
+
react.useEffect(() => {
|
|
2243
|
+
if (!conversationId || !transcribing) {
|
|
2244
|
+
setTranscriptConsent(false);
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
let cancelled = false;
|
|
2248
|
+
chat.calls.recording.settings(conversationId).then((s) => {
|
|
2249
|
+
if (!cancelled) setTranscriptConsent(s.effective.consent === "required");
|
|
2250
|
+
}).catch(() => {
|
|
2251
|
+
});
|
|
2252
|
+
return () => {
|
|
2253
|
+
cancelled = true;
|
|
2254
|
+
};
|
|
2255
|
+
}, [chat, conversationId, transcribing]);
|
|
2256
|
+
const run = react.useCallback(async (fn) => {
|
|
2257
|
+
setPending(true);
|
|
2258
|
+
setError(null);
|
|
2259
|
+
try {
|
|
2260
|
+
await fn();
|
|
2261
|
+
return true;
|
|
2262
|
+
} catch (err) {
|
|
2263
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
2264
|
+
return false;
|
|
2265
|
+
} finally {
|
|
2266
|
+
setPending(false);
|
|
2267
|
+
}
|
|
2268
|
+
}, []);
|
|
2269
|
+
const start = react.useCallback(
|
|
2270
|
+
(mode) => run(async () => {
|
|
2271
|
+
if (!callId) throw new Error("no call");
|
|
2272
|
+
const r = await chat.calls.recording.start(callId, mode ? { mode } : {});
|
|
2273
|
+
setLastRecording(r);
|
|
2274
|
+
}),
|
|
2275
|
+
[chat, callId, run]
|
|
2276
|
+
);
|
|
2277
|
+
const stop = react.useCallback(
|
|
2278
|
+
() => run(async () => {
|
|
2279
|
+
if (!callId) throw new Error("no call");
|
|
2280
|
+
const r = await chat.calls.recording.stop(callId);
|
|
2281
|
+
setLastRecording(r);
|
|
2282
|
+
}),
|
|
2283
|
+
[chat, callId, run]
|
|
2284
|
+
);
|
|
2285
|
+
const consent = react.useCallback(
|
|
2286
|
+
(decision) => run(async () => {
|
|
2287
|
+
if (!callId) throw new Error("no call");
|
|
2288
|
+
const res = await chat.calls.consent(callId, decision);
|
|
2289
|
+
setState(
|
|
2290
|
+
(s) => applyCaptureEvent(s, {
|
|
2291
|
+
type: "recording:consent",
|
|
2292
|
+
evt: { cv: 1, call_id: res.call_id, user_id: res.user_id, decision: res.decision }
|
|
2293
|
+
})
|
|
2294
|
+
);
|
|
2295
|
+
}),
|
|
2296
|
+
[chat, callId, run]
|
|
2297
|
+
);
|
|
2298
|
+
const rec = state.recording;
|
|
2299
|
+
const active = !!rec?.active;
|
|
2300
|
+
const capturing = active || transcribing;
|
|
2301
|
+
const consentRequired = active && !!rec?.consent_required || transcribing && transcriptConsent;
|
|
2302
|
+
const myConsent = meId && rec ? rec.consent.accepted.includes(meId) || active && rec.started_by_user_id === meId ? "accepted" : rec.consent.declined.includes(meId) ? "declined" : null : null;
|
|
2303
|
+
return {
|
|
2304
|
+
available: rec?.available ?? false,
|
|
2305
|
+
active,
|
|
2306
|
+
recording: rec,
|
|
2307
|
+
transcription: state.transcription,
|
|
2308
|
+
capturing,
|
|
2309
|
+
consentRequired,
|
|
2310
|
+
myConsent,
|
|
2311
|
+
needsConsent: capturing && consentRequired && myConsent !== "accepted",
|
|
2312
|
+
notice,
|
|
2313
|
+
lastRecording,
|
|
2314
|
+
pending,
|
|
2315
|
+
error,
|
|
2316
|
+
start,
|
|
2317
|
+
stop,
|
|
2318
|
+
consent,
|
|
2319
|
+
refresh
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
function useLiveTranscript(callId, opts = {}) {
|
|
2323
|
+
const chat = usePoolse();
|
|
2324
|
+
const enabled = opts.enabled ?? true;
|
|
2325
|
+
const max = opts.maxSegments ?? 1e3;
|
|
2326
|
+
const [segments, setSegments] = react.useState([]);
|
|
2327
|
+
const [transcript, setTranscript] = react.useState(null);
|
|
2328
|
+
const [conversationId, setConversationId] = react.useState(null);
|
|
2329
|
+
const [joined, setJoined] = react.useState(false);
|
|
2330
|
+
const [error, setError] = react.useState(null);
|
|
2331
|
+
const [pending, setPending] = react.useState(false);
|
|
2332
|
+
react.useEffect(() => {
|
|
2333
|
+
setSegments([]);
|
|
2334
|
+
setTranscript(null);
|
|
2335
|
+
setJoined(false);
|
|
2336
|
+
setError(null);
|
|
2337
|
+
if (!callId || !enabled) return;
|
|
2338
|
+
let handle;
|
|
2339
|
+
try {
|
|
2340
|
+
handle = chat.realtime.transcript(callId);
|
|
2341
|
+
} catch (err) {
|
|
2342
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
2343
|
+
return;
|
|
2344
|
+
}
|
|
2345
|
+
const offJoined = handle.onJoined((reply) => {
|
|
2346
|
+
setJoined(true);
|
|
2347
|
+
setError(null);
|
|
2348
|
+
setConversationId(reply.conversation_id || null);
|
|
2349
|
+
setTranscript(reply.transcript);
|
|
2350
|
+
setSegments(reply.segments.slice(-max).map((s) => ({ ...s, final: true })));
|
|
2351
|
+
});
|
|
2352
|
+
const offSegment = handle.onSegment((evt) => {
|
|
2353
|
+
const { cv: _cv, call_id: _call, transcript_id: _t, ...seg } = evt;
|
|
2354
|
+
setSegments((list) => sdk.applyLiveSegment(list, seg, max));
|
|
2355
|
+
});
|
|
2356
|
+
const offError = handle.onError((reason) => {
|
|
2357
|
+
setJoined(false);
|
|
2358
|
+
setError(new Error(reason));
|
|
2359
|
+
});
|
|
2360
|
+
return () => {
|
|
2361
|
+
offJoined();
|
|
2362
|
+
offSegment();
|
|
2363
|
+
offError();
|
|
2364
|
+
handle.release();
|
|
2365
|
+
};
|
|
2366
|
+
}, [chat, callId, enabled, max]);
|
|
2367
|
+
react.useEffect(() => {
|
|
2368
|
+
if (!callId || !conversationId || !enabled) return;
|
|
2369
|
+
const conv = chat.realtime.conversation(conversationId);
|
|
2370
|
+
const apply = (evt) => {
|
|
2371
|
+
if (evt.call_id === callId) setTranscript(evt.transcript);
|
|
2372
|
+
};
|
|
2373
|
+
const offs = [
|
|
2374
|
+
conv.onTranscriptStarted(apply),
|
|
2375
|
+
conv.onTranscriptStopped(apply),
|
|
2376
|
+
conv.onTranscriptReady(apply),
|
|
2377
|
+
conv.onTranscriptSpeakers((evt) => {
|
|
2378
|
+
if (evt.call_id !== callId) return;
|
|
2379
|
+
const names = new Map(evt.speakers.map((s) => [s.key, s.name]));
|
|
2380
|
+
setSegments(
|
|
2381
|
+
(list) => list.map(
|
|
2382
|
+
(s) => names.has(s.speaker) ? { ...s, speaker_name: names.get(s.speaker) } : s
|
|
2383
|
+
)
|
|
2384
|
+
);
|
|
2385
|
+
})
|
|
2386
|
+
];
|
|
2387
|
+
return () => offs.forEach((off) => off());
|
|
2388
|
+
}, [chat, callId, conversationId, enabled]);
|
|
2389
|
+
const run = react.useCallback(async (fn) => {
|
|
2390
|
+
setPending(true);
|
|
2391
|
+
setError(null);
|
|
2392
|
+
try {
|
|
2393
|
+
setTranscript(await fn());
|
|
2394
|
+
return true;
|
|
2395
|
+
} catch (err) {
|
|
2396
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
2397
|
+
return false;
|
|
2398
|
+
} finally {
|
|
2399
|
+
setPending(false);
|
|
2400
|
+
}
|
|
2401
|
+
}, []);
|
|
2402
|
+
const start = react.useCallback(
|
|
2403
|
+
() => callId ? run(() => chat.calls.transcription.start(callId)) : Promise.resolve(false),
|
|
2404
|
+
[chat, callId, run]
|
|
2405
|
+
);
|
|
2406
|
+
const stop = react.useCallback(
|
|
2407
|
+
() => callId ? run(() => chat.calls.transcription.stop(callId)) : Promise.resolve(false),
|
|
2408
|
+
[chat, callId, run]
|
|
2409
|
+
);
|
|
2410
|
+
const finals = react.useMemo(() => segments.filter((s) => s.final), [segments]);
|
|
2411
|
+
const interim = react.useMemo(() => segments.filter((s) => !s.final), [segments]);
|
|
2412
|
+
return {
|
|
2413
|
+
segments,
|
|
2414
|
+
finals,
|
|
2415
|
+
interim,
|
|
2416
|
+
transcript,
|
|
2417
|
+
live: transcript?.status === "live",
|
|
2418
|
+
joined,
|
|
2419
|
+
error,
|
|
2420
|
+
pending,
|
|
2421
|
+
start,
|
|
2422
|
+
stop
|
|
2423
|
+
};
|
|
2424
|
+
}
|
|
2425
|
+
function withSpeakers(t, speakers) {
|
|
2426
|
+
const names = new Map(speakers.map((s) => [s.key, s.name]));
|
|
2427
|
+
return {
|
|
2428
|
+
...t,
|
|
2429
|
+
speakers,
|
|
2430
|
+
segments: t.segments.map(
|
|
2431
|
+
(s) => names.has(s.speaker) ? { ...s, speaker_name: names.get(s.speaker) ?? null } : s
|
|
2432
|
+
)
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2435
|
+
function useTranscript(callId) {
|
|
2436
|
+
const chat = usePoolse();
|
|
2437
|
+
const [transcript, setTranscript] = react.useState(null);
|
|
2438
|
+
const [loading, setLoading] = react.useState(!!callId);
|
|
2439
|
+
const [missing, setMissing] = react.useState(false);
|
|
2440
|
+
const [error, setError] = react.useState(null);
|
|
2441
|
+
const seq = react.useRef(0);
|
|
2442
|
+
const refresh = react.useCallback(() => {
|
|
2443
|
+
if (!callId) return;
|
|
2444
|
+
const mine = ++seq.current;
|
|
2445
|
+
setLoading(true);
|
|
2446
|
+
chat.calls.transcript.get(callId).then((t) => {
|
|
2447
|
+
if (mine !== seq.current) return;
|
|
2448
|
+
setTranscript(t);
|
|
2449
|
+
setMissing(false);
|
|
2450
|
+
setError(null);
|
|
2451
|
+
}).catch((err) => {
|
|
2452
|
+
if (mine !== seq.current) return;
|
|
2453
|
+
if (err instanceof sdk.ApiError && err.status === 404) {
|
|
2454
|
+
setMissing(true);
|
|
2455
|
+
setTranscript(null);
|
|
2456
|
+
} else setError(err instanceof Error ? err : new Error(String(err)));
|
|
2457
|
+
}).finally(() => {
|
|
2458
|
+
if (mine === seq.current) setLoading(false);
|
|
2459
|
+
});
|
|
2460
|
+
}, [chat, callId]);
|
|
2461
|
+
react.useEffect(() => {
|
|
2462
|
+
setTranscript(null);
|
|
2463
|
+
setMissing(false);
|
|
2464
|
+
setError(null);
|
|
2465
|
+
setLoading(!!callId);
|
|
2466
|
+
refresh();
|
|
2467
|
+
}, [callId, refresh]);
|
|
2468
|
+
const conversationId = transcript?.conversation_id ?? null;
|
|
2469
|
+
react.useEffect(() => {
|
|
2470
|
+
if (!callId || !conversationId) return;
|
|
2471
|
+
const conv = chat.realtime.conversation(conversationId);
|
|
2472
|
+
const offSpeakers = conv.onTranscriptSpeakers((evt) => {
|
|
2473
|
+
if (evt.call_id !== callId) return;
|
|
2474
|
+
seq.current++;
|
|
2475
|
+
setTranscript((t) => t ? withSpeakers(t, evt.speakers) : t);
|
|
2476
|
+
});
|
|
2477
|
+
const offReady = conv.onTranscriptReady((evt) => {
|
|
2478
|
+
if (evt.call_id === callId) refresh();
|
|
2479
|
+
});
|
|
2480
|
+
const offStatus = onReconnect(chat, refresh);
|
|
2481
|
+
return () => {
|
|
2482
|
+
offSpeakers();
|
|
2483
|
+
offReady();
|
|
2484
|
+
offStatus();
|
|
2485
|
+
};
|
|
2486
|
+
}, [chat, callId, conversationId, refresh]);
|
|
2487
|
+
const renameSpeakers = react.useCallback(
|
|
2488
|
+
async (names) => {
|
|
2489
|
+
if (!callId) return;
|
|
2490
|
+
const t = await chat.calls.transcript.renameSpeakers(callId, names);
|
|
2491
|
+
seq.current++;
|
|
2492
|
+
setTranscript(t);
|
|
2493
|
+
},
|
|
2494
|
+
[chat, callId]
|
|
2495
|
+
);
|
|
2496
|
+
return { transcript, loading, missing, error, renameSpeakers, refresh };
|
|
2497
|
+
}
|
|
2498
|
+
function useCaptureList(conversationId, load, subscribe) {
|
|
2499
|
+
const chat = usePoolse();
|
|
2500
|
+
const [items, setItems] = react.useState([]);
|
|
2501
|
+
const [loading, setLoading] = react.useState(!!conversationId);
|
|
2502
|
+
const [error, setError] = react.useState(null);
|
|
2503
|
+
const seq = react.useRef(0);
|
|
2504
|
+
const loadRef = react.useRef(load);
|
|
2505
|
+
loadRef.current = load;
|
|
2506
|
+
const subscribeRef = react.useRef(subscribe);
|
|
2507
|
+
subscribeRef.current = subscribe;
|
|
2508
|
+
const refresh = react.useCallback(() => {
|
|
2509
|
+
if (!conversationId) return;
|
|
2510
|
+
const mine = ++seq.current;
|
|
2511
|
+
setLoading(true);
|
|
2512
|
+
loadRef.current(conversationId).then((list) => {
|
|
2513
|
+
if (mine !== seq.current) return;
|
|
2514
|
+
setItems(list);
|
|
2515
|
+
setError(null);
|
|
2516
|
+
}).catch((err) => {
|
|
2517
|
+
if (mine === seq.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
2518
|
+
}).finally(() => {
|
|
2519
|
+
if (mine === seq.current) setLoading(false);
|
|
2520
|
+
});
|
|
2521
|
+
}, [conversationId]);
|
|
2522
|
+
react.useEffect(() => {
|
|
2523
|
+
setItems([]);
|
|
2524
|
+
if (!conversationId) {
|
|
2525
|
+
setLoading(false);
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
refresh();
|
|
2529
|
+
const off = subscribeRef.current(conversationId, refresh);
|
|
2530
|
+
const offStatus = onReconnect(chat, refresh);
|
|
2531
|
+
return () => {
|
|
2532
|
+
off();
|
|
2533
|
+
offStatus();
|
|
2534
|
+
};
|
|
2535
|
+
}, [chat, conversationId, refresh]);
|
|
2536
|
+
return { items, loading, error, refresh };
|
|
2537
|
+
}
|
|
2538
|
+
function useTranscripts(conversationId, opts = {}) {
|
|
2539
|
+
const chat = usePoolse();
|
|
2540
|
+
return useCaptureList(
|
|
2541
|
+
conversationId,
|
|
2542
|
+
(id) => chat.calls.transcript.list(id, opts.limit !== void 0 ? { limit: opts.limit } : {}),
|
|
2543
|
+
(id, refresh) => {
|
|
2544
|
+
const conv = chat.realtime.conversation(id);
|
|
2545
|
+
const offs = [conv.onTranscriptStarted(refresh), conv.onTranscriptReady(refresh)];
|
|
2546
|
+
return () => offs.forEach((off) => off());
|
|
2547
|
+
}
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
function useRecordings(conversationId, opts = {}) {
|
|
2551
|
+
const chat = usePoolse();
|
|
2552
|
+
return useCaptureList(
|
|
2553
|
+
conversationId,
|
|
2554
|
+
(id) => chat.calls.recording.list(id, opts.limit !== void 0 ? { limit: opts.limit } : {}),
|
|
2555
|
+
(id, refresh) => {
|
|
2556
|
+
const conv = chat.realtime.conversation(id);
|
|
2557
|
+
const offs = [
|
|
2558
|
+
conv.onRecordingStarted(refresh),
|
|
2559
|
+
conv.onRecordingStopped(refresh),
|
|
2560
|
+
conv.onRecordingReady(refresh)
|
|
2561
|
+
];
|
|
2562
|
+
return () => offs.forEach((off) => off());
|
|
2563
|
+
}
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2053
2566
|
function useReadReceipts() {
|
|
2054
2567
|
const chat = usePoolse();
|
|
2055
2568
|
const { me } = useMe();
|
|
@@ -2099,6 +2612,10 @@ Object.defineProperty(exports, "NetworkError", {
|
|
|
2099
2612
|
enumerable: true,
|
|
2100
2613
|
get: function () { return sdk.NetworkError; }
|
|
2101
2614
|
});
|
|
2615
|
+
Object.defineProperty(exports, "POOLSE_SERVICE_IDENTITY_PREFIX", {
|
|
2616
|
+
enumerable: true,
|
|
2617
|
+
get: function () { return sdk.POOLSE_SERVICE_IDENTITY_PREFIX; }
|
|
2618
|
+
});
|
|
2102
2619
|
Object.defineProperty(exports, "Poolse", {
|
|
2103
2620
|
enumerable: true,
|
|
2104
2621
|
get: function () { return sdk.Poolse; }
|
|
@@ -2111,10 +2628,22 @@ Object.defineProperty(exports, "RateLimitedError", {
|
|
|
2111
2628
|
enumerable: true,
|
|
2112
2629
|
get: function () { return sdk.RateLimitedError; }
|
|
2113
2630
|
});
|
|
2631
|
+
Object.defineProperty(exports, "applyLiveSegment", {
|
|
2632
|
+
enumerable: true,
|
|
2633
|
+
get: function () { return sdk.applyLiveSegment; }
|
|
2634
|
+
});
|
|
2114
2635
|
Object.defineProperty(exports, "callLogDisplayFor", {
|
|
2115
2636
|
enumerable: true,
|
|
2116
2637
|
get: function () { return sdk.callLogDisplayFor; }
|
|
2117
2638
|
});
|
|
2639
|
+
Object.defineProperty(exports, "captureErrorMessage", {
|
|
2640
|
+
enumerable: true,
|
|
2641
|
+
get: function () { return sdk.captureErrorMessage; }
|
|
2642
|
+
});
|
|
2643
|
+
Object.defineProperty(exports, "captureLabel", {
|
|
2644
|
+
enumerable: true,
|
|
2645
|
+
get: function () { return sdk.captureLabel; }
|
|
2646
|
+
});
|
|
2118
2647
|
Object.defineProperty(exports, "createIndexedDbStorage", {
|
|
2119
2648
|
enumerable: true,
|
|
2120
2649
|
get: function () { return sdk.createIndexedDbStorage; }
|
|
@@ -2123,6 +2652,14 @@ Object.defineProperty(exports, "describeCallLog", {
|
|
|
2123
2652
|
enumerable: true,
|
|
2124
2653
|
get: function () { return sdk.describeCallLog; }
|
|
2125
2654
|
});
|
|
2655
|
+
Object.defineProperty(exports, "describeRecordingNotice", {
|
|
2656
|
+
enumerable: true,
|
|
2657
|
+
get: function () { return sdk.describeRecordingNotice; }
|
|
2658
|
+
});
|
|
2659
|
+
Object.defineProperty(exports, "findInText", {
|
|
2660
|
+
enumerable: true,
|
|
2661
|
+
get: function () { return sdk.findInText; }
|
|
2662
|
+
});
|
|
2126
2663
|
Object.defineProperty(exports, "formatCallDuration", {
|
|
2127
2664
|
enumerable: true,
|
|
2128
2665
|
get: function () { return sdk.formatCallDuration; }
|
|
@@ -2131,6 +2668,14 @@ Object.defineProperty(exports, "formatCallLogPreview", {
|
|
|
2131
2668
|
enumerable: true,
|
|
2132
2669
|
get: function () { return sdk.formatCallLogPreview; }
|
|
2133
2670
|
});
|
|
2671
|
+
Object.defineProperty(exports, "formatRecordingNoticePreview", {
|
|
2672
|
+
enumerable: true,
|
|
2673
|
+
get: function () { return sdk.formatRecordingNoticePreview; }
|
|
2674
|
+
});
|
|
2675
|
+
Object.defineProperty(exports, "groupTranscript", {
|
|
2676
|
+
enumerable: true,
|
|
2677
|
+
get: function () { return sdk.groupTranscript; }
|
|
2678
|
+
});
|
|
2134
2679
|
Object.defineProperty(exports, "isCallLogMessage", {
|
|
2135
2680
|
enumerable: true,
|
|
2136
2681
|
get: function () { return sdk.isCallLogMessage; }
|
|
@@ -2139,6 +2684,10 @@ Object.defineProperty(exports, "isMessageVisibleTo", {
|
|
|
2139
2684
|
enumerable: true,
|
|
2140
2685
|
get: function () { return sdk.isMessageVisibleTo; }
|
|
2141
2686
|
});
|
|
2687
|
+
Object.defineProperty(exports, "isServiceParticipant", {
|
|
2688
|
+
enumerable: true,
|
|
2689
|
+
get: function () { return sdk.isServiceParticipant; }
|
|
2690
|
+
});
|
|
2142
2691
|
Object.defineProperty(exports, "isTombstone", {
|
|
2143
2692
|
enumerable: true,
|
|
2144
2693
|
get: function () { return sdk.isTombstone; }
|
|
@@ -2159,12 +2708,29 @@ Object.defineProperty(exports, "parseCallLogBody", {
|
|
|
2159
2708
|
enumerable: true,
|
|
2160
2709
|
get: function () { return sdk.parseCallLogBody; }
|
|
2161
2710
|
});
|
|
2711
|
+
Object.defineProperty(exports, "parseRecordingNotice", {
|
|
2712
|
+
enumerable: true,
|
|
2713
|
+
get: function () { return sdk.parseRecordingNotice; }
|
|
2714
|
+
});
|
|
2715
|
+
Object.defineProperty(exports, "parseRecordingNoticeBody", {
|
|
2716
|
+
enumerable: true,
|
|
2717
|
+
get: function () { return sdk.parseRecordingNoticeBody; }
|
|
2718
|
+
});
|
|
2719
|
+
Object.defineProperty(exports, "recordingNoticeDisplayFor", {
|
|
2720
|
+
enumerable: true,
|
|
2721
|
+
get: function () { return sdk.recordingNoticeDisplayFor; }
|
|
2722
|
+
});
|
|
2723
|
+
Object.defineProperty(exports, "speakerName", {
|
|
2724
|
+
enumerable: true,
|
|
2725
|
+
get: function () { return sdk.speakerName; }
|
|
2726
|
+
});
|
|
2162
2727
|
Object.defineProperty(exports, "toTombstone", {
|
|
2163
2728
|
enumerable: true,
|
|
2164
2729
|
get: function () { return sdk.toTombstone; }
|
|
2165
2730
|
});
|
|
2166
2731
|
exports.EDIT_WINDOW_MS = EDIT_WINDOW_MS;
|
|
2167
2732
|
exports.PoolseProvider = PoolseProvider;
|
|
2733
|
+
exports.applyCaptureEvent = applyCaptureEvent;
|
|
2168
2734
|
exports.canEditOwnMessage = canEditOwnMessage;
|
|
2169
2735
|
exports.computeGroupPosition = computeGroupPosition;
|
|
2170
2736
|
exports.filterConversations = filterConversations;
|
|
@@ -2182,6 +2748,7 @@ exports.useConversation = useConversation;
|
|
|
2182
2748
|
exports.useConversationPresence = useConversationPresence;
|
|
2183
2749
|
exports.useConversations = useConversations;
|
|
2184
2750
|
exports.useLiveCall = useLiveCall;
|
|
2751
|
+
exports.useLiveTranscript = useLiveTranscript;
|
|
2185
2752
|
exports.useMe = useMe;
|
|
2186
2753
|
exports.useMembers = useMembers;
|
|
2187
2754
|
exports.useMessageStreams = useMessageStreams;
|
|
@@ -2193,8 +2760,12 @@ exports.usePresenceMany = usePresenceMany;
|
|
|
2193
2760
|
exports.useReactions = useReactions;
|
|
2194
2761
|
exports.useReadReceipts = useReadReceipts;
|
|
2195
2762
|
exports.useRealtimeStatus = useRealtimeStatus;
|
|
2763
|
+
exports.useRecording = useRecording;
|
|
2764
|
+
exports.useRecordings = useRecordings;
|
|
2196
2765
|
exports.useRoom = useRoom;
|
|
2197
2766
|
exports.useThread = useThread;
|
|
2767
|
+
exports.useTranscript = useTranscript;
|
|
2768
|
+
exports.useTranscripts = useTranscripts;
|
|
2198
2769
|
exports.useTyping = useTyping;
|
|
2199
2770
|
exports.useUnreadQueue = useUnreadQueue;
|
|
2200
2771
|
exports.useUnreadTotals = useUnreadTotals;
|