@suprsend/web-sdk 1.2.3 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "This is sdk used to integrate suprsend functionality in javascript applications",
5
5
  "main": "dist/cjs_bundle.js",
6
6
  "scripts": {
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._get_subscription();
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,7 +114,7 @@ class WebPush {
102
114
  };
103
115
 
104
116
  is_subscribed = async () => {
105
- const subscription = await this._get_subscription();
117
+ const subscription = await this._get_subscription_without_wait();
106
118
  return !!subscription;
107
119
  };
108
120