@realtimexsco/live-chat 1.4.3 → 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 +330 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.mjs +329 -239
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17382,6 +17382,311 @@ function ChatViewport({
|
|
|
17382
17382
|
);
|
|
17383
17383
|
}
|
|
17384
17384
|
var ChatViewport_default = ChatViewport;
|
|
17385
|
+
var showNotification = (message, type = "info", icon, duration) => {
|
|
17386
|
+
const options = {
|
|
17387
|
+
icon,
|
|
17388
|
+
duration
|
|
17389
|
+
};
|
|
17390
|
+
switch (type) {
|
|
17391
|
+
case "success":
|
|
17392
|
+
reactHotToast.toast.success(message, options);
|
|
17393
|
+
break;
|
|
17394
|
+
case "error":
|
|
17395
|
+
reactHotToast.toast.error(message, options);
|
|
17396
|
+
break;
|
|
17397
|
+
case "info":
|
|
17398
|
+
reactHotToast.toast(message, options);
|
|
17399
|
+
break;
|
|
17400
|
+
case "warning":
|
|
17401
|
+
reactHotToast.toast(message, { ...options, icon: "\u26A0\uFE0F" });
|
|
17402
|
+
break;
|
|
17403
|
+
default:
|
|
17404
|
+
reactHotToast.toast(message, options);
|
|
17405
|
+
}
|
|
17406
|
+
};
|
|
17407
|
+
var downloadFile = async (src, name) => {
|
|
17408
|
+
try {
|
|
17409
|
+
const link = document.createElement("a");
|
|
17410
|
+
link.href = src;
|
|
17411
|
+
link.setAttribute("download", name);
|
|
17412
|
+
link.setAttribute("rel", "noopener noreferrer");
|
|
17413
|
+
link.click();
|
|
17414
|
+
showNotification("File Downloaded Successfully", "success");
|
|
17415
|
+
} catch (err) {
|
|
17416
|
+
console.error("File download failed:", err);
|
|
17417
|
+
showNotification("Failed to download file", "error");
|
|
17418
|
+
}
|
|
17419
|
+
};
|
|
17420
|
+
var getResponsiveWidth = (width) => {
|
|
17421
|
+
const screenWidth = window.innerWidth;
|
|
17422
|
+
if (width) {
|
|
17423
|
+
return width;
|
|
17424
|
+
} else if (screenWidth < 640) {
|
|
17425
|
+
return 350;
|
|
17426
|
+
} else if (screenWidth >= 640 && screenWidth < 1024) {
|
|
17427
|
+
return 600;
|
|
17428
|
+
} else if (screenWidth >= 1024 && screenWidth < 1280) {
|
|
17429
|
+
return 800;
|
|
17430
|
+
} else {
|
|
17431
|
+
return 1e3;
|
|
17432
|
+
}
|
|
17433
|
+
};
|
|
17434
|
+
var isEmpty = (value) => {
|
|
17435
|
+
if (value === null || value === void 0) return true;
|
|
17436
|
+
if (typeof value === "string") return value.trim().length === 0;
|
|
17437
|
+
if (Array.isArray(value)) {
|
|
17438
|
+
return value.length === 0 || value.every((item) => isEmpty(item));
|
|
17439
|
+
}
|
|
17440
|
+
if (typeof value === "object") {
|
|
17441
|
+
return Object.keys(value).length === 0;
|
|
17442
|
+
}
|
|
17443
|
+
return false;
|
|
17444
|
+
};
|
|
17445
|
+
function uniqueList(list, key) {
|
|
17446
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17447
|
+
return list.filter((item) => {
|
|
17448
|
+
const value = item[key];
|
|
17449
|
+
if (seen.has(value)) return false;
|
|
17450
|
+
seen.add(value);
|
|
17451
|
+
return true;
|
|
17452
|
+
});
|
|
17453
|
+
}
|
|
17454
|
+
var capitalizeFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
17455
|
+
var getFirstAndLastNameOneCharacter = (name) => {
|
|
17456
|
+
const names = name.split(" ");
|
|
17457
|
+
return names.map((name2) => name2.charAt(0).toUpperCase()).join("");
|
|
17458
|
+
};
|
|
17459
|
+
|
|
17460
|
+
// src/notifications/ForegroundPushBridge.tsx
|
|
17461
|
+
init_useStore();
|
|
17462
|
+
|
|
17463
|
+
// src/notifications/push.service.ts
|
|
17464
|
+
init_client();
|
|
17465
|
+
var PUSH_TOKEN_STORAGE_KEY = "realtimex-push-token";
|
|
17466
|
+
var SERVICE_WORKER_PATH = "/firebase-messaging-sw.js";
|
|
17467
|
+
var PUSH_CHANGED_EVENT = "realtimex:push-changed";
|
|
17468
|
+
var emitPushChanged = (enabled) => {
|
|
17469
|
+
try {
|
|
17470
|
+
window.dispatchEvent(
|
|
17471
|
+
new CustomEvent(PUSH_CHANGED_EVENT, { detail: { enabled } })
|
|
17472
|
+
);
|
|
17473
|
+
} catch {
|
|
17474
|
+
}
|
|
17475
|
+
};
|
|
17476
|
+
var v2Url = "https://realtimex.softwareco.com/api/v2";
|
|
17477
|
+
var apiGetPushConfig = async () => {
|
|
17478
|
+
const { data } = await apiClient.get(`${v2Url}/notifications/push/config`);
|
|
17479
|
+
return data?.data;
|
|
17480
|
+
};
|
|
17481
|
+
var apiRegisterPushToken = async (token, deviceLabel) => {
|
|
17482
|
+
const { data } = await apiClient.post(`${v2Url}/notifications/push/token`, {
|
|
17483
|
+
token,
|
|
17484
|
+
deviceLabel
|
|
17485
|
+
});
|
|
17486
|
+
return data?.data;
|
|
17487
|
+
};
|
|
17488
|
+
var apiRemovePushToken = async (token) => {
|
|
17489
|
+
const { data } = await apiClient.delete(`${v2Url}/notifications/push/token`, {
|
|
17490
|
+
data: { token }
|
|
17491
|
+
});
|
|
17492
|
+
return data;
|
|
17493
|
+
};
|
|
17494
|
+
var apiGetPushPreference = async () => {
|
|
17495
|
+
const { data } = await apiClient.get(
|
|
17496
|
+
`${v2Url}/notifications/push/preference`
|
|
17497
|
+
);
|
|
17498
|
+
return data?.data;
|
|
17499
|
+
};
|
|
17500
|
+
var apiUpdatePushPreference = async (enabled) => {
|
|
17501
|
+
const { data } = await apiClient.patch(
|
|
17502
|
+
`${v2Url}/notifications/push/preference`,
|
|
17503
|
+
{ enabled }
|
|
17504
|
+
);
|
|
17505
|
+
return data?.data;
|
|
17506
|
+
};
|
|
17507
|
+
var isPushSupported = () => typeof window !== "undefined" && "Notification" in window && "serviceWorker" in navigator && "PushManager" in window;
|
|
17508
|
+
var getStoredPushToken = () => {
|
|
17509
|
+
try {
|
|
17510
|
+
return localStorage.getItem(PUSH_TOKEN_STORAGE_KEY);
|
|
17511
|
+
} catch {
|
|
17512
|
+
return null;
|
|
17513
|
+
}
|
|
17514
|
+
};
|
|
17515
|
+
var storePushToken = (token) => {
|
|
17516
|
+
try {
|
|
17517
|
+
if (token) localStorage.setItem(PUSH_TOKEN_STORAGE_KEY, token);
|
|
17518
|
+
else localStorage.removeItem(PUSH_TOKEN_STORAGE_KEY);
|
|
17519
|
+
} catch {
|
|
17520
|
+
}
|
|
17521
|
+
};
|
|
17522
|
+
var defaultDeviceLabel = () => {
|
|
17523
|
+
const ua = navigator.userAgent;
|
|
17524
|
+
const browser = /edg\//i.test(ua) ? "Edge" : /chrome/i.test(ua) ? "Chrome" : /safari/i.test(ua) ? "Safari" : /firefox/i.test(ua) ? "Firefox" : "Browser";
|
|
17525
|
+
const os = /mac/i.test(ua) ? "macOS" : /windows/i.test(ua) ? "Windows" : /android/i.test(ua) ? "Android" : /iphone|ipad/i.test(ua) ? "iOS" : /linux/i.test(ua) ? "Linux" : "Unknown OS";
|
|
17526
|
+
return `${browser} on ${os}`;
|
|
17527
|
+
};
|
|
17528
|
+
var loadFirebaseMessaging = async () => {
|
|
17529
|
+
try {
|
|
17530
|
+
const [{ initializeApp, getApps }, messagingModule] = await Promise.all([
|
|
17531
|
+
import('firebase/app'),
|
|
17532
|
+
import('firebase/messaging')
|
|
17533
|
+
]);
|
|
17534
|
+
return { initializeApp, getApps, ...messagingModule };
|
|
17535
|
+
} catch {
|
|
17536
|
+
throw new Error(
|
|
17537
|
+
'Push notifications need the "firebase" package \u2014 run: npm install firebase'
|
|
17538
|
+
);
|
|
17539
|
+
}
|
|
17540
|
+
};
|
|
17541
|
+
var getFirebaseMessaging = async (firebaseConfig) => {
|
|
17542
|
+
const fb = await loadFirebaseMessaging();
|
|
17543
|
+
const app = fb.getApps().length ? fb.getApps()[0] : fb.initializeApp(firebaseConfig);
|
|
17544
|
+
return { fb, messaging: fb.getMessaging(app) };
|
|
17545
|
+
};
|
|
17546
|
+
var enablePushOnThisDevice = async () => {
|
|
17547
|
+
if (!isPushSupported()) {
|
|
17548
|
+
throw new Error("Push notifications are not supported in this browser");
|
|
17549
|
+
}
|
|
17550
|
+
const config = await apiGetPushConfig();
|
|
17551
|
+
if (!config?.enabled) {
|
|
17552
|
+
throw new Error("Push notifications are disabled for this workspace");
|
|
17553
|
+
}
|
|
17554
|
+
if (!config.configured || !config.firebaseConfig || !config.vapidKey) {
|
|
17555
|
+
throw new Error(
|
|
17556
|
+
"Push notifications are not configured on the server yet"
|
|
17557
|
+
);
|
|
17558
|
+
}
|
|
17559
|
+
const permission = await Notification.requestPermission();
|
|
17560
|
+
if (permission !== "granted") {
|
|
17561
|
+
throw new Error("Notification permission was not granted");
|
|
17562
|
+
}
|
|
17563
|
+
let registration;
|
|
17564
|
+
try {
|
|
17565
|
+
registration = await navigator.serviceWorker.register(
|
|
17566
|
+
`${SERVICE_WORKER_PATH}?config=${encodeURIComponent(
|
|
17567
|
+
JSON.stringify(config.firebaseConfig)
|
|
17568
|
+
)}`
|
|
17569
|
+
);
|
|
17570
|
+
} catch {
|
|
17571
|
+
throw new Error(
|
|
17572
|
+
`Could not register ${SERVICE_WORKER_PATH} \u2014 copy it from node_modules/@realtimexsco/live-chat/dist/firebase-messaging-sw.js into your app's public folder`
|
|
17573
|
+
);
|
|
17574
|
+
}
|
|
17575
|
+
const { fb, messaging } = await getFirebaseMessaging(config.firebaseConfig);
|
|
17576
|
+
const token = await fb.getToken(messaging, {
|
|
17577
|
+
vapidKey: config.vapidKey,
|
|
17578
|
+
serviceWorkerRegistration: registration
|
|
17579
|
+
});
|
|
17580
|
+
if (!token) {
|
|
17581
|
+
throw new Error("Could not obtain a push token from Firebase");
|
|
17582
|
+
}
|
|
17583
|
+
await apiRegisterPushToken(token, defaultDeviceLabel());
|
|
17584
|
+
storePushToken(token);
|
|
17585
|
+
emitPushChanged(true);
|
|
17586
|
+
return token;
|
|
17587
|
+
};
|
|
17588
|
+
var disablePushOnThisDevice = async () => {
|
|
17589
|
+
const token = getStoredPushToken();
|
|
17590
|
+
if (!token) return;
|
|
17591
|
+
try {
|
|
17592
|
+
const config = await apiGetPushConfig();
|
|
17593
|
+
if (config?.firebaseConfig) {
|
|
17594
|
+
const { fb, messaging } = await getFirebaseMessaging(
|
|
17595
|
+
config.firebaseConfig
|
|
17596
|
+
);
|
|
17597
|
+
await fb.deleteToken(messaging).catch(() => void 0);
|
|
17598
|
+
}
|
|
17599
|
+
} catch {
|
|
17600
|
+
}
|
|
17601
|
+
await apiRemovePushToken(token).catch(() => void 0);
|
|
17602
|
+
storePushToken(null);
|
|
17603
|
+
emitPushChanged(false);
|
|
17604
|
+
};
|
|
17605
|
+
var onForegroundPush = async (callback) => {
|
|
17606
|
+
const config = await apiGetPushConfig();
|
|
17607
|
+
if (!config?.configured || !config.firebaseConfig) {
|
|
17608
|
+
throw new Error("Push config unavailable (not configured or API not ready)");
|
|
17609
|
+
}
|
|
17610
|
+
const { fb, messaging } = await getFirebaseMessaging(config.firebaseConfig);
|
|
17611
|
+
return fb.onMessage(messaging, (payload) => {
|
|
17612
|
+
callback({
|
|
17613
|
+
title: payload?.notification?.title,
|
|
17614
|
+
body: payload?.notification?.body,
|
|
17615
|
+
data: payload?.data
|
|
17616
|
+
});
|
|
17617
|
+
});
|
|
17618
|
+
};
|
|
17619
|
+
|
|
17620
|
+
// src/notifications/ForegroundPushBridge.tsx
|
|
17621
|
+
var RETRY_DELAYS_MS = [1e3, 3e3, 8e3, 2e4];
|
|
17622
|
+
var ForegroundPushBridge = ({ onPush }) => {
|
|
17623
|
+
React2.useEffect(() => {
|
|
17624
|
+
let unsubscribe = null;
|
|
17625
|
+
let retryTimer = null;
|
|
17626
|
+
let cancelled = false;
|
|
17627
|
+
const handlePayload = (payload) => {
|
|
17628
|
+
const incoming = payload.data?.conversationId;
|
|
17629
|
+
const activeId = exports.useChatStore.getState().activeConversationId;
|
|
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
|
+
});
|
|
17642
|
+
if (onPush && onPush(payload) !== false) return;
|
|
17643
|
+
const text = payload.title ? payload.body ? `${payload.title}: ${payload.body}` : payload.title : payload.body;
|
|
17644
|
+
if (text) showNotification(text, "info");
|
|
17645
|
+
};
|
|
17646
|
+
const start = async (attempt = 0) => {
|
|
17647
|
+
if (cancelled || unsubscribe || !getStoredPushToken()) return;
|
|
17648
|
+
try {
|
|
17649
|
+
const stop = await onForegroundPush(handlePayload);
|
|
17650
|
+
if (cancelled) stop();
|
|
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
|
+
);
|
|
17669
|
+
}
|
|
17670
|
+
};
|
|
17671
|
+
void start();
|
|
17672
|
+
const onPushChanged = (event) => {
|
|
17673
|
+
const enabled = event.detail?.enabled;
|
|
17674
|
+
if (enabled) void start();
|
|
17675
|
+
else {
|
|
17676
|
+
unsubscribe?.();
|
|
17677
|
+
unsubscribe = null;
|
|
17678
|
+
}
|
|
17679
|
+
};
|
|
17680
|
+
window.addEventListener(PUSH_CHANGED_EVENT, onPushChanged);
|
|
17681
|
+
return () => {
|
|
17682
|
+
cancelled = true;
|
|
17683
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
17684
|
+
unsubscribe?.();
|
|
17685
|
+
window.removeEventListener(PUSH_CHANGED_EVENT, onPushChanged);
|
|
17686
|
+
};
|
|
17687
|
+
}, [onPush]);
|
|
17688
|
+
return null;
|
|
17689
|
+
};
|
|
17385
17690
|
var ChatMain = ({
|
|
17386
17691
|
clientId,
|
|
17387
17692
|
loggedUserDetails,
|
|
@@ -17446,7 +17751,7 @@ var ChatMain = ({
|
|
|
17446
17751
|
defaultHour12,
|
|
17447
17752
|
onDateTimePreferencesChange,
|
|
17448
17753
|
showDateTimeSettings,
|
|
17449
|
-
children: /* @__PURE__ */ jsxRuntime.
|
|
17754
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
17450
17755
|
Chat,
|
|
17451
17756
|
{
|
|
17452
17757
|
client: clientObj,
|
|
@@ -17460,25 +17765,28 @@ var ChatMain = ({
|
|
|
17460
17765
|
queryParams,
|
|
17461
17766
|
queryParamApis,
|
|
17462
17767
|
queryParamsByApi,
|
|
17463
|
-
children:
|
|
17464
|
-
|
|
17465
|
-
|
|
17466
|
-
|
|
17467
|
-
|
|
17468
|
-
|
|
17469
|
-
|
|
17470
|
-
|
|
17471
|
-
|
|
17472
|
-
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17478
|
-
|
|
17479
|
-
|
|
17480
|
-
|
|
17481
|
-
|
|
17768
|
+
children: [
|
|
17769
|
+
/* @__PURE__ */ jsxRuntime.jsx(ForegroundPushBridge, {}),
|
|
17770
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
17771
|
+
ChatAlertsProvider,
|
|
17772
|
+
{
|
|
17773
|
+
value: {
|
|
17774
|
+
error,
|
|
17775
|
+
info,
|
|
17776
|
+
onDismissError: onErrorDismiss,
|
|
17777
|
+
onDismissInfo: onInfoDismiss
|
|
17778
|
+
},
|
|
17779
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
17780
|
+
ChatLayout_default,
|
|
17781
|
+
{
|
|
17782
|
+
layout,
|
|
17783
|
+
loggedUserDetails,
|
|
17784
|
+
themeColor
|
|
17785
|
+
}
|
|
17786
|
+
)
|
|
17787
|
+
}
|
|
17788
|
+
)
|
|
17789
|
+
]
|
|
17482
17790
|
}
|
|
17483
17791
|
)
|
|
17484
17792
|
}
|
|
@@ -17532,80 +17840,6 @@ var getSocketConfig = (accessToken, tenantId, options) => {
|
|
|
17532
17840
|
}
|
|
17533
17841
|
};
|
|
17534
17842
|
};
|
|
17535
|
-
var showNotification = (message, type = "info", icon, duration) => {
|
|
17536
|
-
const options = {
|
|
17537
|
-
icon,
|
|
17538
|
-
duration
|
|
17539
|
-
};
|
|
17540
|
-
switch (type) {
|
|
17541
|
-
case "success":
|
|
17542
|
-
reactHotToast.toast.success(message, options);
|
|
17543
|
-
break;
|
|
17544
|
-
case "error":
|
|
17545
|
-
reactHotToast.toast.error(message, options);
|
|
17546
|
-
break;
|
|
17547
|
-
case "info":
|
|
17548
|
-
reactHotToast.toast(message, options);
|
|
17549
|
-
break;
|
|
17550
|
-
case "warning":
|
|
17551
|
-
reactHotToast.toast(message, { ...options, icon: "\u26A0\uFE0F" });
|
|
17552
|
-
break;
|
|
17553
|
-
default:
|
|
17554
|
-
reactHotToast.toast(message, options);
|
|
17555
|
-
}
|
|
17556
|
-
};
|
|
17557
|
-
var downloadFile = async (src, name) => {
|
|
17558
|
-
try {
|
|
17559
|
-
const link = document.createElement("a");
|
|
17560
|
-
link.href = src;
|
|
17561
|
-
link.setAttribute("download", name);
|
|
17562
|
-
link.setAttribute("rel", "noopener noreferrer");
|
|
17563
|
-
link.click();
|
|
17564
|
-
showNotification("File Downloaded Successfully", "success");
|
|
17565
|
-
} catch (err) {
|
|
17566
|
-
console.error("File download failed:", err);
|
|
17567
|
-
showNotification("Failed to download file", "error");
|
|
17568
|
-
}
|
|
17569
|
-
};
|
|
17570
|
-
var getResponsiveWidth = (width) => {
|
|
17571
|
-
const screenWidth = window.innerWidth;
|
|
17572
|
-
if (width) {
|
|
17573
|
-
return width;
|
|
17574
|
-
} else if (screenWidth < 640) {
|
|
17575
|
-
return 350;
|
|
17576
|
-
} else if (screenWidth >= 640 && screenWidth < 1024) {
|
|
17577
|
-
return 600;
|
|
17578
|
-
} else if (screenWidth >= 1024 && screenWidth < 1280) {
|
|
17579
|
-
return 800;
|
|
17580
|
-
} else {
|
|
17581
|
-
return 1e3;
|
|
17582
|
-
}
|
|
17583
|
-
};
|
|
17584
|
-
var isEmpty = (value) => {
|
|
17585
|
-
if (value === null || value === void 0) return true;
|
|
17586
|
-
if (typeof value === "string") return value.trim().length === 0;
|
|
17587
|
-
if (Array.isArray(value)) {
|
|
17588
|
-
return value.length === 0 || value.every((item) => isEmpty(item));
|
|
17589
|
-
}
|
|
17590
|
-
if (typeof value === "object") {
|
|
17591
|
-
return Object.keys(value).length === 0;
|
|
17592
|
-
}
|
|
17593
|
-
return false;
|
|
17594
|
-
};
|
|
17595
|
-
function uniqueList(list, key) {
|
|
17596
|
-
const seen = /* @__PURE__ */ new Set();
|
|
17597
|
-
return list.filter((item) => {
|
|
17598
|
-
const value = item[key];
|
|
17599
|
-
if (seen.has(value)) return false;
|
|
17600
|
-
seen.add(value);
|
|
17601
|
-
return true;
|
|
17602
|
-
});
|
|
17603
|
-
}
|
|
17604
|
-
var capitalizeFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
17605
|
-
var getFirstAndLastNameOneCharacter = (name) => {
|
|
17606
|
-
const names = name.split(" ");
|
|
17607
|
-
return names.map((name2) => name2.charAt(0).toUpperCase()).join("");
|
|
17608
|
-
};
|
|
17609
17843
|
var SIZE_MAP = {
|
|
17610
17844
|
xs: "size-6",
|
|
17611
17845
|
sm: "size-8",
|
|
@@ -17779,150 +18013,6 @@ var packageDefaultComponents = {
|
|
|
17779
18013
|
ChatDateTimeSettings: ChatDateTimeSettings_default,
|
|
17780
18014
|
ChatSocketStatus: ChatSocketStatus_default
|
|
17781
18015
|
};
|
|
17782
|
-
|
|
17783
|
-
// src/notifications/push.service.ts
|
|
17784
|
-
init_client();
|
|
17785
|
-
var PUSH_TOKEN_STORAGE_KEY = "realtimex-push-token";
|
|
17786
|
-
var SERVICE_WORKER_PATH = "/firebase-messaging-sw.js";
|
|
17787
|
-
var v2Url = "https://realtimex.softwareco.com/api/v2";
|
|
17788
|
-
var apiGetPushConfig = async () => {
|
|
17789
|
-
const { data } = await apiClient.get(`${v2Url}/notifications/push/config`);
|
|
17790
|
-
return data?.data;
|
|
17791
|
-
};
|
|
17792
|
-
var apiRegisterPushToken = async (token, deviceLabel) => {
|
|
17793
|
-
const { data } = await apiClient.post(`${v2Url}/notifications/push/token`, {
|
|
17794
|
-
token,
|
|
17795
|
-
deviceLabel
|
|
17796
|
-
});
|
|
17797
|
-
return data?.data;
|
|
17798
|
-
};
|
|
17799
|
-
var apiRemovePushToken = async (token) => {
|
|
17800
|
-
const { data } = await apiClient.delete(`${v2Url}/notifications/push/token`, {
|
|
17801
|
-
data: { token }
|
|
17802
|
-
});
|
|
17803
|
-
return data;
|
|
17804
|
-
};
|
|
17805
|
-
var apiGetPushPreference = async () => {
|
|
17806
|
-
const { data } = await apiClient.get(
|
|
17807
|
-
`${v2Url}/notifications/push/preference`
|
|
17808
|
-
);
|
|
17809
|
-
return data?.data;
|
|
17810
|
-
};
|
|
17811
|
-
var apiUpdatePushPreference = async (enabled) => {
|
|
17812
|
-
const { data } = await apiClient.patch(
|
|
17813
|
-
`${v2Url}/notifications/push/preference`,
|
|
17814
|
-
{ enabled }
|
|
17815
|
-
);
|
|
17816
|
-
return data?.data;
|
|
17817
|
-
};
|
|
17818
|
-
var isPushSupported = () => typeof window !== "undefined" && "Notification" in window && "serviceWorker" in navigator && "PushManager" in window;
|
|
17819
|
-
var getStoredPushToken = () => {
|
|
17820
|
-
try {
|
|
17821
|
-
return localStorage.getItem(PUSH_TOKEN_STORAGE_KEY);
|
|
17822
|
-
} catch {
|
|
17823
|
-
return null;
|
|
17824
|
-
}
|
|
17825
|
-
};
|
|
17826
|
-
var storePushToken = (token) => {
|
|
17827
|
-
try {
|
|
17828
|
-
if (token) localStorage.setItem(PUSH_TOKEN_STORAGE_KEY, token);
|
|
17829
|
-
else localStorage.removeItem(PUSH_TOKEN_STORAGE_KEY);
|
|
17830
|
-
} catch {
|
|
17831
|
-
}
|
|
17832
|
-
};
|
|
17833
|
-
var defaultDeviceLabel = () => {
|
|
17834
|
-
const ua = navigator.userAgent;
|
|
17835
|
-
const browser = /edg\//i.test(ua) ? "Edge" : /chrome/i.test(ua) ? "Chrome" : /safari/i.test(ua) ? "Safari" : /firefox/i.test(ua) ? "Firefox" : "Browser";
|
|
17836
|
-
const os = /mac/i.test(ua) ? "macOS" : /windows/i.test(ua) ? "Windows" : /android/i.test(ua) ? "Android" : /iphone|ipad/i.test(ua) ? "iOS" : /linux/i.test(ua) ? "Linux" : "Unknown OS";
|
|
17837
|
-
return `${browser} on ${os}`;
|
|
17838
|
-
};
|
|
17839
|
-
var loadFirebaseMessaging = async () => {
|
|
17840
|
-
try {
|
|
17841
|
-
const [{ initializeApp, getApps }, messagingModule] = await Promise.all([
|
|
17842
|
-
import('firebase/app'),
|
|
17843
|
-
import('firebase/messaging')
|
|
17844
|
-
]);
|
|
17845
|
-
return { initializeApp, getApps, ...messagingModule };
|
|
17846
|
-
} catch {
|
|
17847
|
-
throw new Error(
|
|
17848
|
-
'Push notifications need the "firebase" package \u2014 run: npm install firebase'
|
|
17849
|
-
);
|
|
17850
|
-
}
|
|
17851
|
-
};
|
|
17852
|
-
var getFirebaseMessaging = async (firebaseConfig) => {
|
|
17853
|
-
const fb = await loadFirebaseMessaging();
|
|
17854
|
-
const app = fb.getApps().length ? fb.getApps()[0] : fb.initializeApp(firebaseConfig);
|
|
17855
|
-
return { fb, messaging: fb.getMessaging(app) };
|
|
17856
|
-
};
|
|
17857
|
-
var enablePushOnThisDevice = async () => {
|
|
17858
|
-
if (!isPushSupported()) {
|
|
17859
|
-
throw new Error("Push notifications are not supported in this browser");
|
|
17860
|
-
}
|
|
17861
|
-
const config = await apiGetPushConfig();
|
|
17862
|
-
if (!config?.enabled) {
|
|
17863
|
-
throw new Error("Push notifications are disabled for this workspace");
|
|
17864
|
-
}
|
|
17865
|
-
if (!config.configured || !config.firebaseConfig || !config.vapidKey) {
|
|
17866
|
-
throw new Error(
|
|
17867
|
-
"Push notifications are not configured on the server yet"
|
|
17868
|
-
);
|
|
17869
|
-
}
|
|
17870
|
-
const permission = await Notification.requestPermission();
|
|
17871
|
-
if (permission !== "granted") {
|
|
17872
|
-
throw new Error("Notification permission was not granted");
|
|
17873
|
-
}
|
|
17874
|
-
let registration;
|
|
17875
|
-
try {
|
|
17876
|
-
registration = await navigator.serviceWorker.register(
|
|
17877
|
-
`${SERVICE_WORKER_PATH}?config=${encodeURIComponent(
|
|
17878
|
-
JSON.stringify(config.firebaseConfig)
|
|
17879
|
-
)}`
|
|
17880
|
-
);
|
|
17881
|
-
} catch {
|
|
17882
|
-
throw new Error(
|
|
17883
|
-
`Could not register ${SERVICE_WORKER_PATH} \u2014 copy it from node_modules/@realtimexsco/live-chat/dist/firebase-messaging-sw.js into your app's public folder`
|
|
17884
|
-
);
|
|
17885
|
-
}
|
|
17886
|
-
const { fb, messaging } = await getFirebaseMessaging(config.firebaseConfig);
|
|
17887
|
-
const token = await fb.getToken(messaging, {
|
|
17888
|
-
vapidKey: config.vapidKey,
|
|
17889
|
-
serviceWorkerRegistration: registration
|
|
17890
|
-
});
|
|
17891
|
-
if (!token) {
|
|
17892
|
-
throw new Error("Could not obtain a push token from Firebase");
|
|
17893
|
-
}
|
|
17894
|
-
await apiRegisterPushToken(token, defaultDeviceLabel());
|
|
17895
|
-
storePushToken(token);
|
|
17896
|
-
return token;
|
|
17897
|
-
};
|
|
17898
|
-
var disablePushOnThisDevice = async () => {
|
|
17899
|
-
const token = getStoredPushToken();
|
|
17900
|
-
if (!token) return;
|
|
17901
|
-
try {
|
|
17902
|
-
const config = await apiGetPushConfig();
|
|
17903
|
-
if (config?.firebaseConfig) {
|
|
17904
|
-
const { fb, messaging } = await getFirebaseMessaging(
|
|
17905
|
-
config.firebaseConfig
|
|
17906
|
-
);
|
|
17907
|
-
await fb.deleteToken(messaging).catch(() => void 0);
|
|
17908
|
-
}
|
|
17909
|
-
} catch {
|
|
17910
|
-
}
|
|
17911
|
-
await apiRemovePushToken(token).catch(() => void 0);
|
|
17912
|
-
storePushToken(null);
|
|
17913
|
-
};
|
|
17914
|
-
var onForegroundPush = async (callback) => {
|
|
17915
|
-
const config = await apiGetPushConfig();
|
|
17916
|
-
if (!config?.configured || !config.firebaseConfig) return () => void 0;
|
|
17917
|
-
const { fb, messaging } = await getFirebaseMessaging(config.firebaseConfig);
|
|
17918
|
-
return fb.onMessage(messaging, (payload) => {
|
|
17919
|
-
callback({
|
|
17920
|
-
title: payload?.notification?.title,
|
|
17921
|
-
body: payload?.notification?.body,
|
|
17922
|
-
data: payload?.data
|
|
17923
|
-
});
|
|
17924
|
-
});
|
|
17925
|
-
};
|
|
17926
18016
|
var usePushNotifications = () => {
|
|
17927
18017
|
const [state, setState] = React2.useState({
|
|
17928
18018
|
supported: false,
|
|
@@ -18075,12 +18165,14 @@ exports.ChatViewport = ChatViewport;
|
|
|
18075
18165
|
exports.DefaultChannelListItem = DefaultChannelListItem;
|
|
18076
18166
|
exports.DefaultChatAvatar = DefaultChatAvatar;
|
|
18077
18167
|
exports.DefaultChatLayout = DefaultChatLayout_default;
|
|
18168
|
+
exports.ForegroundPushBridge = ForegroundPushBridge;
|
|
18078
18169
|
exports.ForwardModal = ForwardModalView;
|
|
18079
18170
|
exports.HeaderCallActions = HeaderCallActions_default;
|
|
18080
18171
|
exports.LoggedUserDetails = LoggedUserDetails_default;
|
|
18081
18172
|
exports.MessageInput = ChannelMessageBoxView_default;
|
|
18082
18173
|
exports.MessageItem = MessageItemView;
|
|
18083
18174
|
exports.MessageList = ActiveChannelMessagesView_default;
|
|
18175
|
+
exports.PUSH_CHANGED_EVENT = PUSH_CHANGED_EVENT;
|
|
18084
18176
|
exports.PushNotificationToggle = PushNotificationToggle;
|
|
18085
18177
|
exports.apiGetPushConfig = apiGetPushConfig;
|
|
18086
18178
|
exports.apiGetPushPreference = apiGetPushPreference;
|