@sevenfold/setto-client 0.47.0 → 0.48.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/dist/chunks/{SettoChat-C4QpE5Gm.js → SettoChat-SqJlsGXL.js} +42 -3
- package/dist/chunks/{SettoChat-C4QpE5Gm.js.map → SettoChat-SqJlsGXL.js.map} +1 -1
- package/dist/modules/chat/SettoChat.d.ts +3 -0
- package/dist/modules/chat/realtime.d.ts +17 -0
- package/dist/setto-client.js +1 -1
- package/package.json +1 -1
|
@@ -12934,6 +12934,21 @@ function refreshOutcome(started, current) {
|
|
|
12934
12934
|
if (current.busy || started.turn !== current.turn) return "defer";
|
|
12935
12935
|
return "apply";
|
|
12936
12936
|
}
|
|
12937
|
+
const AVAILABILITY_POLL_MS = 3e4;
|
|
12938
|
+
const AVAILABILITY_POLL_LIVE_MS = 12e4;
|
|
12939
|
+
function presenceTopic(value) {
|
|
12940
|
+
return typeof value === "string" && value.length <= 200 && /^chat-presence:\S+$/.test(value) ? value : null;
|
|
12941
|
+
}
|
|
12942
|
+
function nextAvailabilityChange(humans, now) {
|
|
12943
|
+
let next = null;
|
|
12944
|
+
for (const human of humans) {
|
|
12945
|
+
for (const at of [human.online ? human.onlineUntil : null, human.nearbyUntil]) {
|
|
12946
|
+
const time = at ? Date.parse(at) : NaN;
|
|
12947
|
+
if (Number.isFinite(time) && time > now && (next === null || time < next)) next = time;
|
|
12948
|
+
}
|
|
12949
|
+
}
|
|
12950
|
+
return next;
|
|
12951
|
+
}
|
|
12937
12952
|
const CAPTION_STRINGS = {
|
|
12938
12953
|
en: { translatedFrom: "Translated from {language}", translated: "Translated", showOriginal: "Show original", showTranslation: "Show translation" },
|
|
12939
12954
|
no: { translatedFrom: "Oversatt fra {language}", translated: "Oversatt", showOriginal: "Vis original", showTranslation: "Vis oversettelse" },
|
|
@@ -13931,6 +13946,23 @@ function SettoChatWidget({ settings }) {
|
|
|
13931
13946
|
const palette = useSitePalette(config.brandColors);
|
|
13932
13947
|
const desktopPopup = useDesktopPopup();
|
|
13933
13948
|
const pageVisible = usePageVisible();
|
|
13949
|
+
const refreshAvailabilityRef = useRef(() => void 0);
|
|
13950
|
+
const [presenceLive, setPresenceLive] = useState(false);
|
|
13951
|
+
useConversationChannel(loadSupabase, mounted ? presenceTopic(availability.topic) : null, {
|
|
13952
|
+
onStatus(next) {
|
|
13953
|
+
setPresenceLive(next);
|
|
13954
|
+
if (next) refreshAvailabilityRef.current();
|
|
13955
|
+
},
|
|
13956
|
+
onChanged() {
|
|
13957
|
+
refreshAvailabilityRef.current();
|
|
13958
|
+
},
|
|
13959
|
+
onRead() {
|
|
13960
|
+
},
|
|
13961
|
+
onTyping() {
|
|
13962
|
+
},
|
|
13963
|
+
onLeave() {
|
|
13964
|
+
}
|
|
13965
|
+
});
|
|
13934
13966
|
const channelRef = useConversationChannel(loadSupabase, mounted ? realtime?.topic ?? null : null, {
|
|
13935
13967
|
onStatus(next) {
|
|
13936
13968
|
subscribedRef.current = next;
|
|
@@ -14221,13 +14253,20 @@ function SettoChatWidget({ settings }) {
|
|
|
14221
14253
|
}).then(async (response) => response.ok ? await response.json() : null).then((next) => {
|
|
14222
14254
|
if (!cancelled && next) setAvailability(next);
|
|
14223
14255
|
}).catch(() => void 0);
|
|
14256
|
+
refreshAvailabilityRef.current = () => void refresh();
|
|
14224
14257
|
void refresh();
|
|
14225
|
-
const timer = window.setInterval(() => void refresh(),
|
|
14258
|
+
const timer = window.setInterval(() => void refresh(), presenceLive ? AVAILABILITY_POLL_LIVE_MS : AVAILABILITY_POLL_MS);
|
|
14226
14259
|
return () => {
|
|
14227
14260
|
cancelled = true;
|
|
14228
14261
|
window.clearInterval(timer);
|
|
14229
14262
|
};
|
|
14230
|
-
}, [apiUrl, config.siteId, settings, mounted]);
|
|
14263
|
+
}, [apiUrl, config.siteId, settings, mounted, presenceLive]);
|
|
14264
|
+
useEffect(() => {
|
|
14265
|
+
const at = nextAvailabilityChange(availability.humans ?? [], Date.now());
|
|
14266
|
+
if (at === null) return;
|
|
14267
|
+
const timer = window.setTimeout(() => refreshAvailabilityRef.current(), at - Date.now() + 1e3);
|
|
14268
|
+
return () => window.clearTimeout(timer);
|
|
14269
|
+
}, [availability]);
|
|
14231
14270
|
const greeterKey = greeter ? `${greeter.handle}:${greeter.avatarUrl ?? ""}` : "";
|
|
14232
14271
|
useEffect(() => {
|
|
14233
14272
|
if (!mounted || !settings || conversationId.current) return;
|
|
@@ -14857,4 +14896,4 @@ export {
|
|
|
14857
14896
|
sineOut,
|
|
14858
14897
|
teamRowLabelled
|
|
14859
14898
|
};
|
|
14860
|
-
//# sourceMappingURL=SettoChat-
|
|
14899
|
+
//# sourceMappingURL=SettoChat-SqJlsGXL.js.map
|