@realtimexsco/live-chat 1.3.4 → 1.4.1
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/firebase-messaging-sw.js +68 -0
- package/dist/index.cjs +1268 -292
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +155 -1
- package/dist/index.d.ts +155 -1
- package/dist/index.mjs +1231 -294
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +93 -59
- package/package.json +9 -2
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* RealtimeX live-chat push service worker (FCM).
|
|
2
|
+
*
|
|
3
|
+
* Copy this file into your app's public root so it is served at
|
|
4
|
+
* /firebase-messaging-sw.js:
|
|
5
|
+
*
|
|
6
|
+
* cp node_modules/@realtimexsco/live-chat/dist/firebase-messaging-sw.js public/
|
|
7
|
+
*
|
|
8
|
+
* Do NOT edit the Firebase config into this file — the chat package passes it
|
|
9
|
+
* via the registration URL (?config=...), so the copy stays generic.
|
|
10
|
+
*
|
|
11
|
+
* If your app already has its own service worker at the root scope, merge the
|
|
12
|
+
* contents of this file into it instead (two workers cannot share a scope).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/* global firebase, importScripts */
|
|
16
|
+
|
|
17
|
+
importScripts(
|
|
18
|
+
"https://www.gstatic.com/firebasejs/10.14.1/firebase-app-compat.js",
|
|
19
|
+
);
|
|
20
|
+
importScripts(
|
|
21
|
+
"https://www.gstatic.com/firebasejs/10.14.1/firebase-messaging-compat.js",
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
var params = new URL(self.location.href).searchParams;
|
|
25
|
+
var rawConfig = params.get("config");
|
|
26
|
+
|
|
27
|
+
if (rawConfig) {
|
|
28
|
+
try {
|
|
29
|
+
var firebaseConfig = JSON.parse(rawConfig);
|
|
30
|
+
|
|
31
|
+
firebase.initializeApp(firebaseConfig);
|
|
32
|
+
|
|
33
|
+
// Background messages that carry a `notification` payload are displayed
|
|
34
|
+
// by FCM automatically; initializing messaging here is what enables it.
|
|
35
|
+
firebase.messaging();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error("[realtimex] Invalid firebase config in SW URL:", error);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
console.warn(
|
|
41
|
+
"[realtimex] firebase-messaging-sw.js registered without ?config= — " +
|
|
42
|
+
"push notifications will not be delivered",
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Focus (or open) the chat when a notification is clicked.
|
|
47
|
+
self.addEventListener("notificationclick", function (event) {
|
|
48
|
+
event.notification.close();
|
|
49
|
+
|
|
50
|
+
var targetUrl =
|
|
51
|
+
(event.notification.data &&
|
|
52
|
+
event.notification.data.FCM_MSG &&
|
|
53
|
+
event.notification.data.FCM_MSG.data &&
|
|
54
|
+
event.notification.data.FCM_MSG.data.link) ||
|
|
55
|
+
"/";
|
|
56
|
+
|
|
57
|
+
event.waitUntil(
|
|
58
|
+
clients
|
|
59
|
+
.matchAll({ type: "window", includeUncontrolled: true })
|
|
60
|
+
.then(function (windowClients) {
|
|
61
|
+
for (var i = 0; i < windowClients.length; i++) {
|
|
62
|
+
if ("focus" in windowClients[i]) return windowClients[i].focus();
|
|
63
|
+
}
|
|
64
|
+
if (clients.openWindow) return clients.openWindow(targetUrl);
|
|
65
|
+
return undefined;
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
});
|