@rivium/push-web 0.1.7 → 0.1.9
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/README.md +19 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/service-worker.js +150 -64
package/README.md
CHANGED
|
@@ -50,6 +50,25 @@ cp node_modules/@rivium/push-web/service-worker.js public/rivium-push-sw.js
|
|
|
50
50
|
curl -o public/rivium-push-sw.js https://unpkg.com/@rivium/push-web/service-worker.js
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
Let the SDK register it (`init()` does this for you). It registers the worker
|
|
54
|
+
with its API key and device id on the URL, and mirrors the same values into
|
|
55
|
+
IndexedDB under `rivium-push` / `config`.
|
|
56
|
+
|
|
57
|
+
The worker needs those two values to confirm delivery and to re-register a
|
|
58
|
+
subscription the browser replaces. It reads the URL first and falls back to
|
|
59
|
+
storage, so it keeps working even when something else registered
|
|
60
|
+
`/rivium-push-sw.js` without the query string - your own
|
|
61
|
+
`navigator.serviceWorker.register` call, another library, or a hot reload in
|
|
62
|
+
development. Nothing secret is stored: the API key is public and already in
|
|
63
|
+
your page.
|
|
64
|
+
|
|
65
|
+
Where IndexedDB is unavailable (private windows, blocked site data), only the
|
|
66
|
+
URL is used, exactly as before. A worker with neither says so in the console:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
[RiviumPush SW] Delivery ack skipped - no SDK config in the worker URL or in storage
|
|
70
|
+
```
|
|
71
|
+
|
|
53
72
|
## Quick Start
|
|
54
73
|
|
|
55
74
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -582,6 +582,15 @@ declare class RiviumPush {
|
|
|
582
582
|
private handleVisibilityChange;
|
|
583
583
|
private checkInitialMessage;
|
|
584
584
|
private registerServiceWorker;
|
|
585
|
+
/**
|
|
586
|
+
* Keeps `rivium-push` / `config` up to date for the service worker.
|
|
587
|
+
*
|
|
588
|
+
* Rewritten on every load, so a device id or server URL that changed does
|
|
589
|
+
* not leave a stale record behind. Best-effort: private browsing and
|
|
590
|
+
* blocked site data make IndexedDB unavailable, and the worker then falls
|
|
591
|
+
* back to its URL exactly as before.
|
|
592
|
+
*/
|
|
593
|
+
private storeServiceWorkerConfig;
|
|
585
594
|
private requestNotificationPermission;
|
|
586
595
|
/**
|
|
587
596
|
* Whether an existing subscription was created with the given VAPID key.
|
|
@@ -640,6 +649,19 @@ declare class RiviumPush {
|
|
|
640
649
|
private showRichNotification;
|
|
641
650
|
private updateFaviconBadge;
|
|
642
651
|
private setConnectionState;
|
|
652
|
+
/**
|
|
653
|
+
* The id the BACKEND uses in MQTT topics: the first 16 characters of the
|
|
654
|
+
* project id, returned as `appId` by /devices/register.
|
|
655
|
+
*
|
|
656
|
+
* Channels were built from the API key prefix instead, so every channel this
|
|
657
|
+
* SDK streamed from was one nothing is ever published to - the real-time
|
|
658
|
+
* path silently delivered nothing on web, from 0.1.0 until 0.1.9. It went
|
|
659
|
+
* unnoticed because Web Push carried every message on its own.
|
|
660
|
+
*
|
|
661
|
+
* The API key prefix stays as the fallback for a backend old enough not to
|
|
662
|
+
* return `appId`; the native SDKs do exactly the same.
|
|
663
|
+
*/
|
|
664
|
+
private topicAppId;
|
|
643
665
|
private getOrCreateDeviceId;
|
|
644
666
|
private generateUUID;
|
|
645
667
|
private urlBase64ToUint8Array;
|