@braze/web-sdk 6.10.2 → 6.12.0
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/index.d.ts +61 -6
- package/package.json +1 -1
- package/shared-lib/encoding-utils.js +3 -3
- package/shared-lib/event-types.js +12 -12
- package/shared-lib/indexed-db-adapter.js +52 -52
- package/shared-lib/logger.js +7 -7
- package/shared-lib/supported-options.js +10 -10
- package/src/Core/logout.js +2 -2
- package/src/DUST/dust-config-store.js +89 -0
- package/src/DUST/dust-connection-core.js +7 -21
- package/src/DUST/dust-message-dedup.js +33 -0
- package/src/DUST/dust-provider.js +367 -397
- package/src/DUST/dust-tab-identity.js +30 -0
- package/src/DUST/index.js +7 -9
- package/src/DUST/subscribe-to-dust.js +5 -5
- package/src/FeatureFlags/feature-flag-factory.js +4 -4
- package/src/FeatureFlags/feature-flag.js +5 -5
- package/src/FeatureFlags/feature-flags-provider-factory.js +8 -1
- package/src/FeatureFlags/feature-flags-provider.js +74 -74
- package/src/FeatureFlags/get-all-feature-flags.js +2 -2
- package/src/FeatureFlags/get-feature-flag.js +2 -2
- package/src/FeatureFlags/log-feature-flag-impression.js +3 -3
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
- package/src/InAppMessage/constants.js +39 -47
- package/src/InAppMessage/defer-in-app-message.js +2 -2
- package/src/InAppMessage/display/get-animation-effect.js +1 -1
- package/src/InAppMessage/display/html-message-display-utils.js +4 -4
- package/src/InAppMessage/display/html-message-to-html.js +10 -10
- package/src/InAppMessage/display/in-app-message-to-html.js +68 -66
- package/src/InAppMessage/display/modal-utils.js +14 -14
- package/src/InAppMessage/get-deferred-in-app-message.js +2 -2
- package/src/InAppMessage/in-app-message-factory.js +6 -6
- package/src/InAppMessage/in-app-message-manager-factory.js +5 -5
- package/src/InAppMessage/in-app-message-manager.js +101 -80
- package/src/InAppMessage/log-in-app-message-button-click.js +2 -2
- package/src/InAppMessage/log-in-app-message-click.js +2 -2
- package/src/InAppMessage/log-in-app-message-html-click.js +4 -4
- package/src/InAppMessage/log-in-app-message-impression.js +3 -3
- package/src/InAppMessage/models/full-screen-message.js +25 -25
- package/src/InAppMessage/models/html-message.js +14 -14
- package/src/InAppMessage/models/in-app-message-button.js +4 -4
- package/src/InAppMessage/models/in-app-message.js +100 -98
- package/src/InAppMessage/models/modal-message.js +23 -23
- package/src/InAppMessage/models/slide-up-message.js +29 -29
- package/src/InAppMessage/models/templated-in-app-message.js +8 -8
- package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +2 -2
- package/src/InAppMessage/ui/show-in-app-message.js +42 -40
- package/src/Push/index.js +1 -0
- package/src/Push/is-push-blocked.js +2 -2
- package/src/Push/is-push-permission-granted.js +2 -2
- package/src/Push/is-push-supported.js +2 -2
- package/src/Push/push-manager-factory.js +6 -6
- package/src/Push/push-manager.js +228 -185
- package/src/Push/register-push.js +9 -0
- package/src/Push/unregister-push-token-on-server.js +4 -4
- package/src/Push/utils/push-utils.js +16 -16
- package/src/User/user-manager.js +19 -19
- package/src/User/user.js +36 -36
- package/src/common/constants.js +1 -1
- package/src/common/content-cards-display.js +21 -21
- package/src/common/event-logger.js +2 -2
- package/src/l10n/l10n-manager-factory.js +7 -7
- package/src/l10n/l10n-manager.js +5 -5
- package/src/managers/auth-manager.js +1 -1
- package/src/managers/braze-instance.js +70 -66
- package/src/managers/device-manager.js +12 -12
- package/src/managers/network-manager.js +118 -118
- package/src/managers/server-config-manager.js +84 -84
- package/src/managers/session-manager.js +10 -10
- package/src/managers/storage-manager-factory.js +4 -4
- package/src/managers/storage-manager.js +138 -136
- package/src/managers/subscription-manager.js +1 -1
- package/src/managers/utils.js +1 -1
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +7 -7
- package/src/models/device.js +2 -2
- package/src/models/identifier.js +6 -6
- package/src/models/push-token.js +6 -6
- package/src/models/server-config.js +31 -31
- package/src/request-controller.js +91 -91
- package/src/triggers/models/filter.js +58 -58
- package/src/triggers/models/in-app-message-click-data.js +4 -4
- package/src/triggers/models/push-click-data.js +2 -2
- package/src/triggers/models/trigger-condition.js +35 -35
- package/src/triggers/models/trigger.js +37 -37
- package/src/triggers/triggers-provider-factory.js +3 -3
- package/src/triggers/triggers-provider.js +61 -53
- package/src/types.js +1 -1
- package/src/ui/js/attach-css.js +1 -1
- package/src/ui/js/feed-css.js +2 -2
- package/src/ui/js/iam-css.js +2 -2
- package/src/util/base-device-parser.js +1 -1
- package/src/util/braze-actions.js +4 -4
- package/src/util/browser-detector.js +13 -13
- package/src/util/client-hints-parser.js +4 -4
- package/src/util/component-utils.js +4 -4
- package/src/util/dom-utils.js +5 -5
- package/src/util/ecommerce-event-validation.js +77 -48
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +4 -4
- package/src/util/request-header-utils.js +20 -20
- package/src/util/string-utils.js +5 -0
- package/src/util/user-agent-parser.js +15 -15
- package/src/util/validation-utils.js +9 -9
- package/src/util/window-utils.js +2 -2
- package/src/DUST/dust-shared-worker-code.js +0 -2
- package/src/DUST/dust-shared-worker-impl.js +0 -234
- package/src/DUST/dust-worker-bridge.js +0 -151
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import t from "../common/base-provider.js";
|
|
2
2
|
import r from "../managers/braze-instance.js";
|
|
3
|
-
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
|
|
4
3
|
import f from "../managers/subscription-manager.js";
|
|
5
4
|
import l from "../util/net.js";
|
|
6
5
|
import h from "../util/request-header-utils.js";
|
|
@@ -12,16 +11,17 @@ import {
|
|
|
12
11
|
} from "../common/constants.js";
|
|
13
12
|
import { randomInclusive as a } from "../util/math.js";
|
|
14
13
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
buildSseUrl as si,
|
|
14
|
+
MAX_RETRIES as ii,
|
|
15
|
+
buildSseUrl as ti,
|
|
18
16
|
} from "./dust-connection-core.js";
|
|
17
|
+
import lt, { isConfigExpired as si } from "./dust-config-store.js";
|
|
18
|
+
import at from "./dust-message-dedup.js";
|
|
19
19
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "./dust-
|
|
20
|
+
buildTabMite as ei,
|
|
21
|
+
generateIndividual as ni,
|
|
22
|
+
} from "./dust-tab-identity.js";
|
|
23
23
|
export default class sr extends t {
|
|
24
|
-
constructor(i, t, s, e
|
|
24
|
+
constructor(i, t, s, e) {
|
|
25
25
|
super(),
|
|
26
26
|
(this.B = i),
|
|
27
27
|
(this.j = t),
|
|
@@ -30,198 +30,171 @@ export default class sr extends t {
|
|
|
30
30
|
(this.j = t),
|
|
31
31
|
(this.h = s),
|
|
32
32
|
(this.mite = null),
|
|
33
|
-
(this.Wi = null),
|
|
34
|
-
(this.Gi = null),
|
|
35
|
-
(this.Hi = null),
|
|
36
|
-
(this.Oi = e || null),
|
|
37
|
-
(this.Ki = null),
|
|
38
|
-
(this.Vi = null),
|
|
39
|
-
(this.T = null),
|
|
40
|
-
(this._i = 0),
|
|
41
|
-
(this.Qi = ti),
|
|
42
|
-
(this.Yi = null),
|
|
43
|
-
(this.Zi = null),
|
|
44
|
-
(this.we = !0),
|
|
45
|
-
(this.Se = null),
|
|
46
|
-
(this.ke = null),
|
|
47
33
|
(this.ye = null),
|
|
34
|
+
(this.Se = null),
|
|
48
35
|
(this.Re = null),
|
|
49
|
-
(this.
|
|
50
|
-
(this.Me =
|
|
51
|
-
(this.xe = null),
|
|
52
|
-
(this.We = null),
|
|
36
|
+
(this.ke = e || null),
|
|
37
|
+
(this.Me = null),
|
|
53
38
|
(this.Fe = null),
|
|
54
|
-
(this.
|
|
55
|
-
(this.
|
|
39
|
+
(this.Ne = null),
|
|
40
|
+
(this.T = null),
|
|
56
41
|
(this.Te = 0),
|
|
57
|
-
(this.
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
),
|
|
67
|
-
"direct")
|
|
68
|
-
: (b.info("Shared connection disabled, using direct EventSource"),
|
|
69
|
-
"direct");
|
|
70
|
-
}
|
|
71
|
-
Ge() {
|
|
72
|
-
this.Fe = new ei({
|
|
73
|
-
Pe: (i) => {
|
|
74
|
-
this.qe(i);
|
|
75
|
-
},
|
|
76
|
-
He: () => {
|
|
77
|
-
this.Je(), (this.ze = new Date().valueOf());
|
|
78
|
-
},
|
|
79
|
-
Le: () => {
|
|
80
|
-
this.ze = null;
|
|
81
|
-
},
|
|
82
|
-
Oe: (i) => {
|
|
83
|
-
b.error(`Real-time messaging SharedWorker error: ${i}`);
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
this.Fe.initialize() ||
|
|
87
|
-
(b.info(
|
|
88
|
-
"SharedWorker initialization failed, falling back to direct EventSource",
|
|
89
|
-
),
|
|
90
|
-
(this.Ue = "direct"),
|
|
91
|
-
(this.Fe = null));
|
|
92
|
-
}
|
|
93
|
-
Je() {
|
|
94
|
-
(this._i = 0),
|
|
95
|
-
(this.Se = null),
|
|
96
|
-
(this.we = !0),
|
|
42
|
+
(this.De = ii),
|
|
43
|
+
(this.Ue = null),
|
|
44
|
+
(this.Ae = null),
|
|
45
|
+
(this.Ge = null),
|
|
46
|
+
(this.Ie = !0),
|
|
47
|
+
(this.Je = null),
|
|
48
|
+
(this.Oe = null),
|
|
49
|
+
(this.Pe = null),
|
|
50
|
+
(this.qe = null),
|
|
97
51
|
(this.Be = !1),
|
|
98
|
-
(this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
52
|
+
(this.ze = new Map()),
|
|
53
|
+
(this.He = null),
|
|
54
|
+
(this.Ke = null),
|
|
55
|
+
(this.Ve = null),
|
|
56
|
+
(this.We = null),
|
|
57
|
+
(this._e = new lt(t)),
|
|
58
|
+
(this.Qe = null),
|
|
59
|
+
(this.Xe = new at(t)),
|
|
60
|
+
(this.Ye = !1),
|
|
61
|
+
this.Ze();
|
|
62
|
+
}
|
|
63
|
+
sn() {
|
|
64
|
+
return this.We || (this.We = ni()), this.We;
|
|
65
|
+
}
|
|
66
|
+
en() {
|
|
67
|
+
(this.Te = 0), (this.Je = null), (this.Ie = !0);
|
|
68
|
+
}
|
|
69
|
+
hn() {
|
|
70
|
+
return null !== this.Fe && this.Fe === this.Ve;
|
|
71
|
+
}
|
|
72
|
+
on(i, t) {
|
|
73
|
+
const s = i.type;
|
|
74
|
+
if (!s)
|
|
113
75
|
return void b.warn(
|
|
114
76
|
`Received real-time message without type: ${JSON.stringify(i)}`,
|
|
115
77
|
);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
78
|
+
if ((b.info(`Received real-time message of type '${s}'`), "cir" === s))
|
|
79
|
+
return void this.ln(t || this.Fe);
|
|
80
|
+
if (!this.Xe.Mr(s))
|
|
81
|
+
return void b.info(
|
|
82
|
+
`Another tab is handling the real-time message of type '${s}', skipping it`,
|
|
83
|
+
);
|
|
84
|
+
const e = this.ze.get(s);
|
|
85
|
+
if (e && e.an() > 0)
|
|
120
86
|
try {
|
|
121
87
|
e.A(i);
|
|
122
88
|
} catch (i) {
|
|
123
|
-
b.error(`Error invoking subscription for message type '${
|
|
89
|
+
b.error(`Error invoking subscription for message type '${s}': ${i}`);
|
|
124
90
|
}
|
|
125
|
-
else b.info(`No subscribers for real-time message type '${
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
91
|
+
else b.info(`No subscribers for real-time message type '${s}'`);
|
|
92
|
+
}
|
|
93
|
+
ln(i) {
|
|
94
|
+
i &&
|
|
95
|
+
this.cn(i) &&
|
|
96
|
+
(b.info("Real-time messaging connection is ready"), (this.Ve = i));
|
|
97
|
+
}
|
|
98
|
+
un(i) {
|
|
99
|
+
this.Ve === i && (this.Ve = null);
|
|
100
|
+
}
|
|
101
|
+
Ze() {
|
|
102
|
+
if (!this.j) return;
|
|
103
|
+
const i = this._e.read();
|
|
104
|
+
i.mite && i.host
|
|
105
|
+
? ((this.mite = i.mite),
|
|
106
|
+
(this.ye = i.host),
|
|
107
|
+
(this.Se = i.auth),
|
|
108
|
+
(this.Re = i.expiration),
|
|
109
|
+
b.info("Restored real-time messaging configuration from storage"))
|
|
110
|
+
: (i.mite || i.host) &&
|
|
111
|
+
(b.warn(
|
|
112
|
+
"Incomplete real-time messaging configuration in storage, clearing",
|
|
113
|
+
),
|
|
114
|
+
this.gn());
|
|
115
|
+
}
|
|
116
|
+
dn() {
|
|
117
|
+
const i = this._e.read();
|
|
118
|
+
i.mite &&
|
|
119
|
+
i.host &&
|
|
120
|
+
(i.auth !== this.Se &&
|
|
121
|
+
b.info(
|
|
122
|
+
"Using real-time messaging configuration refreshed by another tab",
|
|
123
|
+
),
|
|
124
|
+
(this.mite = i.mite),
|
|
125
|
+
(this.ye = i.host),
|
|
126
|
+
(this.Se = i.auth),
|
|
127
|
+
(this.Re = i.expiration));
|
|
151
128
|
}
|
|
152
129
|
Hr() {
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
155
|
-
((this.
|
|
130
|
+
this.He ||
|
|
131
|
+
this.Ke ||
|
|
132
|
+
((this.He = this.mn("ddr", (i) => {
|
|
156
133
|
var t, s, e;
|
|
157
134
|
const n = i.body;
|
|
158
135
|
if (!n) return;
|
|
159
|
-
const
|
|
160
|
-
if ("number" != typeof
|
|
136
|
+
const h = n.r_ms;
|
|
137
|
+
if ("number" != typeof h) return;
|
|
161
138
|
const o = n.e,
|
|
162
|
-
|
|
139
|
+
r = (null === (t = this.h) || void 0 === t ? void 0 : t.vt()) || d,
|
|
163
140
|
l = (null === (s = this.h) || void 0 === s ? void 0 : s.gt()) || m,
|
|
164
141
|
u = (null === (e = this.h) || void 0 === e ? void 0 : e.bt()) || c,
|
|
165
|
-
g = Math.min(u, a(
|
|
166
|
-
f = Math.round(
|
|
142
|
+
g = Math.min(u, a(r, r * l)),
|
|
143
|
+
f = Math.round(h + g),
|
|
167
144
|
p = o ? ` (${o})` : "";
|
|
168
145
|
b.info(
|
|
169
|
-
`Admin requested disconnect${p}, reconnecting in ${f}ms (r_ms=${
|
|
146
|
+
`Admin requested disconnect${p}, reconnecting in ${f}ms (r_ms=${h} + backoff=${g})`,
|
|
170
147
|
),
|
|
171
|
-
this.
|
|
172
|
-
setTimeout(() =>
|
|
148
|
+
this.fn(),
|
|
149
|
+
(this.Ge = window.setTimeout(() => {
|
|
150
|
+
(this.Ge = null), this.pn();
|
|
151
|
+
}, f));
|
|
173
152
|
})),
|
|
174
|
-
(this.
|
|
153
|
+
(this.Ke = this.mn("ttl", (i) => {
|
|
175
154
|
const t = i.body;
|
|
176
155
|
if (!t) return;
|
|
156
|
+
b.info(`ttl message: ${JSON.stringify(t)}`);
|
|
177
157
|
const s = t.t_ms;
|
|
178
158
|
if ("number" != typeof s) return;
|
|
179
159
|
const e = s;
|
|
180
|
-
|
|
181
|
-
(b.info(`Time to live set to ${e}ms, will reconnect when expired`),
|
|
182
|
-
"sharedworker" === this.Ue)
|
|
183
|
-
)
|
|
184
|
-
return;
|
|
160
|
+
b.info(`Time to live set to ${e}ms, will reconnect when expired`);
|
|
185
161
|
const n = t.rcs;
|
|
186
|
-
"string" == typeof n && (this.
|
|
187
|
-
null !== this.
|
|
188
|
-
(this.
|
|
189
|
-
(this.
|
|
162
|
+
"string" == typeof n && (this.Me = n),
|
|
163
|
+
null !== this.Ae && window.clearTimeout(this.Ae),
|
|
164
|
+
(this.Ae = window.setTimeout(() => {
|
|
165
|
+
(this.Ae = null),
|
|
190
166
|
b.info("Time to live expired, performing gapless reconnection"),
|
|
191
|
-
this.
|
|
167
|
+
this.vn();
|
|
192
168
|
}, e));
|
|
193
169
|
})));
|
|
194
170
|
}
|
|
195
|
-
|
|
196
|
-
this.
|
|
197
|
-
this.
|
|
198
|
-
((this.
|
|
199
|
-
(this.
|
|
171
|
+
wn() {
|
|
172
|
+
this.Oe ||
|
|
173
|
+
this.Pe ||
|
|
174
|
+
((this.qe = () => {
|
|
175
|
+
(this.Be = !0), (this.Ie = !1);
|
|
200
176
|
}),
|
|
201
|
-
window.addEventListener("beforeunload", this.
|
|
202
|
-
(this.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.hn());
|
|
177
|
+
window.addEventListener("beforeunload", this.qe),
|
|
178
|
+
(this.Oe = () => {
|
|
179
|
+
(this.Be = !0),
|
|
180
|
+
this.we(),
|
|
181
|
+
(this.Fe || this.Ne) &&
|
|
182
|
+
(b.info("Page unloading, closing real-time connection gracefully"),
|
|
183
|
+
(this.Ie = !1),
|
|
184
|
+
this.fn());
|
|
210
185
|
}),
|
|
211
|
-
window.addEventListener("pagehide", this.
|
|
212
|
-
(this.
|
|
213
|
-
var t;
|
|
214
|
-
const s =
|
|
215
|
-
this.Vi || (null === (t = this.Fe) || void 0 === t ? void 0 : t.Ke());
|
|
186
|
+
window.addEventListener("pagehide", this.Oe),
|
|
187
|
+
(this.Pe = (i) => {
|
|
216
188
|
i.persisted &&
|
|
217
|
-
this.
|
|
218
|
-
!
|
|
189
|
+
this.bn() &&
|
|
190
|
+
!this.Fe &&
|
|
191
|
+
!this.Ne &&
|
|
219
192
|
(b.info("Page restored from bfcache, reconnecting"),
|
|
220
|
-
(this.
|
|
221
|
-
this.
|
|
222
|
-
this.
|
|
193
|
+
(this.Be = !1),
|
|
194
|
+
this.en(),
|
|
195
|
+
this.pn());
|
|
223
196
|
}),
|
|
224
|
-
window.addEventListener("pageshow", this.
|
|
197
|
+
window.addEventListener("pageshow", this.Pe));
|
|
225
198
|
}
|
|
226
199
|
Et() {
|
|
227
200
|
return this.T;
|
|
@@ -229,218 +202,213 @@ export default class sr extends t {
|
|
|
229
202
|
Lt(i) {
|
|
230
203
|
this.T = i;
|
|
231
204
|
}
|
|
232
|
-
|
|
205
|
+
mn(i, t) {
|
|
233
206
|
if ("function" != typeof t) return null;
|
|
234
|
-
let s = this.
|
|
235
|
-
return s || ((s = new f()), this.
|
|
207
|
+
let s = this.ze.get(i);
|
|
208
|
+
return s || ((s = new f()), this.ze.set(i, s), r.S(s)), s.Ut(t);
|
|
236
209
|
}
|
|
237
|
-
|
|
238
|
-
const s = this.
|
|
210
|
+
yn(i, t) {
|
|
211
|
+
const s = this.ze.get(i);
|
|
239
212
|
s && s.removeSubscription(t);
|
|
240
213
|
}
|
|
241
|
-
|
|
242
|
-
return Boolean(this.mite && this.
|
|
214
|
+
bn() {
|
|
215
|
+
return Boolean(this.mite && this.ye);
|
|
216
|
+
}
|
|
217
|
+
Sn() {
|
|
218
|
+
return si(this.Re);
|
|
243
219
|
}
|
|
244
220
|
gn() {
|
|
245
|
-
if (!this.Hi) return !1;
|
|
246
|
-
return Math.floor(new Date().valueOf() / 1e3) >= this.Hi;
|
|
247
|
-
}
|
|
248
|
-
en() {
|
|
249
221
|
(this.mite = null),
|
|
250
|
-
(this.
|
|
251
|
-
(this.
|
|
252
|
-
(this.
|
|
253
|
-
(this.
|
|
254
|
-
this.
|
|
255
|
-
(this.j.Vt(s.It.Xe),
|
|
256
|
-
this.j.Vt(s.It.Ye),
|
|
257
|
-
this.j.Vt(s.It.Ze),
|
|
258
|
-
this.j.Vt(s.It.sn));
|
|
222
|
+
(this.ye = null),
|
|
223
|
+
(this.Se = null),
|
|
224
|
+
(this.Re = null),
|
|
225
|
+
(this.Me = null),
|
|
226
|
+
this._e.clear();
|
|
259
227
|
}
|
|
260
|
-
|
|
228
|
+
Rn(i, t, s = !1) {
|
|
261
229
|
const e = () => {
|
|
262
230
|
"function" == typeof t && t();
|
|
263
231
|
},
|
|
264
|
-
n =
|
|
232
|
+
n = () => {
|
|
233
|
+
this.pn(), "function" == typeof i && i();
|
|
234
|
+
};
|
|
235
|
+
if (this.Ye) return void e();
|
|
236
|
+
const o = this.B,
|
|
265
237
|
r = this.j;
|
|
266
|
-
if (!
|
|
238
|
+
if (!o || !r)
|
|
267
239
|
return (
|
|
268
240
|
b.error("NetworkManager or StorageManager not available"), void e()
|
|
269
241
|
);
|
|
270
|
-
if (!this.h || !this.h
|
|
242
|
+
if (!this.h || !this.h.$n())
|
|
271
243
|
return (
|
|
272
244
|
b.info("Real-time messaging is not enabled, skipping refresh"), void e()
|
|
273
245
|
);
|
|
274
|
-
this.
|
|
275
|
-
|
|
276
|
-
: b.info("Fetching initial real-time messaging configuration");
|
|
277
|
-
const o = n.Z({}, !0),
|
|
278
|
-
a = n.tt(o, h.it.pn),
|
|
279
|
-
c = new Date().valueOf();
|
|
280
|
-
h.nt(r, h.it.pn, c),
|
|
281
|
-
l.ot({
|
|
282
|
-
url: `${n.ht()}/dust/config`,
|
|
283
|
-
headers: a,
|
|
284
|
-
data: o,
|
|
285
|
-
lt: (t) => {
|
|
286
|
-
if (!n.ut(o, t, a))
|
|
287
|
-
return (
|
|
288
|
-
b.error(
|
|
289
|
-
"Failed to validate server response for real-time messaging configuration",
|
|
290
|
-
),
|
|
291
|
-
void e()
|
|
292
|
-
);
|
|
293
|
-
n.ct(),
|
|
294
|
-
t.mite && t.host
|
|
295
|
-
? ((this.mite = t.mite),
|
|
296
|
-
(this.Wi = t.host),
|
|
297
|
-
(this.Gi = t.auth || null),
|
|
298
|
-
(this.Hi = t.expiration || null),
|
|
299
|
-
b.info(
|
|
300
|
-
"Received real-time messaging configuration from server",
|
|
301
|
-
),
|
|
302
|
-
r.Pt(s.It.Xe, t.mite),
|
|
303
|
-
r.Pt(s.It.Ye, t.host),
|
|
304
|
-
t.auth ? r.Pt(s.It.Ze, t.auth) : r.Vt(s.It.Ze),
|
|
305
|
-
t.expiration ? r.Pt(s.It.sn, t.expiration) : r.Vt(s.It.sn),
|
|
306
|
-
this.an(),
|
|
307
|
-
"function" == typeof i && i())
|
|
308
|
-
: (b.info(
|
|
309
|
-
"Real-time messaging configuration not available - this SDK version may not be supported",
|
|
310
|
-
),
|
|
311
|
-
this.en(),
|
|
312
|
-
e());
|
|
313
|
-
},
|
|
314
|
-
error: (i) => {
|
|
315
|
-
n.dt(i, "retrieving DUST config"), e();
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
an() {
|
|
320
|
-
if (!this.h || !this.h.fn()) return;
|
|
321
|
-
if (!this.un())
|
|
322
|
-
return void b.error(
|
|
323
|
-
"Cannot start real-time subscription without configuration",
|
|
324
|
-
);
|
|
325
|
-
if (this.gn())
|
|
246
|
+
const a = this.Qe || this._e.Yi();
|
|
247
|
+
if (!a && !s)
|
|
326
248
|
return (
|
|
327
249
|
b.info(
|
|
328
|
-
"
|
|
250
|
+
"Another tab is refreshing real-time messaging configuration, waiting for the result",
|
|
329
251
|
),
|
|
330
|
-
void this.
|
|
331
|
-
() => {
|
|
332
|
-
this.an();
|
|
333
|
-
},
|
|
252
|
+
void this._e.xe(
|
|
334
253
|
() => {
|
|
335
|
-
|
|
336
|
-
"Failed to refresh expired real-time messaging configuration",
|
|
337
|
-
);
|
|
254
|
+
this.dn(), n();
|
|
338
255
|
},
|
|
256
|
+
() => this.Rn(i, t, !0),
|
|
339
257
|
)
|
|
340
258
|
);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
259
|
+
(this.Qe = a),
|
|
260
|
+
this.bn()
|
|
261
|
+
? b.info("Refreshing real-time messaging configuration")
|
|
262
|
+
: b.info("Fetching initial real-time messaging configuration");
|
|
263
|
+
const c = o.Z({}, !0),
|
|
264
|
+
u = o.tt(c, h.it.Cn),
|
|
265
|
+
g = new Date().valueOf();
|
|
266
|
+
h.nt(r, h.it.Cn, g),
|
|
267
|
+
l.ot({
|
|
268
|
+
url: `${o.ht()}/dust/config`,
|
|
269
|
+
headers: u,
|
|
270
|
+
data: c,
|
|
271
|
+
lt: (i) => {
|
|
272
|
+
if (!this.Ye) {
|
|
273
|
+
if ((this.we(), !o.ut(c, i, u)))
|
|
274
|
+
return (
|
|
275
|
+
b.error(
|
|
276
|
+
"Failed to validate server response for real-time messaging configuration",
|
|
277
|
+
),
|
|
278
|
+
void e()
|
|
279
|
+
);
|
|
280
|
+
o.ct(),
|
|
281
|
+
i.mite && i.host
|
|
282
|
+
? ((this.mite = i.mite),
|
|
283
|
+
(this.ye = i.host),
|
|
284
|
+
(this.Se = i.auth || null),
|
|
285
|
+
(this.Re = i.expiration || null),
|
|
286
|
+
b.info(
|
|
287
|
+
"Received real-time messaging configuration from server",
|
|
288
|
+
),
|
|
289
|
+
this._e.write({
|
|
290
|
+
mite: this.mite,
|
|
291
|
+
host: this.ye,
|
|
292
|
+
auth: this.Se,
|
|
293
|
+
expiration: this.Re,
|
|
294
|
+
}),
|
|
295
|
+
n())
|
|
296
|
+
: (b.info(
|
|
297
|
+
"Real-time messaging configuration not available - this SDK version may not be supported",
|
|
298
|
+
),
|
|
299
|
+
this.gn(),
|
|
300
|
+
e());
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
error: (i) => {
|
|
304
|
+
this.Ye || (this.we(), o.dt(i, "retrieving DUST config"), e());
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
we() {
|
|
309
|
+
this.Qe && (this._e.we(this.Qe), (this.Qe = null));
|
|
310
|
+
}
|
|
311
|
+
pn() {
|
|
312
|
+
if (!this.Ye && this.h && this.h.$n())
|
|
313
|
+
if (this.Ne)
|
|
314
|
+
b.info("Real-time messaging connection attempt already in progress");
|
|
315
|
+
else {
|
|
316
|
+
if ((this.dn(), this.bn()))
|
|
317
|
+
return this.Sn()
|
|
318
|
+
? (b.info(
|
|
319
|
+
"Real-time messaging auth token has expired, refreshing configuration",
|
|
320
|
+
),
|
|
321
|
+
void this.Rn(void 0, () => {
|
|
322
|
+
b.error(
|
|
323
|
+
"Failed to refresh expired real-time messaging configuration",
|
|
324
|
+
);
|
|
325
|
+
}))
|
|
326
|
+
: void (
|
|
327
|
+
this.kn() &&
|
|
328
|
+
(this.ke || this.ye) &&
|
|
329
|
+
(this.Fe &&
|
|
330
|
+
(b.info(
|
|
331
|
+
"Real-time connection already exists, closing before starting new subscription",
|
|
332
|
+
),
|
|
333
|
+
this.fn()),
|
|
334
|
+
this.jn())
|
|
335
|
+
);
|
|
336
|
+
b.error("Cannot start real-time subscription without configuration");
|
|
355
337
|
}
|
|
356
338
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
339
|
+
kn() {
|
|
340
|
+
return this.mite ? ei(this.mite, this.sn()) : null;
|
|
341
|
+
}
|
|
342
|
+
xn() {
|
|
343
|
+
const i = this.kn(),
|
|
344
|
+
t = this.ke || this.ye;
|
|
360
345
|
return i && t
|
|
361
|
-
?
|
|
346
|
+
? ti(t, i, this.Te, this.Se || void 0, this.Me || void 0)
|
|
362
347
|
: null;
|
|
363
348
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if ((this.Fe || this.Ge(), !this.Fe))
|
|
367
|
-
return (
|
|
368
|
-
b.info(
|
|
369
|
-
"SharedWorker initialization failed, falling back to direct EventSource",
|
|
370
|
-
),
|
|
371
|
-
(this.Ue = "direct"),
|
|
372
|
-
void this.Sn()
|
|
373
|
-
);
|
|
374
|
-
this.Oi && b.info(`Using custom real-time messaging host: ${this.Oi}`),
|
|
375
|
-
b.info("Starting real-time subscription via SharedWorker");
|
|
376
|
-
const r = (null === (s = this.h) || void 0 === s ? void 0 : s.vt()) || d,
|
|
377
|
-
o = (null === (e = this.h) || void 0 === e ? void 0 : e.bt()) || c,
|
|
378
|
-
h = (null === (n = this.h) || void 0 === n ? void 0 : n.gt()) || m;
|
|
379
|
-
this.Fe.connect({
|
|
380
|
-
mite: i,
|
|
381
|
-
dustHost: t,
|
|
382
|
-
auth: this.Gi || void 0,
|
|
383
|
-
backoff: { minSleepMs: r, maxSleepMs: o, scaleFactor: h },
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
Sn() {
|
|
387
|
-
this.Vi &&
|
|
388
|
-
(b.info(
|
|
389
|
-
"Real-time connection already exists, closing before starting new subscription",
|
|
390
|
-
),
|
|
391
|
-
this.kn()),
|
|
392
|
-
this.wn();
|
|
349
|
+
cn(i) {
|
|
350
|
+
return this.Fe === i || this.Ne === i;
|
|
393
351
|
}
|
|
394
|
-
|
|
395
|
-
|
|
352
|
+
jn(i) {
|
|
353
|
+
if (this.Ye) return;
|
|
354
|
+
const t = this.xn();
|
|
396
355
|
if (t) {
|
|
397
|
-
this.
|
|
356
|
+
this.ke && b.info(`Using custom real-time messaging host: ${this.ke}`);
|
|
398
357
|
try {
|
|
399
358
|
const s = new EventSource(t);
|
|
400
|
-
(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
359
|
+
(this.Ne = s),
|
|
360
|
+
b.info(`createConnection: ${t}`),
|
|
361
|
+
(s.onopen = () => {
|
|
362
|
+
this.cn(s)
|
|
363
|
+
? (this.Ne === s && (this.Ne = null),
|
|
364
|
+
i
|
|
365
|
+
? (b.info(
|
|
366
|
+
"Gapless reconnection: new connection established, closing old connection",
|
|
367
|
+
),
|
|
368
|
+
i.close())
|
|
369
|
+
: b.info("Real-time messaging connection established"),
|
|
370
|
+
(this.Fe = s),
|
|
371
|
+
this.Ve !== s && (this.Ve = null),
|
|
372
|
+
(this.Te = 0),
|
|
373
|
+
(this.Je = null),
|
|
374
|
+
(this.Ie = !0))
|
|
375
|
+
: s.close();
|
|
376
|
+
}),
|
|
414
377
|
s.addEventListener("msg", (i) => {
|
|
415
|
-
this.
|
|
378
|
+
if (!this.cn(s))
|
|
379
|
+
return (
|
|
380
|
+
b.info("Ignoring real-time message from superseded connection"),
|
|
381
|
+
void s.close()
|
|
382
|
+
);
|
|
383
|
+
this.Mn(i.data, s);
|
|
416
384
|
}),
|
|
417
385
|
(s.onerror = () => {
|
|
418
386
|
const t = s.readyState;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
387
|
+
if (this.cn(s)) {
|
|
388
|
+
if (
|
|
389
|
+
(this.Be ||
|
|
390
|
+
(0 === t
|
|
391
|
+
? b.info("Real-time messaging failed to connect")
|
|
392
|
+
: b.info("Real-time messaging connection lost")),
|
|
393
|
+
i && this.Fe !== s)
|
|
394
|
+
)
|
|
395
|
+
return (
|
|
396
|
+
b.info("Gapless reconnection failed, keeping old connection"),
|
|
428
397
|
s.close(),
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
398
|
+
this.Ne === s && (this.Ne = null),
|
|
399
|
+
void (this.Ie && this.Te < this.De && this.Fn())
|
|
400
|
+
);
|
|
401
|
+
if (this.Ne && this.Fe === s)
|
|
402
|
+
return s.close(), (this.Fe = null), void this.un(s);
|
|
403
|
+
this.fn(),
|
|
404
|
+
this.Ie && this.Te < this.De
|
|
405
|
+
? this.Fn()
|
|
406
|
+
: (this.Te >= this.De &&
|
|
407
|
+
b.error(
|
|
408
|
+
`Max retry attempts (${this.De}) reached for real-time messaging, giving up for current session`,
|
|
434
409
|
),
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
? this.$n()
|
|
438
|
-
: (this._i >= this.Qi &&
|
|
439
|
-
b.error(
|
|
440
|
-
`Max retry attempts (${this.Qi}) reached for real-time messaging, giving up for current session`,
|
|
441
|
-
),
|
|
442
|
-
(this.we = !1))))
|
|
443
|
-
);
|
|
410
|
+
(this.Ie = !1));
|
|
411
|
+
} else s.close();
|
|
444
412
|
});
|
|
445
413
|
} catch (i) {
|
|
446
414
|
b.error(
|
|
@@ -451,60 +419,59 @@ export default class sr extends t {
|
|
|
451
419
|
}
|
|
452
420
|
}
|
|
453
421
|
}
|
|
454
|
-
|
|
422
|
+
Fn() {
|
|
455
423
|
var i, t, s;
|
|
456
|
-
this.
|
|
424
|
+
this.Te++;
|
|
457
425
|
const e = (null === (i = this.h) || void 0 === i ? void 0 : i.vt()) || d,
|
|
458
426
|
n = (null === (t = this.h) || void 0 === t ? void 0 : t.gt()) || m,
|
|
459
|
-
|
|
460
|
-
let o = this.
|
|
427
|
+
h = (null === (s = this.h) || void 0 === s ? void 0 : s.bt()) || c;
|
|
428
|
+
let o = this.Je;
|
|
461
429
|
(null == o || o < e) && (o = e);
|
|
462
|
-
const
|
|
463
|
-
(this.
|
|
430
|
+
const r = Math.min(h, a(e, o * n));
|
|
431
|
+
(this.Je = r),
|
|
464
432
|
b.info(
|
|
465
|
-
`Retrying real-time messaging connection in ${
|
|
433
|
+
`Retrying real-time messaging connection in ${r}ms (attempt ${this.Te}/${this.De})`,
|
|
466
434
|
),
|
|
467
|
-
(this.
|
|
468
|
-
(this.
|
|
469
|
-
},
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
if (this.
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
break;
|
|
491
|
-
case "direct":
|
|
492
|
-
this.kn();
|
|
435
|
+
(this.Ue = window.setTimeout(() => {
|
|
436
|
+
(this.Ue = null), this.pn();
|
|
437
|
+
}, r));
|
|
438
|
+
}
|
|
439
|
+
vn() {
|
|
440
|
+
if (this.Ne)
|
|
441
|
+
b.info("Real-time messaging connection attempt already in progress");
|
|
442
|
+
else {
|
|
443
|
+
if ((this.dn(), this.bn()))
|
|
444
|
+
return this.Sn()
|
|
445
|
+
? (b.info(
|
|
446
|
+
"Auth token expired during gapless reconnection, falling back to regular reconnection",
|
|
447
|
+
),
|
|
448
|
+
this.fn(),
|
|
449
|
+
void this.pn())
|
|
450
|
+
: void (this.Ne
|
|
451
|
+
? b.info(
|
|
452
|
+
"Real-time connection attempt already in progress, skipping gapless reconnection",
|
|
453
|
+
)
|
|
454
|
+
: (null !== this.Ae &&
|
|
455
|
+
(window.clearTimeout(this.Ae), (this.Ae = null)),
|
|
456
|
+
this.jn(this.Fe || void 0)));
|
|
457
|
+
b.error("Cannot perform gapless reconnection without configuration");
|
|
493
458
|
}
|
|
494
459
|
}
|
|
495
|
-
|
|
496
|
-
null !== this.
|
|
497
|
-
null !== this.
|
|
498
|
-
(this.
|
|
499
|
-
this.
|
|
500
|
-
|
|
501
|
-
|
|
460
|
+
fn() {
|
|
461
|
+
null !== this.Ue && (window.clearTimeout(this.Ue), (this.Ue = null)),
|
|
462
|
+
null !== this.Ae && (window.clearTimeout(this.Ae), (this.Ae = null)),
|
|
463
|
+
null !== this.Ge && (window.clearTimeout(this.Ge), (this.Ge = null)),
|
|
464
|
+
(this.Ve = null),
|
|
465
|
+
this.Ne && (this.Ne.close(), (this.Ne = null)),
|
|
466
|
+
this.Fe &&
|
|
467
|
+
(this.Fe.close(),
|
|
468
|
+
(this.Fe = null),
|
|
502
469
|
b.info("Real-time messaging connection closed"));
|
|
503
470
|
}
|
|
504
|
-
|
|
471
|
+
Mn(i, t) {
|
|
505
472
|
try {
|
|
506
|
-
const
|
|
507
|
-
this.
|
|
473
|
+
const s = JSON.parse(i);
|
|
474
|
+
this.on(s, t);
|
|
508
475
|
} catch (i) {
|
|
509
476
|
b.warn(
|
|
510
477
|
`Failed to parse real-time message: ${
|
|
@@ -514,39 +481,42 @@ export default class sr extends t {
|
|
|
514
481
|
}
|
|
515
482
|
}
|
|
516
483
|
changeUser(i = !1) {
|
|
517
|
-
this.
|
|
484
|
+
this.fn(),
|
|
518
485
|
i ||
|
|
519
|
-
(this.
|
|
486
|
+
(this.bn() &&
|
|
520
487
|
b.info(
|
|
521
488
|
"Clearing cached real-time messaging configuration for user change",
|
|
522
489
|
),
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
490
|
+
this.gn()),
|
|
491
|
+
this.en();
|
|
525
492
|
}
|
|
526
493
|
clearData(i = !1) {
|
|
527
|
-
(this.
|
|
528
|
-
this.
|
|
494
|
+
(this.Ie = !1),
|
|
495
|
+
this.fn(),
|
|
529
496
|
i &&
|
|
530
|
-
(this.
|
|
497
|
+
(this.bn() &&
|
|
531
498
|
b.info(
|
|
532
499
|
"Clearing cached real-time messaging configuration (wipeData)",
|
|
533
500
|
),
|
|
534
|
-
this.
|
|
535
|
-
|
|
501
|
+
this.gn(),
|
|
502
|
+
this.Xe.Wr()),
|
|
503
|
+
this.en();
|
|
536
504
|
}
|
|
537
505
|
destroy() {
|
|
538
|
-
(this.
|
|
539
|
-
this.
|
|
540
|
-
this.
|
|
541
|
-
this.
|
|
542
|
-
this.
|
|
543
|
-
this.
|
|
544
|
-
this.
|
|
545
|
-
|
|
546
|
-
this.
|
|
547
|
-
(window.removeEventListener("
|
|
548
|
-
this.
|
|
549
|
-
(window.removeEventListener("
|
|
506
|
+
(this.Ye = !0),
|
|
507
|
+
(this.Ie = !1),
|
|
508
|
+
this.fn(),
|
|
509
|
+
this.we(),
|
|
510
|
+
this._e.destroy(),
|
|
511
|
+
this.gn(),
|
|
512
|
+
this.He && (this.yn("ddr", this.He), (this.He = null)),
|
|
513
|
+
this.Ke && (this.yn("ttl", this.Ke), (this.Ke = null)),
|
|
514
|
+
this.qe &&
|
|
515
|
+
(window.removeEventListener("beforeunload", this.qe), (this.qe = null)),
|
|
516
|
+
this.Oe &&
|
|
517
|
+
(window.removeEventListener("pagehide", this.Oe), (this.Oe = null)),
|
|
518
|
+
this.Pe &&
|
|
519
|
+
(window.removeEventListener("pageshow", this.Pe), (this.Pe = null)),
|
|
550
520
|
this.T && (r.removeSubscription(this.T), (this.T = null));
|
|
551
521
|
}
|
|
552
522
|
}
|