@realtimexsco/live-chat 1.4.3 → 1.4.4
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 +298 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.mjs +297 -239
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17382,6 +17382,279 @@ 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) return () => void 0;
|
|
17608
|
+
const { fb, messaging } = await getFirebaseMessaging(config.firebaseConfig);
|
|
17609
|
+
return fb.onMessage(messaging, (payload) => {
|
|
17610
|
+
callback({
|
|
17611
|
+
title: payload?.notification?.title,
|
|
17612
|
+
body: payload?.notification?.body,
|
|
17613
|
+
data: payload?.data
|
|
17614
|
+
});
|
|
17615
|
+
});
|
|
17616
|
+
};
|
|
17617
|
+
|
|
17618
|
+
// src/notifications/ForegroundPushBridge.tsx
|
|
17619
|
+
var ForegroundPushBridge = ({ onPush }) => {
|
|
17620
|
+
React2.useEffect(() => {
|
|
17621
|
+
let unsubscribe = null;
|
|
17622
|
+
let cancelled = false;
|
|
17623
|
+
const handlePayload = (payload) => {
|
|
17624
|
+
const incoming = payload.data?.conversationId;
|
|
17625
|
+
const activeId = exports.useChatStore.getState().activeConversationId;
|
|
17626
|
+
if (incoming && activeId && incoming === activeId) return;
|
|
17627
|
+
if (onPush && onPush(payload) !== false) return;
|
|
17628
|
+
const text = payload.title ? payload.body ? `${payload.title}: ${payload.body}` : payload.title : payload.body;
|
|
17629
|
+
if (text) showNotification(text, "info");
|
|
17630
|
+
};
|
|
17631
|
+
const start = async () => {
|
|
17632
|
+
if (cancelled || unsubscribe || !getStoredPushToken()) return;
|
|
17633
|
+
try {
|
|
17634
|
+
const stop = await onForegroundPush(handlePayload);
|
|
17635
|
+
if (cancelled) stop();
|
|
17636
|
+
else unsubscribe = stop;
|
|
17637
|
+
} catch {
|
|
17638
|
+
}
|
|
17639
|
+
};
|
|
17640
|
+
void start();
|
|
17641
|
+
const onPushChanged = (event) => {
|
|
17642
|
+
const enabled = event.detail?.enabled;
|
|
17643
|
+
if (enabled) void start();
|
|
17644
|
+
else {
|
|
17645
|
+
unsubscribe?.();
|
|
17646
|
+
unsubscribe = null;
|
|
17647
|
+
}
|
|
17648
|
+
};
|
|
17649
|
+
window.addEventListener(PUSH_CHANGED_EVENT, onPushChanged);
|
|
17650
|
+
return () => {
|
|
17651
|
+
cancelled = true;
|
|
17652
|
+
unsubscribe?.();
|
|
17653
|
+
window.removeEventListener(PUSH_CHANGED_EVENT, onPushChanged);
|
|
17654
|
+
};
|
|
17655
|
+
}, [onPush]);
|
|
17656
|
+
return null;
|
|
17657
|
+
};
|
|
17385
17658
|
var ChatMain = ({
|
|
17386
17659
|
clientId,
|
|
17387
17660
|
loggedUserDetails,
|
|
@@ -17446,7 +17719,7 @@ var ChatMain = ({
|
|
|
17446
17719
|
defaultHour12,
|
|
17447
17720
|
onDateTimePreferencesChange,
|
|
17448
17721
|
showDateTimeSettings,
|
|
17449
|
-
children: /* @__PURE__ */ jsxRuntime.
|
|
17722
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
17450
17723
|
Chat,
|
|
17451
17724
|
{
|
|
17452
17725
|
client: clientObj,
|
|
@@ -17460,25 +17733,28 @@ var ChatMain = ({
|
|
|
17460
17733
|
queryParams,
|
|
17461
17734
|
queryParamApis,
|
|
17462
17735
|
queryParamsByApi,
|
|
17463
|
-
children:
|
|
17464
|
-
|
|
17465
|
-
|
|
17466
|
-
|
|
17467
|
-
|
|
17468
|
-
|
|
17469
|
-
|
|
17470
|
-
|
|
17471
|
-
|
|
17472
|
-
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17478
|
-
|
|
17479
|
-
|
|
17480
|
-
|
|
17481
|
-
|
|
17736
|
+
children: [
|
|
17737
|
+
/* @__PURE__ */ jsxRuntime.jsx(ForegroundPushBridge, {}),
|
|
17738
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
17739
|
+
ChatAlertsProvider,
|
|
17740
|
+
{
|
|
17741
|
+
value: {
|
|
17742
|
+
error,
|
|
17743
|
+
info,
|
|
17744
|
+
onDismissError: onErrorDismiss,
|
|
17745
|
+
onDismissInfo: onInfoDismiss
|
|
17746
|
+
},
|
|
17747
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
17748
|
+
ChatLayout_default,
|
|
17749
|
+
{
|
|
17750
|
+
layout,
|
|
17751
|
+
loggedUserDetails,
|
|
17752
|
+
themeColor
|
|
17753
|
+
}
|
|
17754
|
+
)
|
|
17755
|
+
}
|
|
17756
|
+
)
|
|
17757
|
+
]
|
|
17482
17758
|
}
|
|
17483
17759
|
)
|
|
17484
17760
|
}
|
|
@@ -17532,80 +17808,6 @@ var getSocketConfig = (accessToken, tenantId, options) => {
|
|
|
17532
17808
|
}
|
|
17533
17809
|
};
|
|
17534
17810
|
};
|
|
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
17811
|
var SIZE_MAP = {
|
|
17610
17812
|
xs: "size-6",
|
|
17611
17813
|
sm: "size-8",
|
|
@@ -17779,150 +17981,6 @@ var packageDefaultComponents = {
|
|
|
17779
17981
|
ChatDateTimeSettings: ChatDateTimeSettings_default,
|
|
17780
17982
|
ChatSocketStatus: ChatSocketStatus_default
|
|
17781
17983
|
};
|
|
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
17984
|
var usePushNotifications = () => {
|
|
17927
17985
|
const [state, setState] = React2.useState({
|
|
17928
17986
|
supported: false,
|
|
@@ -18075,12 +18133,14 @@ exports.ChatViewport = ChatViewport;
|
|
|
18075
18133
|
exports.DefaultChannelListItem = DefaultChannelListItem;
|
|
18076
18134
|
exports.DefaultChatAvatar = DefaultChatAvatar;
|
|
18077
18135
|
exports.DefaultChatLayout = DefaultChatLayout_default;
|
|
18136
|
+
exports.ForegroundPushBridge = ForegroundPushBridge;
|
|
18078
18137
|
exports.ForwardModal = ForwardModalView;
|
|
18079
18138
|
exports.HeaderCallActions = HeaderCallActions_default;
|
|
18080
18139
|
exports.LoggedUserDetails = LoggedUserDetails_default;
|
|
18081
18140
|
exports.MessageInput = ChannelMessageBoxView_default;
|
|
18082
18141
|
exports.MessageItem = MessageItemView;
|
|
18083
18142
|
exports.MessageList = ActiveChannelMessagesView_default;
|
|
18143
|
+
exports.PUSH_CHANGED_EVENT = PUSH_CHANGED_EVENT;
|
|
18084
18144
|
exports.PushNotificationToggle = PushNotificationToggle;
|
|
18085
18145
|
exports.apiGetPushConfig = apiGetPushConfig;
|
|
18086
18146
|
exports.apiGetPushPreference = apiGetPushPreference;
|