@realtimexsco/live-chat 1.4.4 → 1.4.5
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/index.cjs +37 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +0 -12
- package/dist/index.d.ts +0 -12
- package/dist/index.mjs +37 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17604,7 +17604,9 @@ var disablePushOnThisDevice = async () => {
|
|
|
17604
17604
|
};
|
|
17605
17605
|
var onForegroundPush = async (callback) => {
|
|
17606
17606
|
const config = await apiGetPushConfig();
|
|
17607
|
-
if (!config?.configured || !config.firebaseConfig)
|
|
17607
|
+
if (!config?.configured || !config.firebaseConfig) {
|
|
17608
|
+
throw new Error("Push config unavailable (not configured or API not ready)");
|
|
17609
|
+
}
|
|
17608
17610
|
const { fb, messaging } = await getFirebaseMessaging(config.firebaseConfig);
|
|
17609
17611
|
return fb.onMessage(messaging, (payload) => {
|
|
17610
17612
|
callback({
|
|
@@ -17616,25 +17618,54 @@ var onForegroundPush = async (callback) => {
|
|
|
17616
17618
|
};
|
|
17617
17619
|
|
|
17618
17620
|
// src/notifications/ForegroundPushBridge.tsx
|
|
17621
|
+
var RETRY_DELAYS_MS = [1e3, 3e3, 8e3, 2e4];
|
|
17619
17622
|
var ForegroundPushBridge = ({ onPush }) => {
|
|
17620
17623
|
React2.useEffect(() => {
|
|
17621
17624
|
let unsubscribe = null;
|
|
17625
|
+
let retryTimer = null;
|
|
17622
17626
|
let cancelled = false;
|
|
17623
17627
|
const handlePayload = (payload) => {
|
|
17624
17628
|
const incoming = payload.data?.conversationId;
|
|
17625
17629
|
const activeId = exports.useChatStore.getState().activeConversationId;
|
|
17626
|
-
if (incoming && activeId && incoming === activeId)
|
|
17630
|
+
if (incoming && activeId && incoming === activeId) {
|
|
17631
|
+
console.debug(
|
|
17632
|
+
"[realtimex-push] foreground push suppressed (conversation open):",
|
|
17633
|
+
incoming
|
|
17634
|
+
);
|
|
17635
|
+
return;
|
|
17636
|
+
}
|
|
17637
|
+
console.debug("[realtimex-push] foreground push \u2192 toast:", {
|
|
17638
|
+
title: payload.title,
|
|
17639
|
+
conversationId: incoming,
|
|
17640
|
+
activeConversationId: activeId
|
|
17641
|
+
});
|
|
17627
17642
|
if (onPush && onPush(payload) !== false) return;
|
|
17628
17643
|
const text = payload.title ? payload.body ? `${payload.title}: ${payload.body}` : payload.title : payload.body;
|
|
17629
17644
|
if (text) showNotification(text, "info");
|
|
17630
17645
|
};
|
|
17631
|
-
const start = async () => {
|
|
17646
|
+
const start = async (attempt = 0) => {
|
|
17632
17647
|
if (cancelled || unsubscribe || !getStoredPushToken()) return;
|
|
17633
17648
|
try {
|
|
17634
17649
|
const stop = await onForegroundPush(handlePayload);
|
|
17635
17650
|
if (cancelled) stop();
|
|
17636
|
-
else
|
|
17637
|
-
|
|
17651
|
+
else {
|
|
17652
|
+
unsubscribe = stop;
|
|
17653
|
+
console.debug(
|
|
17654
|
+
"[realtimex-push] foreground listener active"
|
|
17655
|
+
);
|
|
17656
|
+
}
|
|
17657
|
+
} catch (error) {
|
|
17658
|
+
if (cancelled || attempt >= RETRY_DELAYS_MS.length) {
|
|
17659
|
+
console.debug(
|
|
17660
|
+
"[realtimex-push] foreground listener NOT started:",
|
|
17661
|
+
error instanceof Error ? error.message : error
|
|
17662
|
+
);
|
|
17663
|
+
return;
|
|
17664
|
+
}
|
|
17665
|
+
retryTimer = setTimeout(
|
|
17666
|
+
() => void start(attempt + 1),
|
|
17667
|
+
RETRY_DELAYS_MS[attempt]
|
|
17668
|
+
);
|
|
17638
17669
|
}
|
|
17639
17670
|
};
|
|
17640
17671
|
void start();
|
|
@@ -17649,6 +17680,7 @@ var ForegroundPushBridge = ({ onPush }) => {
|
|
|
17649
17680
|
window.addEventListener(PUSH_CHANGED_EVENT, onPushChanged);
|
|
17650
17681
|
return () => {
|
|
17651
17682
|
cancelled = true;
|
|
17683
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
17652
17684
|
unsubscribe?.();
|
|
17653
17685
|
window.removeEventListener(PUSH_CHANGED_EVENT, onPushChanged);
|
|
17654
17686
|
};
|