@suprsend/web-sdk 1.2.2 → 1.2.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/cdn_bundle.js +1 -1
- package/dist/cjs_bundle.js +1 -1
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -1
- package/src/web_push.js +17 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -160,7 +160,7 @@ class SuprSend {
|
|
|
160
160
|
async reset(options = { unsubscribe_push: true }) {
|
|
161
161
|
// unsubscribe push
|
|
162
162
|
if (options?.unsubscribe_push) {
|
|
163
|
-
const subscription = await this.web_push.
|
|
163
|
+
const subscription = await this.web_push._get_subscription_without_wait();
|
|
164
164
|
if (subscription) {
|
|
165
165
|
this.user.remove_webpush(subscription);
|
|
166
166
|
}
|
package/src/web_push.js
CHANGED
|
@@ -28,6 +28,18 @@ class WebPush {
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
_get_subscription_without_wait = async () => {
|
|
32
|
+
const registration = await navigator.serviceWorker.getRegistration();
|
|
33
|
+
if (!registration) return;
|
|
34
|
+
|
|
35
|
+
return registration.pushManager
|
|
36
|
+
.getSubscription()
|
|
37
|
+
.then(async (subscription) => {
|
|
38
|
+
if (!subscription) return;
|
|
39
|
+
return subscription;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
31
43
|
_get_subscription = () => {
|
|
32
44
|
return navigator.serviceWorker.ready
|
|
33
45
|
.then((registration) => {
|
|
@@ -102,10 +114,14 @@ class WebPush {
|
|
|
102
114
|
};
|
|
103
115
|
|
|
104
116
|
is_subscribed = async () => {
|
|
105
|
-
const subscription = await this.
|
|
117
|
+
const subscription = await this._get_subscription_without_wait();
|
|
106
118
|
return !!subscription;
|
|
107
119
|
};
|
|
108
120
|
|
|
121
|
+
notification_permission() {
|
|
122
|
+
return Notification.permission;
|
|
123
|
+
}
|
|
124
|
+
|
|
109
125
|
// unsubscribe_push = () => {
|
|
110
126
|
// navigator.serviceWorker.ready
|
|
111
127
|
// .then((registration) => {
|